How to get (-8) ^ 0.333333 = -2 in MATLAB?

Using the exponential function MATLAB:

(-8)^0.333333 ans = 1.0000 + 1.7320i 

How to get (-8)^0.333333 = -2 instead?

 x=-10:-1; x.^0.333333 

How to get real value?

How to override ^ :

 x.^y 

to

 sign(x).*abs(x.^y)) 
+2
source share
2 answers

MATLAB 7.0 provides an NTHROOT function that returns the actual roots of a number. This way your formula becomes NTHROOT(-8, 3) = -2

If you are using a version prior to MATLAB 7.0 (R14), read the following:

To get the real cube root of a negative real number "x", rather than execute:

 x.^(1/3) 

use the command:

 sign(x).*abs(x.^(1/3)) 

This will find the absolute value of the root and change it by the sign of the argument.

Watch it

+3
source

There are 3 possible answers for the cube root of -8: -2, 1+/- sqrt(3)

You probably want nthroot(-8,3) --> -2

+4
source

Source: https://habr.com/ru/post/905760/


All Articles