In plotting a simple cube root function y = x1/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

• Anonymous
• Posted December 13, 2008 at 10:35 pm

wtf

• Anonymous
• Posted March 12, 2009 at 8:39 pm

thank you

• tin
• Posted December 31, 2011 at 11:55 am