Why matlab return me a complex number
Mostra commenti meno recenti
Hi, Why >>(-27)^(1/3) return me a complex number rather than -3??? I am curious about this. Please help.
1 Commento
David
il 27 Set 2013
Risposta accettata
Più risposte (2)
Edu Santos
il 21 Mag 2019
1 voto
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
il 27 Set 2013
% 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
Categorie
Scopri di più su Number Theory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!