Numerical issue in simple summation/addition
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali
am 23 Jan. 2016
Kommentiert: Image Analyst
am 23 Jan. 2016
below code prints 1. But if you have b = 0.2 at the second line, it does not print 1.
a = 0;
b = 0.1;
c = a;
while c < 1
c
c = c+b;
end
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 23 Jan. 2016
It has nothing to do with the version. It has everything to do with digitization/quantization differences as discussed in the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
0 Kommentare
Ali
am 23 Jan. 2016
Bearbeitet: Ali
am 23 Jan. 2016
4 Kommentare
Image Analyst
am 23 Jan. 2016
"What's the fix?" Did you read the FAQ like both Star and I pointed you to? In there is the "fix" or way to deal with the reality of it -- you check against a tolerance.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!