Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Not all points plot on my graph...

0 views
Skip to first unread message

davef

unread,
Nov 23, 2009, 6:59:00 AM11/23/09
to
Why is it when I write this...

Clear[f, x]
f[x_] = (x + 2)^(2/3)
Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]
f[-3]

.. I get no values show in the graph for x<-2 even though f[-3]
evaluates to (-1)^(2/3).

(-1)^(2/3) evaluates as f[-3]=1 so why wouldn't the point (-3,1) plot
on my graph?


michael.p...@googlemail.com

unread,
Nov 24, 2009, 5:47:42 AM11/24/09
to

Hi Dave

f[-3] isn't 1 - it's -0.5 + 0.866025 I and, since this is a complex
number, Mathematica can't plot it on a simply x-y graph Evaluate

f[-3] //N to see the complex result for yourself

Cheers,
Mike
www.walkingrandomly.com

Bob Hanlon

unread,
Nov 24, 2009, 5:49:14 AM11/24/09
to

Your assumption that (-1)^(2/3) = 1 is bad.

Clear[f, x]
f[x_] = (x + 2)^(2/3);

f[-3.]

-0.5+0.866025 I

(-1)^(2/3) // N

-0.5+0.866025 I

(-1)^(1/3) // N

0.5+0.866025 I

%^2

-0.5+0.866025 I

% == %%% == %%%%

True


Bob Hanlon

---- davef <davidfr...@yahoo.com> wrote:

=============


Why is it when I write this...

Clear[f, x]
f[x_] = (x + 2)^(2/3)
Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]
f[-3]

.. I get no values show in the graph for x<-2 even though f[-3]
evaluates to (-1)^(2/3).

(-1)^(2/3) evaluates as f[-3]=1 so why wouldn't the point (-3,1) plot
on my graph?

--

Bob Hanlon


Bill Rowe

unread,
Nov 24, 2009, 5:49:59 AM11/24/09
to
On 11/23/09 at 6:49 AM, davidfr...@yahoo.com (davef) wrote:

>Why is it when I write this...

>Clear[f, x]
>f[x_] = (x + 2)^(2/3)
>Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]
>f[-3]

>.. I get no values show in the graph for x<-2 even though f[-3]
>evaluates to (-1)^(2/3).

>(-1)^(2/3) evaluates as f[-3]=1 so why wouldn't the point (-3,1)
>plot on my graph?

When you say f[-3] evaluates to 1, did you actually evaluate
this with Mathematica or in your head? On my system

In[6]:= f[-3] // N

Out[6]= -0.5+0.866025 I

That is Mathematica is not evaluating f[-3] to 1 as you suggest
which explains the missing points. Mathematica by default is not
restricted to real solutions nor does Mathematica give priority
to a real over a complex solution when both exist.


David Bailey

unread,
Nov 24, 2009, 5:50:33 AM11/24/09
to
(-1)^(2/3) is a complex number, so you can't plot it on a real plot.
Have a look at:

(-1)^(2/3)//N

and you will see your mistake.

David Bailey
http://www.dbaileyconsultancy.co.uk

DrMajorBob

unread,
Nov 24, 2009, 5:51:27 AM11/24/09
to
You get no plotted values for x<-2, because f is Complex there.

For instance,

f[-3] // N

-0.5 + 0.866025 I

Bobby

On Mon, 23 Nov 2009 05:49:43 -0600, davef <davidfr...@yahoo.com> wrote:

> Why is it when I write this...
>
> Clear[f, x]
> f[x_] = (x + 2)^(2/3)
> Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]
> f[-3]
>
> .. I get no values show in the graph for x<-2 even though f[-3]
> evaluates to (-1)^(2/3).
>
> (-1)^(2/3) evaluates as f[-3]=1 so why wouldn't the point (-3,1) plot
> on my graph?
>
>


--
DrMaj...@yahoo.com

Murray Eisenberg

unread,
Nov 24, 2009, 6:03:55 AM11/24/09
to
Because Mathematica uses the principal cube root, hence the principal
2/3 power; when a number is negative, the principal cube root is not the
negative real number you might expect, but rather a non-real complex number.

For example:

cuberoot = ComplexExpand[(-3)^(1/3)]
3^(1/3)/2 + (I/2)*3^(5/6)

Expand[cuberoot^2]
((3*I)/2)*3^(1/6) - 3^(2/3)/2

This is often an unwanted and, for Mathematica novices, an unexpected
behavior. But Mathematica wants things to be complex when they can be!

There's a very easy fix here, since the 2/3 power is the cube-root of a
square, and any square is nonnegative:

f[x_] := ((x + 2)^2)^(1/3)

davef wrote:
> Why is it when I write this...
>
> Clear[f, x]
> f[x_] = (x + 2)^(2/3)
> Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]
> f[-3]
>
> .. I get no values show in the graph for x<-2 even though f[-3]
> evaluates to (-1)^(2/3).
>
> (-1)^(2/3) evaluates as f[-3]=1 so why wouldn't the point (-3,1) plot
> on my graph?
>
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Tomas Garza

unread,
Nov 24, 2009, 6:04:06 AM11/24/09
to
Well, f is complex-valued in the range {-2, -3}.
E.g.,

In[13]:= Table[f[j],{j, -2, -3, -0.1}]

Out[13]= {0.,-0.107722+0.18658 I,-0.170998+0.296177 I,-0.22407+0.388101 I,-0.271442+0.470151 I,-0.31498+0.545562 I,-0.355689+0.616072 I,-0.394187+0.682751 I,-0.430887+0.746318 I,-0.466085+0.807283 I,-0.5+0.866025 I}

No way to graph it. Also, probably the point (-3, 1) is too small and almost invisible.

BTW, I would use SetDelayed (:=) instead of Set (=) in the definition of f.

Tomas

> Date: Mon, 23 Nov 2009 06:49:43 -0500
> From: davidfr...@yahoo.com
> Subject: Not all points plot on my graph...
> To: math...@smc.vnet.net

Sjoerd C. de Vries

unread,
Nov 24, 2009, 6:10:32 AM11/24/09
to
Just try f[-3]//N. You'll see it's imaginary (one of the three
possible roots).

Cheers -- Sjoerd

Helen Read

unread,
Nov 25, 2009, 2:30:06 AM11/25/09
to
Tomas Garza wrote:
>
> BTW, I would use SetDelayed (:=) instead of Set (=) in the definition of f.
>>
>> f[x_] = (x + 2)^(2/3)

That's a matter of taste, I think. I have for many years taught my
students to use Set when defining garden variety functions. An advantage
of this is that the function is immediately evaluated and you get
output, which allows students to catch many errors. For example, suppose
they left off the parentheses in the function quoted above, and entered
(x+2)^2/3 . They will immediately see their mistake if they pay the
slightest attention to the output, and can fix it immediately. Using
SetDelayed, it's the rare student who will figure out that they entered
the function incorrectly. This year I have noticed more of this type of
error, because the students learned to define functions by using the
Define Function button on the Classroom Assistant palette, which uses
SetDelayed, and most of them have continued to use SetDelayed after they
stopped relying on the palette. (I have showed the students that can
check the definition of their function by typing in f[x] and evaluating,
but nobody seems to think of it even when it is clear that something
isn't right.)

There are of course times when we need SetDelayed, and we discuss it in
class when it comes up.

--
Helen Read
University of Vermont

David Park

unread,
Nov 25, 2009, 2:35:15 AM11/25/09
to
You have a multivalued complex function. You could solve for these values
by:

w == (z + 2)^(2/3)
#^3 & /@ %
Solve[%, w]
wvalues = w /. %
{(2 + z)^(2/3), -(-1)^(1/3) (2 + z)^(2/3), (-1)^(2/3) (2 + z)^(2/3)}

I have shown only the last output, which is the list of multivalues.

A little exploration with real z shows that the first solution is real for z
> -2 and the second solution is real for z <= -2. So you could write and
plot:

f[x_] := Piecewise[{{-(-1)^(1/3) (2 + x)^(2/3), x <= -2}, {(2 + x)^(
2/3), x > -2}}]


Plot[f[x], {x, -3, 0}, PlotRange -> {{-3, 0}, {-4, 4}}]

However, I'm not certain if always taking the real solution and piecing them
together is proper to whatever underlying application you have.

The better way to handle such functions would be to treat them as
multivalued complex functions and make a plot on an implicit Riemann
surface. For those who have the Presentations package you can do that with
the following code.

Needs["Presentations`Master`"]

DynamicModule[{zpt = {0, 0}, w, root},
Module[
{f = Function[z, (z + 2)^(2/3)],
sqrtz, z,
zcenter = -2},
multif =
Multivalues[
Null, {(2 + z)^(
2/3), -(-1)^(1/3) (2 + z)^(2/3), (-1)^(2/3) (2 + z)^(2/3)} // N,
z];
Row[
{Draw2D[
{ComplexPolarDensityDraw[
Abs[f[z]], {z, ComplexPolar[0, -\[Pi]], ComplexPolar[3, \[Pi]],
zcenter},
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["GrayYellowTones"][
Rescale[#, {0, Sqrt[3]}]] &),
Mesh -> {Sqrt /@ Range[.5, 3, .5]},
MeshFunctions -> (Abs[Sqrt[#1]] &),
PlotPoints -> {5, 10} 4,
MaxRecursion -> 0,
PlotRange -> {0, 3}],
Dynamic@
Arrow[{zpt,
zpt + 1/2 ToCoordinates[
root = Extract[
CalculateMultivalues[multif][ToComplex[zpt]], {1, 1}]]}],
Locator[Dynamic[zpt],
Graphics[{CirclePoint[{0, 0}, 3, Black, Red]}]]},
Frame -> True, FrameLabel -> {Re, Im},
PlotRange -> {{-5, 1}, {-3, 3}},
PlotLabel -> Row[{f["z"], " as a Rieman Surface"}],
Background -> None,
ImageSize -> 350],
Dynamic@Column[
{ComplexArgumentPanel[ToComplex[zpt], {True, True, False},
Row[{"z", Spacer[20]}], {Left, Center},
ImageSize -> {185, 42}],
ComplexArgumentPanel[root, {True, True, False},
Row[{f["z"]}], {Left, Center}, ImageSize -> {185, 42}]}](*
Column *)},
Spacer[20]](* Row *)
]
]

This shows a red CirclePoint locator on a background plot of the modulus of
the function. The locator has a vector attached to it that represents the
value of the function. At every point on the Riemann surface the function is
single valued and continuous. The point can be dragged around and the vector
will behave smoothly with no branch line jumps. The values of z and the
function are shown in a panel on the side. However, because this is a
multifunction, if you drag the locator once around the branch point at z ==
-2 you will not return to the original value. You have to drag it around
three times to get back to the original point on the Riemann surface and the
original value. Other than the fact that you can't actually "see" the
Riemann surface as a geometric surface, there are no artifacts such as
branch lines or surfaces that cross.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


From: davef [mailto:davidfr...@yahoo.com]

Why is it when I write this...

Clear[f, x]


f[x_] = (x + 2)^(2/3)

dh

unread,
Nov 25, 2009, 2:40:17 AM11/25/09
to

davef wrote:

>

> Clear[f, x]

> f[-3]

>

> evaluates to (-1)^(2/3).

>

> on my graph?

>

>

Hi Dave,

your function is multivalued. The principal value is complex for

arguments below -2. Mathematica returns the principal value for numeric

functions. Read on the internet how the principal value is defined.

Where did you see that (-1)^(2/3) evaluates to 1?? This is not the

principal value.

Daniel

0 new messages