MATLAB: How to tell when you have a precision problem, an equality problem, or a MATLAB bug

equalityMATLABprecision

I am using an educational version of MATLAB R2012a on a Mac running OS X 10.8.5.
I am having issues with equality of two different numbers. When I expand the displayed precision the numbers are exactly the same, so why is my equality failing?
EDU>> deltaArray(3,2)
ans =
0.0951
EDU>> deltaArray(3,2) == d_t
ans =
0
EDU>> d_t
d_t =
0.0951
EDU>> format 'long'
EDU>> d_t
d_t =
0.095145024596147
EDU>> deltaArray(3,2)
ans =
0.095145024596147

Best Answer

  • format long still does not show all of the digits. Try
    sprintf('%.30g - %.30g = %.30g', deltaArray(3,2), d_t, deltaArray(3,2) - d_t)