How to improve accuracy?
Show older comments
I am trying to evaluate a matlab code. A snippet is shown. I am facing an issue with accuracy of digits. I expect the answer to be 0 but get a non-zero value. My entire code deals with many more similar calculations. Is there a way to improve the accuracy of the code. I am using double precision. Any help would be appreciated
Code:
Tw = 306.13;
Tsat = 302.63;
rho_l = 1440.8;
hlv = 126e3;
Adis = 2e-21;
Pc = (Tw/Tsat - 1)*hlv*rho_l;
del1 = (Adis/Pc)^(1/3);
Pc - Adis/del1^3 %Expected answer = 0
2 Comments
Use vpa function if you have the Symbolic Math Toolbox with your calculations. The vpa function also allows you to define the precision by simply adding a second argument to the function;
i.e., "vpa(1/3+5*6-2,32)"
clear
Tw = 306.13;
Tsat = 302.63;
rho_l = 1440.8;
hlv = 126e3;
Adis = 2e-21;
Pc = vpa((Tw/Tsat - 1)*hlv*rho_l);
del1 = vpa((Adis/Pc)^(1/3));
vpa(Pc - Adis/del1^3) %Expected answer = 0, results -1.5e-32
Siddharth Iyer
on 12 Jun 2018
Accepted Answer
More Answers (0)
Categories
Find more on Number Theory 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!