In plotting a simple cube root function y = x^{1/3}, you expect to see a graph like this:

But when you do

x = -3:0.01:3;

y = x.^(1/3);

plot(x,y)

You get:

Why?

“Pete wanted it that way.”

No, but really. Why is the plot of the cube root complex-valued, and not real-valued?

You should know that there are in fact __3__ cube roots for any number.

For instance, -3 has 1 real, and 2 COMPLEX cube roots:

The three cube roots of -3 are:

- 0.7211 + 1.2490i
- 0.7211 – 1.2490i
- -1.44224

They look like this in the complex plane. Notice that they are separated by 120 degrees.

When you multiply those cube roots together, you get -3 again:

(0.7211 + 1.249i)*(0.7211 - 1.249i)*(-1.44224)
= (2.08)(-1.44224)
= -3

When you do:

x = -3:0.01:3;

y = x.^(1/3);

plot(x,y)

Matlab is putting the *first* cube root inside y (values like 0.7211 + 1.2490i as the cube root of -3), hence giving y complex values.

Howdya get it to give you just the real ones? Use Matlab’s **nthroot** function. For example, try:

x = -3:0.01:3;

y = nthroot( x, 3 );

plot(x,y);

Ref:

just see this.

y = nthroot(X, n) returns the real nth root of the elements of X. Both X and n must be real and n must be a scalar. If X has negative entries, n must be an odd integer.

Example

nthroot(-2, 3)

returns the real cube root of -2.

ans =

-1.2599

### Like this:

Like Loading...

*Related*

## 4 Comments

wtf

thank you

thanks for your post.But If it is the nth root, is the angle equal pi/n ? And is there any way to get that n from the function ex:

f= (((x-1)^2)*(x-4))^(1/3) (n=3 for this func) which is already in workspace?

buenas me gustaria saber como se represeta el seno de la raiz cubica de x y el seno al cubo en el intervalo [0,2*pi]..muxas gracias y un saludo