Rounding error for simple array
3 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!