Dealing with small numbers in matlab
15 views (last 30 days)
Show older comments
Hello to Everyone,
I'm a beginner on Matlab programming, at the moment I'm dealing with a physical phenomena which I'm using a small numbers in the order of magnitude of 10^ (-30) approximately, therefore, when I run the program, I get a catastrophic results,.
So what I understand is that maybe, when the program is running, operations like addition and subtraction are losing their accuracy ( for Example : 1- 10^ (-30) = 1 in Matlab). So, I started to learn about the floating point number, but I didn't find the exact answer to my problem,
Thank you for any helping PLZ!!
4 Comments
Andrew Janke
on 31 Jan 2020
Here is the document you should read to get the background on what all is going on here: What Every Computer Scientist Should Know About Floating-Point Arithmetic - https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Walter Roberson
on 31 Jan 2020
John is correct, if your values differ by that many orders of magnitude then adding or subtracting them is essentially meaningless. MATLAB considers double precision 1 to only be known to within about 1e-16.
If you switch to symbolic then please remember to switch to rational numbers and uncertainties, such as converting f=1.234e-5 to
syms delta
assume(-sym(5)*sym(10)^-9 <= delta & delta < sym(5)*sym(10)^-9)
f=sym(1234)/sym(10)^8 + delta
and do interval calculations on the final formula to minimize and maximize each subexpression that involves delta taking into account the bounds, so that you arrive at a range of results all of which could be true given the uncertainty in expressing f.
Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!