Reputation: 269
MATLAB code:
x^(1/3)
If x = -1
then the result is 0.5000 + 0.8660i
, but I only want the real root -1
.
How do I modify the above expression?
PS: I don't want such a solution:
sign(x)*(abs(x))^(1/3)
Upvotes: 0
Views: 919
Reputation: 112759
Using ^
produces only one root. From Mathworks,
The root returned by
^
is the one with the smallest absolute phase angle returned from theangle
function. When two values are equal in absolute phase angle, then the^
operator returns the positive one.
To find the real root use nthroot
:
Y = nthroot(X,N)
returns the real nth root of the elements ofX
. BothX
andN
must be real scalars or arrays of the same size. If an element inX
is negative, then the corresponding element inN
must be an odd integer.
Example:
>> nthroot(-1, 3)
ans =
-1
Upvotes: 4
Reputation: 2835
You will probably have to use nthroot
:
>> nthroot(-1, 3)
ans =
-1
Upvotes: 4