Colon operator numerical error
2 views (last 30 days)
Show older comments
When I create a vector using the colon operator I noticed for certain vectors there is a small numerical error in the values returned. For example: >> a = 0:.1:1
a =
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
>> a(4)
ans =
0.3
>> a(4) == .3
ans =
0
>> a(4) - .3
ans =
5.5511e-17
I find this very strange. Do other people have this same problem?
0 Comments
Accepted Answer
Walter Roberson
on 13 May 2011
2 Comments
Jan
on 13 May 2011
To be exact: I have the same *behaviour*, which is caused by the underlying representation of numbers. A *problem* occurs only, if a user has not matching expectations.
More Answers (0)
See Also
Categories
Find more on Annotations 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!