error (rounding or user) in simple math op
5 ビュー (過去 30 日間)
古いコメントを表示
I just noticed odd behavior in R2012b that really seems like an error though perhaps I'm making a foolish error?
I enter the following >> 2.7+1.8*[1,2,3,4,5,6,7,8,9]
I expect 4.5 6.3 8.1 9.9 11.7 13.5 15.3 17.1 18.9
I get: ans =
Columns 1 through 5
4.500000000000000 6.300000000000001 8.100000000000001 9.900000000000000 11.699999999999999
Columns 6 through 9
13.500000000000000 15.300000000000001 17.100000000000001 18.899999999999999
This seems odd to me for obvious reasons. Even something simple like
>> 1.8*9
ans =
16.199999999999999
how could this be happening?
Thank you
(p.s. its 8.0.0.783 R2012b)
0 件のコメント
採用された回答
Azzi Abdelmalek
2013 年 1 月 8 日
編集済み: Azzi Abdelmalek
2013 年 1 月 8 日
Use
format short
The problem is simply caused by the way, real data are stored in memory
0 件のコメント
その他の回答 (1 件)
José-Luis
2013 年 1 月 8 日
It is due to numerical precision, and is expected behavior.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!