Dealing with small numbers in matlab

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

Adam Danz
Adam Danz on 13 Jan 2020
Edited: Adam Danz on 13 Jan 2020
Often this means you are using the wrong units. Instead of meters, use nanometers, or picometers, etc. But as much, if you are doing any computation on actual data, if you are adding two numbers and they differ by 30 orders of magnitude, then it does not matter.
For example, suppose you measure two numbers, x and y. They differ by a factor of 10^30. Have you measured both x and y with sufficiently accuracy that you can confidently form the sum or the product of the two? Do you know of many constants in nature that are able to be measured to 30 significant digits? (pi does not count here.)
So, yes, you can use symbolic computation to give better computational accuracy. But high precision computations come at a significnt cost - they are SLOW. And the result still need not have any meaning, unless you know all of your numbers to an essentially immense number of digits.
There will be much you can gain from taking a numerical methods class. You can also learn much simply by reading about floating point arithmetic.
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
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.

Sign in to comment.

Answers (0)

Categories

Asked:

on 13 Jan 2020

Commented:

on 31 Jan 2020

Community Treasure Hunt

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

Start Hunting!