When I create a simple array from 0 to 0.6 with 0.1 spacing, the values are not precise. There is an error in some of them on the order of 10^-17. I've managed to work around by creating an array from 1 to 6, then dividing by 10, but I'm looking to understand why this happens so I can avoid similar precision errors in the future.
X = 0:0.1:0.6;
X == [0 0.1 0.2 0.3 0.4 0.5 0.6]
ans =
1 1 1 1 0 1 1
X(5) - 0.4
ans = -5.5511e-17
X = (0:1:6)/10;
X == [0 0.1 0.2 0.3 0.4 0.5 0.6]
ans =
1 1 1 1 1 1 1
X(5) - 0.4
ans = 0