Remember, that Matlab works with the type double, which is a floating point type according to IEEE754. If you define a variable as:
if is displayed as 3.000, when the format in the output to the command window is set to 'shortE'.
Try this:
disp(a - b)
fprintf('%.16g\n', a)
fprintf('%.16g\n', b)
You will see, that Matlab works correctly, but only the rounded output to the command window is confusing.
See also: FAQ: Why is 0.1+0.2 ~= 0.3? and hundreds of other related threads - search e.g. for "IEEE754" or "floating point" in this forum. The tag "faq6.1" is used frequently also for this kind of problems.
Best Answer