Why matlab return me a complex number

조회 수: 14 (최근 30일)
David
David 2013년 9월 27일
답변: Edu Santos 2019년 5월 21일
Hi, Why >>(-27)^(1/3) return me a complex number rather than -3??? I am curious about this. Please help.

채택된 답변

Andreas Goser
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."
  댓글 수: 1
David
David 2013년 9월 27일
편집: David 2013년 9월 27일
Thanks very much. I also found an useful answer here: http://www.mathworks.com/support/solutions/en/data/1-15M1N/?solution=1-15M1N

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Edu Santos
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

Azzi Abdelmalek
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

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by