# Gaussian Integral Error Function Approximation

I was just wondering is there a way to approximate the error function arising from the indefinite Gaussian Integral:

$$\int e^{-x^2}dx={\frac{\sqrt\pi}{2}}\text{erf}(x)$$

For instance, like I get the proofs to solving this integral with limits from $$[0.\infty)$$, however I just want to numerically approximate this integral when our limits are any arbitrary $$[a,b]$$ for $$a$$ and $$b$$ are integers. How would I approximate numerically for this integral when the limits are say $$[1, 2]$$? What value to we plug in to the error function? Would it be like this? $$\int_1^2 e^{-x^2}dx=\frac{\sqrt{\pi}}{2}\bigg(\text{erf}(2)-\text{erf}(1)\bigg)$$

All in all my question is basically this:

Question 1: How do we numerically approximate the error function?

Question 2: How do we find the definite integral of the Gaussian integral?

I would appreciate the help.

EDIT: From related posts I have seen, I see that the error function can be expressed as this power series:

$$\frac{\sqrt\pi}{2}\text{erf}(z)=\sum_{n=0}^\infty\frac{(-1)^nt^{2n+1}}{(2n+1)n!}$$

through integration term by term, but I am just not sure how to approximate this function between arbitrary integer limits $$[a,b]$$.

• Taylor series expansion. When comes to approximation, it's almost always about approximating with Taylor series Jul 22 '19 at 13:49
• Like I get the series expansion of the Taylor Series, but how do we plug in our limits in to the Taylor expansion? Jul 22 '19 at 13:53
• Integrate term by term. I'm not sure about how the remainder of the series behaves in that situation though Jul 22 '19 at 13:55

Beside series expansions, there are some approximations of the function.

For example, one I proposed a while ago (based on purely mathematical considerations) is $$\text{erf}(x)\approx \sqrt{1-\exp\Big(-\frac 4 {\pi}\,\frac{1+\alpha\, x^2}{1+\beta \,x^2}\,x^2 \Big)}$$ where $$\alpha=\frac{10-\pi ^2}{5 (\pi -3) \pi } \qquad \text{and} \qquad \beta=\frac{120-60 \pi +7 \pi ^2}{15 (\pi -3) \pi }$$

For $$x=1$$ this would give $$0.842654$$ while the "exact" value would be $$0.842701$$.

For $$x=2$$ this would give $$0.995165$$ while the "exact" value would be $$0.995322$$.

Then $$\text{erf}(2)-\text{erf}(1)\approx 0.152511$$ while the "exact" value would be $$0.152621$$.

Edit

I tried to improve the approximation using $$\text{erf}(x)\approx \sqrt{1-\exp\Big(-\frac 4 {\pi}\,\frac{1+\alpha\, x^2+\gamma\,x^4}{1+\beta \,x^2+\delta\,x^4}\,x^2 \Big)}$$ but the formulae become quite messy. However, after going the calculations, what can be observed is that $$\frac \gamma \alpha \approx 0.10454 \qquad \text{and} \qquad \frac \delta \beta \approx 0.09735$$ So, to get simpler formulae, I forced $$\gamma=\frac \alpha {10}$$ and $$\delta=\frac \beta {10}$$. Then, the results are $$\alpha=\frac{20-3 \pi -\pi ^2}{10 (\pi -3) \pi } \qquad \text{and} \qquad \beta=\frac{240-129 \pi +17 \pi ^2}{30 (\pi -3) \pi }$$

For the worked values, the results are now $$0.842704$$ and $$0.995332$$ which are much better. For the difference, $$0.152629$$.

• Could you possibly show me how you got those approximations through derivations? Thank you Jul 23 '19 at 15:40
• Assume the form used for the approximation (this is not new; have a look at the Wikipedia page abour the error function). Now, use a Taylor expansion around $x=0$; this will give you $(\alpha,\beta)$. We could add extra terms but the coefficients become quite ugly. Jul 24 '19 at 2:13

There's a huge literature on methods for the numerical approximation of special functions like $$\mbox{erf}(x)$$. A good place to start is the Digital Library of Mathematical Functions (DLMF) at

https://dlmf.nist.gov/

Your best bet is to make use of a software library that implements $$\mbox{erf}(x)$$ to your required precision rather than trying to implement something yourself.