Matlab is inconsistent when raising numbers to the zero'th power:

2 ビュー (過去 30 日間)
Leo Simon
Leo Simon 2016 年 3 月 8 日
編集済み: Stephen23 2016 年 3 月 8 日
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!

採用された回答

John D'Errico
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. :)
  2 件のコメント
Leo Simon
Leo Simon 2016 年 3 月 8 日
Thanks! Obvious ex post. Expected it had been asked before, but I searched the forum and found nothing.
Stephen23
Stephen23 2016 年 3 月 8 日
編集済み: Stephen23 2016 年 3 月 8 日
Why search the forum? Once again actually reading the documentation would have been a good step:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by