Borrar filtros
Borrar filtros

How can I use VPA to do 32 digit precision computations?

2 visualizaciones (últimos 30 días)
helia
helia el 28 de En. de 2011
I need to do very high precision computation (32 digit) and therefore I started to work with vpa. I eaither can't get it right or there is some bug with this function. Here is a simple test that I run:
>> clear all;syms p; f=p^10; vpa(subs(f,p,0.1),32)
ans =
0.000000000100000000000000055342008016114
>> clear all;syms p; f=p^10; vpa(subs(f,p,0.1),16)
ans =
0.0000000001000000000000001
>> clear all;syms p; f=p^10; vpa(subs(f,p,0.1),8)
ans =
0.0000000001
One would hope that the high precision of 32 digits, would give correct result for 10^(-10). Can you please help me understand what is goin on here?

Respuestas (1)

Walter Roberson
Walter Roberson el 28 de En. de 2011
For further reading on this topic, please see the FAQ
When you are doing the subs(), you are substituting in the binary floating point representation of 0.1 . The closest to 0.1 that can be represented is 0.1000000000000000055511151231257827021181583404541015625 .
You can fix your code by using sym('0.1') instead of 0.1

Community Treasure Hunt

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

Start Hunting!

Translated by