• C

# Numerical Analysis

How can I calculate the 'Error Function'*  I need a full level of accuracy.  My current method of integrating using trapezium rule and simpson's rule etc.. are not accurate and too slow.  I need something like Excel must use uses to calculate to full accuracy in quick time.

Links to sites with algorithms or code would be ok, i'm envisaging some sort of convergent number sequence must exist.

*Integral of 2/sqrt(pi) * exp(-x**2)
LVL 18
###### Who is Participating?

Commented:
Bluntly stolen from Abramowitz and Stegun:

erf(x)= 1-e^(-x*x)*sum(i,1,5), a{i]*t^i) + e(x)

where t=1/(1+p*x)

where p= 0.3275911

where a[1]=  0.254829592
a[2]= -0.284496736
a[3]=  1.421413741
a[4]=-1.453152027
a[5]=1.061405429

The inaccuracy e(x) is at most 1.5E-7

kind regards,

Jos aka jos@and.nl
0

Commented:
http://www.llp.fu-berlin.de/lsoft/B/1/index.shtml
It if source c/c++ codes for every
in Numeric Analysis!
0

progAuthor Commented:
That looks like an improvement on the formula I've got.

Code unusual not c?  I don't know how to code it into c.
0

progAuthor Commented:
With some mods i'm getting good answers in VB

1 - Exp(-x ^ 2) * (0.254829592 * t - 0.284496736 * t ^ 2 + 1.421413741 * t ^ 3 - 1.453152027 * t ^ 4 + 1.061405429 * t ^ 5)

Is what I used.

0

progAuthor Commented:
The e(x) at the end through me.
0

Commented:
The e(x) term is the absolute error (sic) of this approximation of the
error function; and, of course, it is not part of the approximation formula
itself ...

kind regards,

Jos aka jos@and.nl
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.