How to increase the precision of MATLAB R2015b

1 回表示 (過去 30 日間)
Siva
Siva 2019 年 2 月 9 日
コメント済み: Yair Altman 2019 年 2 月 11 日
how can we increase the precision of MATLAB R 2015b

採用された回答

John D'Errico
John D'Errico 2019 年 2 月 9 日
編集済み: John D'Errico 2019 年 2 月 9 日
Short answer: You can't.
Longer answer: Y o u c a n ' t d o t h a t. Well, not easily. ;-)
Seriously, there is no floating point data type in MATLAB that is longer than a double, UNLESS you are willing to use one of three choices. That is, you can use the symbolic toolbox, or you can use my VPI toolbox, or you can use my HPF toolbox. The latter toolboxes are found on the File Exchange, for free download.
x = sym(2)^300
x =
2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376
x = vpi(2)^300
x =
20370359763344860862684456884093781610514683936659362506361404493543
81299763336706183397376
x = hpf(2,100)^300
x =
2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376
So I've created the number 2^300 in three distinct ways there in MATLAB. First, as a symbolic toolbox number. Then as an integer, using my VPI. Finally, as a floating point number in 100 digits of precision, using my HPF. (Ok, I guess you can also use some Java big number tools in MATLAB. They are kind of inconvenient though to use, wthout writing an overlay class to use them. I have actually done that for the BigInteger tools, to create my VPIJ class, which essentially replaces and boosts the speed of VPI.)
import java.math.BigInteger
X = java.math.BigInteger.pow(java.math.BigInteger(2),300)
X =
2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376
As a double, this is all you can get, and essentially no more:
format long g
2^300
ans =
2.03703597633449e+90
A serious flaw of all three options is they will be relatively slow. That is, if you want to work in high precision, then expect things to get really slow, since MATLAB is highly optimized to work with doubles, but NOT so for other classes of numbers.
Two other tools already in MATLAB will allow you to work over a slightly larger set of integers than a double will allow. Thus in integer form you can use int64 and uint64. But a double stops at 2^53-1 to represent integers eactly, whereas uint64 goes up only to 2^64-1. Hardly worth the bother for a few more powers of 2.
In the end, you are best off if you learn to do your work in double precision. This is the art and skill of numerical analysis, learning how to do computations without resorting to the lazy but terribly slow solution of high precision.
  1 件のコメント
Yair Altman
Yair Altman 2019 年 2 月 11 日
John - it would be great if you could post VPIJ on FEX/Github (or somewhere else, as a commercial tool). We've waited a long time for it, and I'm certain that it will be very warmly received.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by