Increase precision of digits

I am dealing with numbers around 10^-18. Matlab type double only handles up to 10^-15. Is there a way to increase the number of digits? Many thanks.

 Respuesta aceptada

Tobi12
Tobi12 el 14 de En. de 2015

0 votos

Thanks for your replies. Sorry, maybe I was not precise enough in my question.
I am dealing with numbers like -0.897214128288675 * (1.0e+03).
For my calculation I need more accuracy than above -> 18 digits after the comma would be excellent.
Also, I am working with arrays...

5 comentarios

Iain
Iain el 14 de En. de 2015
Depending on what you're doing, 64 bit integers can represent almost 19 digits.
Why do you need more than 16 digits of accuracy?
Tobi12
Tobi12 el 14 de En. de 2015
Editada: Tobi12 el 14 de En. de 2015
I am numerically trying to solve an integral equation. For this purpose I had to substitute a log-function.
After my iteration in the "log-domain", I need to re-substitute with exp-function in order to find the results.
It turns out that the iteration in the "log-domain" is quite good (input/output identical up to 10^-14), however, in the "exp-domain" is not good enough.
...
I just tried the uint64() function for an arrays. Unfortunately the exp() function does not work then anymore...
Titus Edelhofer
Titus Edelhofer el 14 de En. de 2015
Integers will not help you, at least not without effort. I would recommend to try the symbolic toolbox with VPA.
Or rethink your algorithm ;-).
Titus
Tobi12
Tobi12 el 14 de En. de 2015
I am now using the sym. tool box. That makes my algorithm increadibly slow.
Isn't there another solution?!?!
Titus Edelhofer
Titus Edelhofer el 14 de En. de 2015
Hmm, not really. That's why numerical analysts have been working for decades to think of numerically stable algorithms. As said before, not often you have problems where adding digits is the brute force attempt to save a bad/unstable algorithm from failing (not saying that this is indeed the case for you!).
Sorry,
Titus

Iniciar sesión para comentar.

Más respuestas (2)

Titus Edelhofer
Titus Edelhofer el 14 de En. de 2015

0 votos

Hi Tobi,
this is not really true:
x = 2e-127;
y = 3e-126;
x*y
ans =
6.0000e-253
I think you mix up the size of numbers and precision? Could it be that your problem is more like
a = 1+1e-18
a =
1
Titus

5 comentarios

adi
adi el 8 de Dic. de 2019
hey,
i have the exact problem you described.
how can i fix it?
thanks
Rik
Rik el 8 de Dic. de 2019
Do you really need such a large range of decimal precision?
Possible solutions if you indeed need this are linked in several comments in this thread.
adi
adi el 8 de Dic. de 2019
i have 1+7e-6
and it gives me 1 , im dealing with electric fields and i need to have high resolution.
thanks
Rik
Rik el 8 de Dic. de 2019
No, it only displays as a 1. Try the code below to see that 7 digits is not an issue at all.
val=1+7e-6;
clc
fprintf('%.8f\n',val)
adi
adi el 9 de Dic. de 2019
thank you!

Iniciar sesión para comentar.

Guillaume
Guillaume el 14 de En. de 2015

0 votos

Due to the way double values are stored the accuracy of a double value depends on its magnitude. At 1e-18, that accuracy is around 2e-34:
>> eps(1e-18)
ans =
1.92592994438724e-34
Of course, if the magnitude increases, the accuracy decreases.
>>eps(10)
ans =
1.77635683940025e-15
There is no floating-point data type in matlab with more accuracy than double.
If you want fixed accuracy regardless of the magnitude of the number, you have to use a fixed-point data type (double is floating point). I believe there is a matlab toolbox for that but I don't know anything about it.
Another option is to use java's BigDecimal:
>>n = java.math.BigDecimal(java.math.BigInteger('1'), 24)
n =
1E-24
>>m = n.add(java.math.BigDecimal(10))
m =
10.000000000000000000000001

2 comentarios

Titus Edelhofer
Titus Edelhofer el 14 de En. de 2015
Or use variable precision arithmetic from symbolic toolbox, if you need more (relative) accuracy. http://www.mathworks.com/help/releases/R2014b/symbolic/vpa.html
But I would suggest to let us know some more details, most often 16 digits should be enough ...
Titus
John D'Errico
John D'Errico el 14 de En. de 2015
Editada: John D'Errico el 14 de En. de 2015
Or use my HPF toolbox , which does allow your choice of higher precision in a floating point form. It is on the file exchange.
So in 100 decimal digits of precision...
exp(hpf('1.23',100))
ans =
3.421229536289673573790152351452246322159257631512470074140348979345525540446010876820674847912376597
log(ans)
ans =
1.23

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 14 de En. de 2015

Comentada:

adi
el 9 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by