0

I have a problem with Matlab. Mainly 5*10^-15!=5e-15. Depending on how I declare a number (e or 10^) it is different saved (5.000000000000001 vs. 5.000000000000000). It makes problems with comparing values declared with calculated (declared were with 10^, matlab saves calculations with e).

Anyone has some idea why does it happen? It is some kind of matlab's approximation?

For now I can declare everything in scientific notation, but then if I would like to make exponent a variable A I would have problem with writing e.g. 5eA.

Thanks for answers :)

trooper
  • 4,444
  • 5
  • 32
  • 32
Szczupak
  • 3
  • 1
  • 1
    Another case of floating point errors. I would suggest to read into the basics here (http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html). – Daniel Dec 13 '14 at 21:33

1 Answers1

0

It has to do with precision errors and tolerances. The way to deal with it is to compare the difference as opposed to a tolerance level, ex;

eps = 0.00000001
if (abs(a-b) < eps) //success
AMG
  • 704
  • 1
  • 8
  • 20