matlab giving complex number when the expected answer is a real number?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Stephen23
2018년 5월 24일
"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:
채택된 답변
Mischa Kim
2018년 5월 24일
Note:
>> (-1)^1.5
ans =
0.0000 - 1.0000i
which is not the same as
>> -1^1.5 % = -(1^1.5)
ans =
-1
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!