Info

This question is closed. Reopen it to edit or answer.

Different results in comparison of the same number, one being approach from 0.2 and the other from 0.1

1 view (last 30 days)
I approach 0.8 with two different intervals first with intervals of 0.1 it does it one more time than needed and then with intervals of 0.2 and that is fine.
I can also approach a different number like 1.2 and there is also ok, but 0.8 being approach by 0.1 crashes. My initial guess is that it has something to do with the way matlab handles the numbers, but honestly I have no clue on what is happening. Is there any way to solve this?? Below is some code that reproduce what I'm saying. Just in case you might ask I try this on a colleague computer and has the same behaviour, so its not exclusive to my computer
>> h = 0.1; >> while h < t h = h+0.1; disp(h) end 0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
>> h = 0.2; >> while h < t h = h+0.2; disp(h) end 0.4000
0.6000
0.8000

Answers (1)

dpb
dpb on 22 Apr 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!