# Matlab wrong cube root [closed]

How can I get MATLAB to calculate $(-1)^{1/3}$ as $-1$? Why is it giving me $0.5000 + 0.8660i$ as solution? I have same problem with $({-1\over0.1690})^{1/3}$ which should be negative.

## closed as off-topic by Bill Dubuque, user26857, user91500, Claude Leibovici, JonMark PerryFeb 9 '17 at 7:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question is not about mathematics, within the scope defined in the help center." – Bill Dubuque, user26857, user91500, Claude Leibovici, JonMark Perry
If this question can be reworded to fit the rules in the help center, please edit the question.

• Maybe because $\;\frac12+\frac{\sqrt3}2i=e^{\pi i/3}\;$ is one of the three roots of unit in the complex field...? – Timbuc Dec 3 '14 at 4:47
• See also this post on the Undocumented Matlab blog. – horchler Dec 3 '14 at 5:29
• FWIW, this is not (solely) a Matlab issue. Mathematica does the same: N @ (-1)^(1/3) → 0.5 + 0.866025i but CubeRoot[-1] → -1. – Raphael Dec 3 '14 at 16:00
• "Wrong", you say? – imallett Dec 4 '14 at 4:21
• I think "wrong" is the wrong word to use. Without context there is no objective way to select the "best" result for a many valued function. – Tim Seguine Dec 4 '14 at 7:14

## 3 Answers

In the following I'll assume that $n$ is odd, $n>2$, and $x<0$.

When asked for $\sqrt[n]{x}$, MATLAB will prefer to give you the principal root in the complex plane, which in this context will be a complex number in the first quadrant. MATLAB does this basically because the principal root is the most convenient one for finding all of the other complex roots.

You can dodge this issue entirely by taking $-\sqrt[n]{-x}$.

If you want to salvage what you have, then you'll find that the root you want on the negative real axis is $|z| \left ( \frac{z}{|z|} \right )^n$. Basically, this trick is finding a complex number with the same modulus as the root $z$ (since all the roots have the same modulus), but $n$ times the argument. This "undoes" the change in argument from taking the principal root.

• Would the downvoter care to comment? – Ian Dec 3 '14 at 4:51
• Why they down voted a perfectly healthy answer I don't understand... – Fmonkey2001 Dec 3 '14 at 4:53
• And now someone's down-voted the question, which is a perfectly legitimate one. – user_of_math Dec 3 '14 at 4:55
• Taking $-\sqrt[n]{-x}$ only works if you assume $x$ is negative. $\:$ "If you want to salvage what ... on the negative real axis is" not what's given in this answer, as can be seen from trying $\:z=8\;$. $\;\;\;$ You can actually "dodge this issue entirely by taking" $\:($ signum $(x))^n\cdot \sqrt[n]{|x|}\;$. $\;\;\;\;\;\;\;$ – user57159 Dec 3 '14 at 22:45
• @RickyDemer Yes, and the OP was asking about a negative input. I didn't answer a question they didn't ask. I also mentioned this in the first paragraph. – Ian Dec 3 '14 at 22:45

Try nthroot(-1,3).

If you type (-1)^(1/3), it'll give you the solution to $x^3=-1$ on the complex plane with lower argument.

If you want the real cube root of $a<0$, try $-|a|^{\Large\frac{1}{3}}$.

• Can you explain why this works? – turkeyhundt Dec 3 '14 at 4:50
• @turkeyhundt Since it's an odd root you can pull the negative out and just take the absolute value of $a$ to the $1/3$ power and then multiple by the negative at the very end. – Fmonkey2001 Dec 3 '14 at 5:01
• Oh. Ha. Right.. – turkeyhundt Dec 3 '14 at 5:12