How to increase the precision of MATLAB R2015b

조회 수: 1 (최근 30일)
Kallam Haranadha Reddy
Kallam Haranadha Reddy 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by