MATLAB: Looks like a machine error

errorlinuxnumerical integration

Dear all,
I need help with a tiny section of a code which involve a basic computation(seemingly):
The following operation,
>> ((-0.085 - -0.1)/(-0.085 - -0.098))*0.6 -(0.005/(-0.085 - -0.098))
gives
>> 0.3077
However, when I replace the figures with variables as below:
>> ((xp32 - xp12new)/(xp32next - xp12next))*U(tn,j+1)-(Dt/(xp32next - xp12new))
Here the variables have equal values of the figures in the preceeding operation.
I get a wierd answer:
>> 0.3590
I don't know what I'm missing here. Thanks in advance.

Best Answer

Your variables appear to contain the same values as the hard-coded constants, but looks can be deceiving. The small differences between the variable values and the constant values (which don't appear using the default display format but still exist in the stored values) result in the different answer.
You can check this by subtracting the constant values from the variables and noting that you receive a non-zero value.
xp32 - (-0.085) % Not exactly 0, but very small
You can also check this by changing the display format.
format longg
xp32 % not exactly -0.0085