How to stop MATLAB from rounding extremely small values to 0?
28 次查看(过去 30 天)
显示 更早的评论
I have a code in MATLAB which works with very small numbers, for example, I have values that are on the order of 10^{-25}, however when MATLAB does the calculations, the values themselves are rounded to 0. Note, I am not referring to format to display these extra decimals, but rather the number itself is changed to 0. I think the reason is because MATLAB, by default, retains up to 15 digits for its calculations. How can I change this so that numbers that are very very small are retained as they are in the calculations?
0 个评论
回答(2 个)
Walter Roberson
2014-2-21
MATLAB will not change the value to 0. However, it is possible that the result if using the value in an operation is indistinguishable from using 0. For example,
1 + 1E-25
is going to be indistinguishable from
1 + 0
Retaining the value would require a minimum of 84 bits of precision, but MATLAB only calculates to 53 bits.
If you need higher precision then you should use the Symbolic Toolbox. See also today's discussion http://www.mathworks.co.uk/matlabcentral/answers/116949-big-integer-speed-vpi-and-symbolic
0 个评论
Roger Stafford
2014-2-22
The very purpose of floating point numbers is to allow quantities to be represented which are very small or very large. Such numbers can range from somewhere in the neighborhood of 10^-308 up to 10^308 before overflow or underflow occurs. Such small or large numbers can be multiplied without loss of relative accuracy provided the result does not go beyond these limits. However, as Walter has pointed out, when addition or subtraction occurs if both large numbers and small numbers are combined, the small numbers can become overshadowed by the large numbers and their relative accuracy lost. For example the number 1.234e7 is represented with an accuracy of one part in about 10^16 which means the error is around 10^-9. The number 2.345e-7 has an error around 10^-23. If we add them, the answer will only be accurate to around 10^-9, so all but two decimals of that small number have been lost in the process of addition to the large number. This is a limitation imposed by the number of bits used by the double precision floating point numbers which matlab uses, namely 53 binary bits. To do better than this requires the symbolic toolbox or its equivalents, allowing much larger numbers of digits to be used but at the expense of longer computation times.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!