1

Evaluate,

$$\dfrac{1}{\sqrt{2\,\pi}}\int_{-\infty}^{0.5365}e^{-x^2/2}\,dx$$

In other words, how do I find $N (0.5365)$, where $N(x)$ denotes the $cdf$ of the standard normal random variable?

QFi
  • 1,215
L.mak
  • 201
  • 1
  • 3
  • 8

3 Answers3

4

You can make a series expansion for $e^{-x^2/2}$ at $x=0$:

$$e^{-x^2/2}=1-\frac{x^2}{2}+\frac{x^4}{8}-\frac{x^6}{48}+\frac{x^6}{484}-\ldots$$

We want the integral

$$\int_0^x e^{-t^2/2} \,dt=\frac{x}{\color{blue}1\cdot 1}-\frac{x^3}{\color{blue}2\cdot 3}+\frac{x^5}{\color{blue}8\cdot 5}-\frac{x^7}{\color{blue}{48}\cdot 7}+\frac{x^9}{\color{blue}{384}\cdot 9}-\ldots$$

Without the blue factors the series is

$$\sum_{k=0}^{\infty} (-1)^k\frac{x^{2k+1}}{2k+1}$$

A formula for the sequence $1,2,8,48,484,..$ can be found using OEIS. The result is $2^k\cdot k!$. Therefore $$\int_0^x e^{-t^2/2} \,dt=\sum_{k=0}^{\infty}(-1)^k\frac{x^{2k+1}}{(2k+1)\cdot 2^k\cdot k!}$$

And finally

$$\frac1{\sqrt{2\pi}}\int_{-\infty}^x e^{-t^2/2} \,dt=\frac12+\frac1{\sqrt{2\pi}}\cdot \sum_{k=0}^{\infty}(-1)^k\frac{x^{2k+1}}{(2k+1)\cdot 2^k\cdot k!}$$

If $x=0.5365$, already for $k=3$ one gets a good approximation since the approximated value is 0.704193, which is identical to the result of the online calculator.

callculus42
  • 30,550
2

If you look at the definition of the error function, you will easily understand that $$I(a)=\dfrac{1}{\sqrt{2\,\pi}}\int_{-\infty}^{a}e^{-x^2/2}\,dx=\frac{1}{2} \left(1+\text{erf}\left(\frac{a}{\sqrt{2}}\right)\right)$$ The Wikipedia page also gives the Taylor expansion of it $$\operatorname{erf}(z)= \frac{2}{\sqrt{\pi}}\sum_{n=0}^\infty\frac{(-1)^n z^{2n+1}}{n! (2n+1)} =\frac{2}{\sqrt{\pi}} \left(z-\frac{z^3}{3}+\frac{z^5}{10}-\frac{z^7}{42}+\frac{z^9}{216}-\ \cdots\right)$$ Using it, you then have $$I(a)=\frac{1}{2}+\frac{a}{\sqrt{2 \pi }}-\frac{a^3}{6 \sqrt{2 \pi }}+\frac{a^5}{40 \sqrt{2 \pi }}-\frac{a^7}{336 \sqrt{2 \pi }}+\frac{a^9}{3456 \sqrt{2 \pi }}+O\left(a^{11}\right)$$ Using it for different values of $n$ and $a=0.5365$, you would get $$\left( \begin{array}{cc} n & I(0.5365) \\ 0 & 0.7140325334 \\ 1 & 0.7037649558 \\ 2 & 0.7042082568 \\ 3 & 0.7041930668 \\ 4 & 0.7041934919 \\ 5 & 0.7041934818 \\ 6 & 0.7041934820 \end{array} \right)$$ If you prefer not to use series expansion, look at this post where are proposed two rather simple approximations $$\mathrm{erf}\!\left(X\right)\approx \sqrt{1-\exp\Big(-\frac {4X^2} {\pi} \Big)}\tag 1$$ $$\mathrm{erf}\!\left(X\right)\approx\sqrt{1-\exp\Big(-\frac 4 {\pi}\,\frac{1+\alpha\, X^2}{1+\beta\, X^2}\,X^2 \Big)}\tag 2$$ 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 }$$ Approximation $(1)$ would give $0.704592$ and approximation $(2)$ would give $0.704193$.

  • 1
    $\frac{1}{2} + \frac{1}{2} \mathrm{erf} \left(\sqrt{\frac{1}{2}} a \right)$ has undesirable numerical properties (subtractive cancellation). Preferred: $\mathrm{normcdf}\left(a\right) = \frac{1}{2} \mathrm{erfc} \left(-\sqrt{\frac{1}{2}} a \right)$. – njuffa Apr 08 '17 at 18:07
  • @njuffa (By my calculations) using Claude Leibovici's eqtn(1) for erf(X) and that erfc(X)=1-erf(X) then using your eqtn for normcdf(a) only works for a<=0. Claude's equations only work for a>=0. Both your eqtn and Claude's equations give results which are symmetrical about a=0. In both cases, inside the regions of error we can subtract the given output value from 1 to yield the 'correct' adjusted value. But when using Claude's eqtn(1) for erf(X) his adjusted cdf curve and your adjusted cdf curve are not coincident. – steveOw May 12 '22 at 23:01
  • 1
    @steveOw Mathematically, the CDF of the normal distribution with mean $\mu$ and standard deviation $\sigma$ is $\frac{1}{2} \mathrm{erfc} \left(\frac{\mu-x}{\sqrt{2}\sigma}\right)$. See here, for example. For the standard normal distribution with $\mu=0$ and $\sigma=1$ this turns into what I wrote above. I don't see an error in what I wrote. – njuffa May 12 '22 at 23:19
  • @njuffa Thanks. I'm applying Claude's $erf(X)$ equation between $-4<a<+4$ assuming $\mu=0$ and with $X=a/\sqrt{2}$. Which gives the same value irrespective of the sign of $a$. I guess that is where my problem lies. – steveOw May 12 '22 at 23:48
  • Claude's expression for $I(a)$ as a power series of $a$ seems to work (approximately). With mean = $0$ and $\sigma=1$ for $a=+/- 2$ to get $|\phi(a)|<1.0$ requires $n>=11$. – steveOw May 13 '22 at 13:15
0

I use Simpson's Method to compute such function. There is no analytic exact solution to this integral.

QFi
  • 1,215
  • 1
    Can you please show the details on how you use it in this specific . I'm very interested. I don't see any roots how can we write it in a way that Newton's method can be used? – Ahmed S. Attaalla Apr 08 '17 at 03:45
  • @AhmedS.Attaalla Simpson's Method. I fixed my post. Thank you. – QFi Apr 08 '17 at 05:02