Why is 10^5 more expensive than 10e5?

1 回表示 (過去 30 日間)
Mahdi
Mahdi 2014 年 5 月 30 日
編集済み: dpb 2014 年 5 月 30 日
As Jan mentioned in this post, what's the reason behind it?

採用された回答

dpb
dpb 2014 年 5 月 30 日
10^N is a computational expression whereas 10EN is a literal constant. So, the former requires computation (and the exponential is moderately compute-intensive) whereas the latter simply is a conversion from character to numeric representation. Takes (comparatively) little processing internally to do so.
  2 件のコメント
Mahdi
Mahdi 2014 年 5 月 30 日
Thank you :)
dpb
dpb 2014 年 5 月 30 日
編集済み: dpb 2014 年 5 月 30 日
One additional comment and a difference between compiled languages and interpreted ones is that 10^5 is, while a numeric expression, ultimately a constant. Compiled languages will evaluate this at compile-, not run- time and store the result in the object file so from a computational standpoint in that case they're the same.
The difference is that in an interpreted language, the expression is not evaluated until run-time(+) and if it were in a loop it would be evaluated every time as well.
(+) This is w/o the JIT compiler, of course, which may (or again may not, TMW doesn't and won't say :) ) be able to recognize the constant and do it only once, too. But, in general, the admonition to avoid computing constants in Matlab if possible is still a good suggestion.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by