Integral of exponential using error function

I’m trying to solve some integrals below

$$\int_{-\infty}^{\infty} {x^n e^\frac{-(x – \mu)^2}{\sigma^2}}dx$$

I am interested in the solutions where n = 0, 1, 2, 3, 4.

I have learned that integrals of this form can’t be solved the usual way, but can be evaluated in terms of the error function.

I’ve checked using wolfram alpha and it seems that the solutions are indeed expressable using the error function, however I’ve no idea how the solution was reached.

Solutions Collecting From Web of "Integral of exponential using error function"

A related technique. Here is a nice formula in terms of a friendly function, the gamma function

$$ I = \frac{\mu^n\sigma}{2}\sum_{k=0}^{n}((-1)^k+1){n\choose k}\left(\frac{\sigma}{\mu}\right)^k \Gamma\left(\frac{k}{2}+\frac{1}{2} \right),$$

where ${n\choose k}=\frac{n!}{k!(n-k)!}$ and $\Gamma(x)$ is the gamma function. I’ll provide a proof when the time allows.

Note: I’ll appreciate it if someone double check the formula.

Added: If you are interested in the proof you can follow the steps:

1) make the change of variables $t=x-\mu$

2) use the binomial theorem

3) split the range of integration on the intervals $(-\infty,0)$ and $(0,\infty)$

4) for the integral on the interval $(-\infty,0)$ make the change of variables $u=-t$,

5) use the change of variables $y=t^2/\sigma^2$ and the Gamma function.

then you are done.

This integral is $I=\sqrt{\pi\sigma^2}\cdot E(X^n)$ where the random variable $X$ is normal $(\mu,\sigma^2/2)$ hence $X=\mu+(\sigma/\sqrt2) Z$ where the random variable $Z$ is standard normal, and
$$
I=\sqrt{\pi\sigma^2}\cdot\sum_{k=0}^n{n\choose k}\mu^{n-k}(\sigma/\sqrt2)^kE(Z^k).
$$
One knows that, for every nonnegative integer $k$, $E(Z^{2k+1})=0$ and
$$
E(Z^{2k})=(2k-1)(2k-3)\cdots1=(2k-1)!!=\frac{\Gamma(2k)}{2^{k-1}\Gamma(k)},
$$
hence
$$
I=\sqrt{\pi}\cdot\sum_{0\leqslant2k\leqslant n}{n\choose 2k}\mu^{n-2k}\sigma^{k+1}\frac{\Gamma(2k)}{2^{2k-1}\Gamma(k)}.
$$