What shows up for
nc - 19840
The reason is that the intermediate values in your calculation cannot be stored exactly. Here is one starting point for understanding why that is.
syms deltah nb = sym(128, 'r'); h = sym(0.2, 'r') + deltah; t_s = sym(0.004, 'r'); t_i = sym(0.05, 'r'); s = sym(500, 'r');
nc = nb+(nb*((h+2*t_s+2*t_i)*s));
nc subs(nc, deltah, eps(0.2)) vpa(ans)
nc = 64000*deltah + 19840 ans = 1396115884484853885/70368744177664 ans = 19840.00000000000177635683940025
You can see from this that a difference of 1 bit in the representation of 0.2 makes a difference of
>> vpa(subs(nc,deltah,eps(0.2)) - 19840) ans = 0.0000000000017763568394002504646778106689453
0.2 is not exactly representable in binary floating point: it is an infinite repeating decimal, just like 1/7 is not exactly representable in finite decimal.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!