Rounding error for simple array
显示 更早的评论
I have noticed a very strange issue using R2012a installed on Windows 7.
I was creating a very simple array a = [0.2:.1:1.2]'
I then searched for the index where a == 0.6 and kept getting no hit.
Confused, I looked at 'a' in the command window (in format long e) and was shocked to see:
a =
2.000000000000000e-01
3.000000000000000e-01
4.000000000000000e-01
5.000000000000000e-01
6.000000000000001e-01
7.000000000000000e-01
7.999999999999999e-01
8.999999999999999e-01
1.000000000000000e+00
1.100000000000000e+00
1.200000000000000e+00
0.6 , 0.8 and 0.9 are all off by the final machine error digit.
ANy idea what is causing this? Is this a known bug?
Update: To throw more fuel on the fire doing a = [2:1:12]./10 seems to work just fine.
回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!