10 raised to the power

22 ビュー (過去 30 日間)
Snoopy
Snoopy 2021 年 8 月 12 日
編集済み: Snoopy 2021 年 8 月 12 日
When I multiply two matrices element wise (which is probably not important to my question), some numbers appear as 3.400000000000001e+03 instead of simply 3400. Why?

採用された回答

Star Strider
Star Strider 2021 年 8 月 12 日
Put simply: format if you are viewing them in the Command Window. This is likely also due to floating-point approximation error, as described in Floating-Point Numbers.
Otherwise, change the format descriptor in fprintf formatSpec or similar function calls to change the way they are displayed in those function calls.
There is not enough detail in the Question to provide an exact response.
.
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 8 月 12 日
format long g
delta = 0.1;
C = 0; for K = 1 : 34000; C = C + delta; end
C
C =
3399.999999998
C - 3400
ans =
-1.99679561774246e-09
1/10 is not exactly representable in binary floating point. When you compute with non-integer floating point numbers, unless you restrict yourself to pure powers of 2 such as 0.25, then you should expect that the result may be different than you would expect mathematically.
Star Strider
Star Strider 2021 年 8 月 12 日
@Walter Roberson Thank you!
.

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

その他の回答 (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