Matlab is inconsistent when raising numbers to the zero'th power:
조회 수: 1 (최근 30일)
이전 댓글 표시
In matlab R2015a
-1^0
returns
-1
but
a = -1 ; a^0
returns
1
wolfram alpha agrees that -1^0 = -1, but I believe that everybody else says that x^0 = 1, for all x not equal to 0.
The -1^0 = -1 appears to be a bug? But it's hard to believe that Mathematica has exactly the same bug!
댓글 수: 0
채택된 답변
John D'Errico
2016년 3월 8일
What you apparently misunderstand is the idea of operator precedence.
There is a difference between these two operations:
-1^0
ans =
-1
and
(-1)^0
ans =
1
What you need to recognize is that ^ operates before the unary minus operator. Once you recognize that, you recognize it is not a bug, but a design question, and one that makes some sense.
You are not the first person to trip over it though. I've seen this question asked before. :)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!