Compute 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 how to compute error bars Stack Overflow the company Business Learn more about hiring developers or posting ads with how to calculate error function in casio calculator us Mathematics Questions Tags Users Badges Unanswered Ask Question _ Mathematics Stack Exchange is a question and answer site for people
Inverse Error Function Calculator
studying math at any level and professionals in related fields. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers
Complementary Error Function Table
are voted up and rise to the top How to accurately calculate the error function erf(x) with a computer? up vote 9 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 complementary error function calculator 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 "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.
Search All Support Resources Support Documentation MathWorks Search MathWorks.com MathWorks Documentation Support Documentation Toggle navigation Trial Software Product Updates Documentation Home MATLAB Examples Functions Release https://www.mathworks.com/help/matlab/ref/erf.html Notes PDF Documentation Mathematics Elementary Math Special Functions MATLAB Functions erf On this page Syntax Description Examples Find Error Function Find Cumulative Distribution Function of Normal Distribution Calculate Solution of http://www.johndcook.com/blog/2009/01/19/stand-alone-error-function-erf/ Heat Equation with Initial Condition Input Arguments x More About Error Function Tall Array Support Tips See Also This is machine translation Translated by Mouse over text to see error function original. Click the button below to return to the English verison of the page. Back to English × Translate This Page Select Language Bulgarian Catalan Chinese Simplified Chinese Traditional Czech Danish Dutch English Estonian Finnish French German Greek Haitian Creole Hindi Hmong Daw Hungarian Indonesian Italian Japanese Korean Latvian Lithuanian Malay Maltese Norwegian Polish Portuguese Romanian Russian Slovak Slovenian error function calculator Spanish Swedish Thai Turkish Ukrainian Vietnamese Welsh MathWorks Machine Translation The automated translation of this page is provided by a general purpose third party translator tool. MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation. Translate erfError functioncollapse all in page Syntaxerf(x) exampleDescriptionexampleerf(x
) returns the Error Function evaluated for each element of x.Examplescollapse allFind Error FunctionOpen ScriptFind the error function of a value.erf(0.76) ans = 0.7175 Find the error function of the elements of a vector.V = [-0.5 0 1 0.72]; erf(V) ans = -0.5205 0 0.8427 0.6914 Find the error function of the elements of a matrix.M = [0.29 -0.11; 3.1 -2.9]; erf(M) ans = 0.3183 -0.1236 1.0000 -1.0000 Find Cumulative Distribution Function of Normal DistributionOpen ScriptThe cumulative distribution function (CDF) of the normal, or Gaussian, distribution with standard deviation and mean is Note that for increased computational accuracy, you can rewrite the formula in terms of erfc . For details, see Tips.Plot the CDF of the normal distribution with and .x =
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 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 & 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 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