Computing Error Function
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or computing error bars posting ads with us Mathematics Questions Tags Users Badges Unanswered Ask Question _ Mathematics Stack Exchange how to calculate error function in casio calculator is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a
Inverse Error Function Calculator
minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to accurately calculate the error function erf(x) with a computer? up vote 9
Complementary Error Function Calculator
down vote favorite 2 I am looking for an accurate algorithm to calculate the error function I have tried using [this formula] (http://stackoverflow.com/a/457805) (Handbook of Mathematical Functions, formula 7.1.26), but the results are not accurate enough for the application. statistics algorithms numerical-methods special-functions share|cite|improve this question edited Jan 10 '14 at 4:47 pnuts 1056 asked Jul 20 '10 at 20:20 badp 6741225 You may want to take a look at python's code.google.com/p/mpmath or other libraries that advertise a erf function table "multiple precision" feature. Also, this may be a better question for stack overflow instead, since it's more of a computer science thing. –Jon Bringhurst Jul 20 '10 at 20:26 @Jon: Nope, I'm not interested in a library, there is no such library for the language I'm writing in (yet). I need the mathematical algorithm. –badp Jul 20 '10 at 20:49 Have you tried numerical integration? Gaussian Quadrature is an accurate technique –Digital Gal Aug 28 '10 at 1:25 GQ is nice, but with (a number of) efficient methods for computing $\mathrm{erf}$ already known, I don't see the point. –J. M. Aug 29 '10 at 23:07 add a comment| 4 Answers 4 active oldest votes up vote 9 down vote accepted I am assuming that you need the error function only for real values. For complex arguments there are other approaches, more complicated than what I will be suggesting. If you're going the Taylor series route, the best series to use is formula 7.1.6 in Abramowitz and Stegun. It is not as prone to subtractive cancellation as the series derived from integrating the power series for $\exp(-x^2)$. This is good only for "small" arguments. For large arguments, you can use either the asymptotic series or the continued fraction representations. Otherwise, may I direct you to these papers by S. Winitzki that give nice approximations to the error function. (added on 5/4/2011) I wrot
Analysis Shared http://math.stackexchange.com/questions/97/how-to-accurately-calculate-the-error-function-erfx-with-a-computer Life Mathematics Science Practical Science Other Private Column Advanced Cal Some functions are limited now http://keisan.casio.com/exec/system/1180573449 because setting of JAVASCRIPT of the browser is OFF. Home/ Special Function/ Error function Error function Calculator Calculates the error function erf(x) and complementary error function erfc(x). xrealnumber 6dgt10dgt14dgt18dgt22dgt26dgt30dgt34dgt38dgt42dgt46dgt50dgt Privacy Policy Terms of use FAQ Contact us © 2016 CASIO COMPUTER CO., LTD.
19 January 2009 by John The question came up on StackOverflow this morning how to compute the error function erf(x) in Python. The standard answer for how to compute anything numerical in Python is "Look in SciPy." However, this person didn't want to take on the dependence on SciPy. I've seen variations on this question come up in several different contexts http://www.johndcook.com/blog/2009/01/19/stand-alone-error-function-erf/ lately, including questions about computing the normal distribution function, so I thought I'd write up a solution.Here's a Python implementation of erf(x) based on formula 7.1.26 from A&S. The maximum error is below 1.5 × 10-7.import math def erf(x): # constants a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 # Save the sign of x sign = 1 if x < 0: sign = -1 x = abs(x) # A error function & S 7.1.26 t = 1.0/(1.0 + p*x) y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x) return sign*yThis problem is typical in two ways: A&S has a solution, and you've got to know a little background before you can use it.The formula given in A&S is only good for x ≥ 0. That's no problem if you know that the error function is an odd function, i.e. erf(-x) = -erf(x). But if you're an error function calculator engineer who has never heard of the error function but needs to use it, it may take a while to figure out how to handle negative inputs.One other thing that someone just picking up A&S might not know is the best way to evaluate polynomials. The formula appears as 1 - (a1t1 + a2t2 + a3t3 + a4t4 + a5t5)exp(-x2), which is absolutely correct. But directly evaluating an nth order polynomial takes O(n2) operations, while the factorization used in the code above uses O(n) operations. This technique is known as Horner's method. Categories : Computing Math PythonTags : Python Special functionsBookmark the permalink Post navigationPrevious PostDraw a bigger pictureNext PostStand-alone normal (Gaussian) distribution function 14 thoughts on “Stand-alone error function erf(x)” Sergey Fomel 19 January 2009 at 16:21 erf is actually a standard function in C "math.h"For some reason, it is not included in Python's math module but, if you have SWIG, it is easy to write a SWIG wrapper for it. An example on a Linux machine: bash$ cat erf.i %module erf #include double erf(double); bash$ swig -o erf_wrap.c -python erf.i bash$ gcc -o erf_wrap.os -c -fPIC -I/usr/include/python2.4 erf_wrap.c bash$ gcc -o _erf.so -shared erf_wrap.os bash$ python >>> from erf import erf >>> erf(1) 0.84270079294971489 John 19 January 2009 at 16:30 Thanks! That's handy sample code for other problems too.On POSIX systems, erf is included in math.h. But it's not part of the ISO standard requiremen