How does MATLab handle decimal accuracy?

Hi,
I use MATLab to calculate an energy value up to a specific decimal place. However, I have noticed it can only do so up to its 54th decimal place. After that, when adding values (decimals) of the 55th power (numbers like 7.000000000000001e-55), no change is stored.
I have two questions;
  1. Is there something one can do to increase the decimal accuracy? I have read several related topics, and I'm afraid this is not, but it's worth a shot. I thought about storing the decimals places in an array, but MATLab also needs to calculate with this value, which an array would prevent (you'd have to put them in a value again, which would have that problem).
  2. How can I detect the maximum amount of decimal places that the computer can go with? My computer apparently handles 54, but I intend to share my code, and I'd like to give a warning if a user requests more decimal places than their computer will show (assuming this 54-value is different per computer). I read something about the use of eps(E), but I don't quite understand this or how to convert this to the number 54 (now it shows 5.551115123125783e-17)
Kind regards,
Isaiah van Hunen
P.S. I have no problem with rounded of values in my display, I use num2str(E,decimals) to ensure that it is shown to its maximum amount of decimal places.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 5 月 18 日

0 投票

You are not correct:
>> 1e-200+2e-200+3e-200
ans =
6e-200
The limit is 53 binary places:
>> (1+2^(-52)) == 1
ans =
0
>> (1+2^(-53)) == 1
ans =
1
This number, 2^(-52) is also called eps when used in its relative form.
The limit is the same for everyone who uses IEEE 754 Double Precision. You cannot increase it except by switching to the Symbolic Toolbox or by using a third-party package such as John D'Errico's VPI (Variable Precision Integer) from the File Exchange

5 件のコメント

Isaiah van Hunen
Isaiah van Hunen 2016 年 5 月 18 日
編集済み: Isaiah van Hunen 2016 年 5 月 18 日
So any possible solution (VPI also requiring the Symbolic Math Toolbox) would cost money, as I understand. And because of IEEE 754 Double Precision (because of the ..54? :) it cannot be higher than 54; for which I can then safely set a warning? Thanks in advance!
Steven Lord
Steven Lord 2016 年 5 月 18 日
For more information about floating point arithmetic I recommend that you read through the first question in the Math/Algorithms section of the FAQ and the references listed there. Those references describe some of the potential pitfalls you may experience with working with floating point numbers and how to avoid them.
Walter Roberson
Walter Roberson 2016 年 5 月 20 日
John's VPI contribution is free -- but it happens to be restricted to integers. If your code can be programmed in terms of rational numbers then VPI is enough without needing floating point.
Remember the 53 is bits, not decimal places. It works out to _approximately 1E-16. 15 decimal digits in calculations is safe, you get 16 sometimes. This is a relative value, so you cannot get (for example) 432423532 followed by 15 decimal places, only by another 6 or 7.
Remember too that each time you do a floating point multiplication or division (or sine or any of a number of other calculations) you will get some round-off error: at the best of times, the last 1 or 2 bits might not be what you expect, and in the worst of times the round off error can exceed the output value (especially with division.) inv() is a zoo for these kinds of problems.
Isaiah van Hunen
Isaiah van Hunen 2016 年 5 月 21 日
Okay, so roughly said; if using floating point values with no whole numbers (so 0.[...]) and no Symbolic Toolbox, you can only calculate to an accuracy of 15 decimal places?
Walter Roberson
Walter Roberson 2016 年 5 月 21 日
About 15 decimal places from the first non-zero digit.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

製品

質問済み:

2016 年 5 月 18 日

コメント済み:

2016 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by