MATLAB: Interval between colon-generated vector

colondiff()

Hey all,
I'm getting some weird behavior when I'm creating a vector using the colon function. One would expect if I do a diff function on a vector, it would return a single value, being equal to the second input of colon. I seem to be getting some floating-point instability. Please see the attached screenshot which will better explain the problem. Any suggestions as to what may be happening?
Thanks! Trevor

Best Answer

This is explained in the FAQ, because it is a frequently asked question:
So you see, the observed behavior is not "weird", but expected if you consider the limited precision of floating point values according to the IEEE754 standard.