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

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 17 Jan 2014
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)
  1 Comment
Joel
Joel on 17 Jan 2014
Thank you!
sprintf('%.30g - %.30g = %.30g', deltaArray(3,2), d_t, deltaArray(3,2) - d_t)
ans =
0.0951450245961471680056220634469 - 0.0951450245961471263722586400036 = 4.16333634234433702658861875534e-17

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!