# Integrating the Gaussian Distribution, Error Function Confusion

I am tasked with the following problem for a homework assignment:

Evaluate the following integrals by hand and check your results on Mathematica.

1. Gaussian integral: $$\int_{0}^\infty e^{-(x-\mu)^2 / (2\sigma^2)} \, dx$$, assume $$\mu$$ and $$\sigma^2$$ are real scalars and $$\sigma^2 > 0$$.

My question pertains to the end result of this integration. Mathematica lists the result as $$\begin{equation} \sigma\sqrt{\dfrac{\pi}{2}} \left( 1 + Erf\left(\dfrac{\mu}{\sigma \sqrt{2}}\right) \right) \end{equation}$$

I'm having some trouble getting this same result, and I believe it's because I don't fully understand the error function. Below I lay out my work and show my final answer, which is similar to the above, but there are some glaring differences.

The below text is my completed solution:

Firstly, take $$a = 1/(2\sigma^2)$$. Take \begin{align} I &= \int_{0}^\infty e^{-a(x-\mu)^2} \, dx \nonumber \\[.5em] I^2 &= \left[ \int_{0}^\infty e^{-a(x-\mu)^2 } \, dx \right]^2 \nonumber \\[.5em] &= \left( \int_{0}^\infty e^{-a(x-\mu)^2} \, dx \right) \left( \int_{0}^\infty e^{-a(y-\mu)^2} \, dy \right) \nonumber \end{align} In the above, $$y$$ is simply a dummy variable for the sole purpose of easing the difficulty of integration. Now, perform a change of variables such that $$\beta = x - \mu$$, $$\gamma = y - \mu$$, $$dx = d\beta$$, $$dy = d\gamma$$. Note that with this substitution, our limits of integration change. When $$x=0$$, $$\beta = \mu$$ (similarly for $$y$$). So, \begin{align} I^2 &= \int_{0}^\infty \int_{0}^\infty e^{-a(x-\mu)^2} e^{-a(y-\mu)^2 } \, dx dy \nonumber \\[.5em] &= \int_{-\mu}^\infty \int_{-\mu}^\infty e^{-a(\beta^2 + \gamma^2)} \, d\beta d\gamma \nonumber \end{align} Changing to polar coordinates, we have $$\beta = r\cos\theta$$, $$\gamma = r\sin\theta$$, and $$d\beta d \gamma = r dr d\theta$$ such that, \begin{align} I^2 &= \int_0^{2\pi} \int_{\mu}^\infty r e^{-a r^2} dr d\theta \nonumber \\[.5em] & \text{Take } u = r^2 \text{ such that } du = 2r dr \nonumber \\[.5em] &= 2\pi \int_{\mu^2}^\infty \dfrac{e^{-a u}}{2} du \nonumber \\[.5em] &= \pi \left[- \dfrac{e^{-u / (2\sigma^2)}}{a} \right]_{\mu^2}^\infty \nonumber \\[.5em] &= \dfrac{\pi}{a} \, e^{-a\mu^2} \nonumber \end{align}
Therefore, $$\begin{equation} \boxed{ I = \int_{0}^\infty e^{-(x-\mu)^2 / (2\sigma^2)} \, dx = \sigma \sqrt{2\pi} \, e^{-\mu^2 / (4\sigma^2)} } \end{equation}$$

I know how the error function is defined as an integral of an exponential, and the $$\mu/(\sigma\sqrt{2})$$ seen in the Mathematica solution seems to almost match the term in the exponential of my solution, but I'm still very confused on how to get the error function in the solution. Any help is appreciated, thank you.

You wrote that you need to change the limits of integration when you change the variables, but you didn't do it.

....
Now, perform a change of variables such that $$\beta = x - \mu$$, $$\gamma = y - \mu$$, $$dx = d\beta$$, $$dy = d\gamma$$. Note that with this substitution, our limits of integration change. When $$x=0$$, $$\beta = -\mu$$ (similarly for $$y$$). So, \begin{align} I^2 &= \int_{0}^\infty \int_{0}^\infty e^{-a(x-\mu)^2} e^{-a(y-\mu)^2 } \, dx dy \nonumber \\[.5em] &= \int_{-\mu}^\infty \int_{-\mu}^\infty e^{-a(\beta^2 + \gamma^2)} \, d\beta d\gamma \nonumber \end{align} ...

I don't think polar coordinates are going to help you with this one.

• I'm confused, I did change the limits of integration and used polar coordinates in my work.
– NoVa
Jan 16, 2021 at 23:27
• you wrote the lower limits of integration are 0 after changing variables. The lower limits should both be $-\mu$. But, you are not going on the right path by trying to square the integral and switch to polar coordinates. Instead, try to find a transformation in the original integral to make the integrand look like the integrand in the definition of Erf. Jan 16, 2021 at 23:32
• Oh, that was a typo. I just fixed it. if you look at the conversion to polar coordinate line a little farther down, you can see that I actually did that. My confusion is with the error function, I'm not sure how to manipulate the expression to work with it.
– NoVa
Jan 16, 2021 at 23:48