1

If I run x=0:0.1:1; x==0.2, I get equality at the third element (as expected). However, if I change it to x=-1:0.1:1; x==0.2 I no longer get any hits. Why the change? (I am familiar with some details of floating point arithmetic, IEE754, 0.1+0.2 etc. -- but why does this happen here?)

2
  • You might get more robust results using linspace, see stackoverflow.com/questions/26292695/… Commented May 27 at 10:52
  • Why the change? If you start from a different value, the floating-point errors accumulate differently. You can check that in the second case x(13)-0.2 is not exactly zero. So, what is the question exactly (if it is not covered by those linked above)? Commented May 27 at 16:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.