MATLAB Answers

0

matlab giving complex number when the expected answer is a real number?

Sei Him Cheong さんによって質問されました 2018 年 5 月 24 日
最新アクティビティ Stephen Cobeldick
さんによって コメントされました 2018 年 5 月 24 日
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 件のコメント

"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:

サインイン to comment.

1 件の回答

Mischa Kim
Answer by Mischa Kim
on 24 May 2018
 Accepted Answer

Note:
>> (-1)^1.5
ans =
0.0000 - 1.0000i
which is not the same as
>> -1^1.5 % = -(1^1.5)
ans =
-1

  0 件のコメント

サインイン to comment.



Translated by