MATLAB Answers

cube root of negative numbers gets complex numbers? Is it a bug?

27 views (last 30 days)
weidong Li
weidong Li on 20 Apr 2017
Edited: Roger Stafford on 20 Apr 2017
For example, cube root of -8 gets 1.0000 + 1.7321i, which should be -2 from the common sense.

  0 Comments

Sign in to comment.

Answers (1)

Roger Stafford
Roger Stafford on 20 Apr 2017
Edited: Roger Stafford on 20 Apr 2017
It's not a bug. That complex value is one of the three valid cube roots of -8. If you want to get the real -2 value, use the 'nthroot' function:
https://www.mathworks.com/help/matlab/ref/nthroot.html
x = nthroot(-8,3) ---> -2

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!