## Why does the cube root of a negative number give a complex result in MATLAB?

Asked by MathWorks Support Team

### MathWorks Support Team (view profile)

on 30 Sep 2009
Accepted Answer by MathWorks Support Team

### MathWorks Support Team (view profile)

For example, when I compute:
(-8)^(1/3)
I expect the result to be -2. However, I obtain the result:
ans =
1.0000 + 1.7321i
What does this mean?

R13SP1

### MathWorks Support Team (view profile)

Answer by MathWorks Support Team

### MathWorks Support Team (view profile)

on 30 Sep 2009

MATLAB 7.0 (R14) provides the NTHROOT function, which returns the real roots of a number. If you are using a version prior to MATLAB 7.0 (R14), please read the following:
Every number has three cube roots. These three roots can either all be real, or have one be real, while the other two are complex conjugates. The root returned by ^ is the one with the smallest absolute phase angle returned from the ANGLE function. When two values are equal in absolute phase angle, then the ^ operator returns the positive one.
To obtain the real cube root of a negative real number "x", rather than executing:
x.^(1/3)
use the command:
sign(x).*abs(x.^(1/3))
This will find the absolute value of the root and modify it by the sign of the argument.
The best method for finding all integer roots of any real or complex value is to use the ROOTS function. To find the "n"th roots of the complex value "z"
r = z^(1/n)
we can express the above equation as the following polynomial:
r^n - z = 0
This polynomial can be expressed by the vector of coefficients created by the commands:
C = 1;
C(n + 1) = -z;
Then, the following command will compute the "n"th roots "r" of the complex value "z"
r = roots(C) %Compute roots
For example, the following code computes all fifth roots of -243.
z = -243; n = 5; %Define problem constants
C = 1; C(n + 1) = -z; %Create coefficient vector
r = roots(C) %Compute roots
which produces:
r =
-3.0000
-0.9271 + 2.8532i
-0.9271 - 2.8532i
2.4271 + 1.7634i
2.4271 - 1.7634i
These can all be verified as fifth roots of -243 via:
r.^n
resulting in:
ans =
1.0e+002 *
-2.4300
-2.4300 + 0.0000i
-2.4300 - 0.0000i
-2.4300 - 0.0000i
-2.4300 + 0.0000i
which we can see are all close to the value -243.