Borrar filtros
Borrar filtros

How to increase the precision of MATLAB R2015b

3 visualizaciones (últimos 30 días)
Kallam Haranadha Reddy
Kallam Haranadha Reddy el 9 de Feb. de 2019
Comentada: Yair Altman el 11 de Feb. de 2019
how can we increase the precision of MATLAB R 2015b

Respuesta aceptada

John D'Errico
John D'Errico el 9 de Feb. de 2019
Editada: John D'Errico el 9 de Feb. de 2019
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 comentario
Yair Altman
Yair Altman el 11 de Feb. de 2019
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by