matlab giving complex number when the expected answer is a real number?
Ältere Kommentare anzeigen
matlab is giving me complex number when the expected answer is a real number? The code is the following:
A1 = -1;
A = A1^1.5
A = 0.0000 - 1.0000i
The answer should have been -1
A = -1^1.5
A = -1
Can anyone tell me why this is the case? It is giving a complex number when a variable is used.
Many thanks
1 Kommentar
Stephen23
am 24 Mai 2018
"Can anyone tell me why this is the case?"
Because unary negation has a lower priority than the power operation. You can check this yourself:
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!