How can I use VPA to do 32 digit precision computations?
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Walter Roberson
on 28 Jan 2011
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
0 Comments
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!