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

♀尐吖头ヾ 提交于 2019-12-12 20:00:31

问题


Using MATLAB exponential function:

(-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 redefine ^:

x.^y

to

sign(x).*abs(x.^y))

回答1:


MATLAB 7.0 provides the NTHROOT function, which returns the real roots of a number. So your formula becomes NTHROOT(-8, 3) = -2

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

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.

See this




回答2:


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

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



来源:https://stackoverflow.com/questions/7577595/how-to-get-80-333333-2-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!