Stuart’s MATLAB Videos

Watch and Learn

Video tutorial: Tolerances in comparisons

Sometimes you will do a calculation where the answer looks like ‘0’ or ‘1’ or some other number like that. The natural thing to do is to do a test like this:

if (answer == 1)
     Do something
end
However, if the calculation was done in double precision, answer might actually be 1.000000001 or something like that. This video discusses a strategy for overcoming this:

if abs(answer - 1) < 1e-14
     Do something
end
Video Player is loading.
Current Time 0:00
Duration 2:23
Loaded: 6.97%
Stream Type LIVE
Remaining Time 2:23
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected
  • en (Main), selected
     
    |
    • print

    Comments

    To leave a comment, please click here to sign in to your MathWorks Account or create a new one.

    Loading...
    Go to top of page