What method does Matlab use to compute the erf function?
5 次查看(过去 30 天)
显示 更早的评论
I have a quadrature integration technique that I wish to test by comparing to "truth" for integrating a Gaussian, so I'm using the erf function to generate the "truth" integral of the Gaussian. What method does Matlab use to compute erf? Some sort of quadrature? Another method? Also, how accurate is it?
0 个评论
回答(1 个)
John D'Errico
2015-4-8
It will NOT be quadrature.
Instead, I'd look first at a reference like Abramowitz and Stegun, where you will find approximations for erf. A quick check of A&S shows some rational polynomial approximations 7.1.25, 7.1.26, 7.1.27, and 7.1.28 that are decent, but not truly sufficiently accurate for double precision.
So next I looked at the classic by Hart, "Computer Approximations". It offers a variety of approximations that yield as much as 23 digits of accuracy, so entirely adequate for double precision work (essentially 16 digits.)
The help docs for erf and erfc do not indicate exactly which one they use, but I can assure you that it will be something along those lines.
As a test, lets see how well erf does. At the top end, we can see more by looking at erfc, its cousin, since erf will block up at 1 there.
vpa(erfc(sym(12)))
ans =
1.3562611692059042127803061565904e-64
format long
erfc(12)
ans =
1.356261169205904e-64
which to me looks like a pretty good job. Of course, if you also have the symbolic toolbox, then just use that, as I have done above. There you will get as much accuracy as anyone can want.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!