Low precision of floats?
Show older comments
I want to calculate digamma(x),1<x<2 with high precision. I wrote the code
psi(vpa(3/2, 100))
Now I wanted to check the result with the wolfram alpha result of 0.036489973978576520559023667001244... But when I write
x = vpa(0.03648997397857652055, 100)
The stored number is completly wrong after 18 digits (0.03648997397857652036...). How can I save floats with more than 18 digits? Is there a better way to achieve what I am trying to do?
Accepted Answer
More Answers (2)
vpa('0.036489973978576520559023667001244',100)
Don't call vpa first. Perform the calculation symbolically then use vpa on the result.
onePointFive = sym(3/2)
y = psi(onePointFive)
Let's check your statement "Now I wanted to check the result with the wolfram alpha result of 0.036489973978576520559023667001244... But when I write"
vpa(y, 200)
Looks good to me.
1 Comment
Martin Clever
on 29 Aug 2023
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!