# [Maxima] Problem with plotting function defined condionally

Robert Dodier robert.dodier at gmail.com
Sat Jun 7 11:28:12 CDT 2008

```On 6/7/08, Olive <not0read0765 at yopmail.com> wrote:

>  (%i1) croot(x) := if x>0 then x^(1/3) else -(-x)^(1/3) \$
>
>  if I try to plot this function; I obtain only a graph for x>0, the
>  negative part is left blank on the graph:
>
>  (%i2) plot2d(croot(x),[x,-5,5]);

Olive, here is a work-around:

plot2d (croot, [x, -5, 5]);

i.e. just name the function instead of writing croot(x).

Longer explanation -- the "else" branch simplifies as follows:

'(-(-x)^(1/3));
=> x^(1/3)

So plot2d sees if x > 0 then x^(1/3) else x^(1/3) as the expression to
be plotted. But as you know x^(1/3) doesn't have the right behavior
when x < 0. Instead x^(1/3) evaluates to something other than a number.
e.g. ev(x^(1/3), x= -5, numer) => 1.709975946676697*(-1)^.3333333333333333

The origin of this problem seems to be the simplification (- x)^(1/3)
=> - (x^(1/3)).
It seems that is not an identity when x < 0.
Others have thought about branch cut problems a lot more than me,
so I invite someone else to weigh in on this one.

best

Robert Dodier
```

More information about the Maxima mailing list