A similar post here but no answers. http://www.mathworks.com/matlabcentral/newsreader/view_thread/86495
Why matlab return me a complex number
14 次查看(过去 30 天)
显示 更早的评论
Hi, Why >>(-27)^(1/3) return me a complex number rather than -3??? I am curious about this. Please help.
采纳的回答
Andreas Goser
2013-9-27
From the documentation
doc power
"Note that for a negative value X and a non-integer value Y, if the abs(Y) is less than one, the power function returns the complex roots. To obtain the remaining real roots, use the nthroot function."
更多回答(2 个)
Edu Santos
2019-5-21
If instead you do:
(abs(-27))^(1/3)
you may have the good absolute value with the bad sign.
Storing the sign in a term, for example like this:
-27/abs(-27)
we can arrive to the expected answer by doing:
-27/abs(-27)*(abs(-27))^(1/3)
=-3
A simpler way is to just do
nthroot(-27,3)
=-3
0 个评论
Azzi Abdelmalek
2013-9-27
% By definition a^n=exp(n*log(a))
% also if a is a positive real number, log(-a)=log(a)+j*pi
a=-27;
n=1/3
out1=exp(n*log(a))
%the same as
out2=a^n
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!