Evaluating the integral $\int_{-\infty}^\infty x^2\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2} \ dx$

How does one evaluate $$\int_{-\infty}^\infty x^2\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2} \ dx ?$$

The result is $1$ and it corresponds to $E[X^2]$, where $X$ is a random variable with $X\sim\mathcal{N}(0,1)$. I have tried to do some substituions and I've tried integration by parts but didn't succeed to integrate it. With the integration by parts I ended up with a harder integral in both cases and I couldn't find a good substitution.

• Do you have available the special value $\int_{-\infty}^{\infty} e^{-t^2} dt = \sqrt{\pi}$? Commented Jan 4, 2016 at 16:11
• No. But if it shouldn't work otherwise you may use it. It would be nice to know how it works that way anyways. Commented Jan 4, 2016 at 16:13
• What about $Var(X)=E(X^2)-\left( E(X) \right) ^2$ ? Commented Jan 4, 2016 at 16:14
• @callculus yes you may use that fact. I see, that would make things very simple: $1=E(X^2)-0^2 \ \Longrightarrow E(X^2) = 1$. Thanks for that one! Commented Jan 4, 2016 at 16:20
• That was my intention. Commented Jan 4, 2016 at 16:21

Notice, integral can be usually computed using Laplace transform as follows, $$\int_{-\infty}^{\infty}x^2\frac{1}{\sqrt{2\pi }}e^{-\frac{x^2}{2}}\ dx$$ By symmetry of even function: $f(-x)=f(x)$, $$=2\frac{1}{\sqrt{2\pi }}\int_{0}^{\infty}x^2e^{-\frac{x^2}{2}}\ dx$$$$=\sqrt{\frac{2}{\pi }}\int_{0}^{\infty}x^2e^{-\frac{x^2}{2}}\ dx$$ let $\frac{x^2}{2}=u\implies x\ dx=du$ or $dx=\frac{1}{\sqrt{2u}}\ du=\frac{1}{\sqrt2}\frac{ du}{\sqrt u}$, $$=\sqrt{\frac{2}{\pi }}\int_{0}^{\infty}(2u)e^{-u} \frac{1}{\sqrt2}\frac{ du}{\sqrt u}$$ $$=\frac{2}{\sqrt {\pi}}\int_{0}^{\infty}u^{1/2}e^{-u}\ du$$ using Laplace transform: $\color{blue}{\int_0^{\infty}t^ne^{-st}\ dt=\frac{\Gamma(n+1)}{s^{n+1}}}$, $$=\frac{2}{\sqrt {\pi}}\left[\frac{\Gamma\left(1+\frac{1}{2}\right)}{s^{1+\frac{1}{2}}}\right]_{s=1}$$ $$=\frac{2}{\sqrt {\pi}}\left[\frac{\frac{1}{2}\Gamma\left(\frac{1}{2}\right)}{(1)^{3/2}}\right]$$ $$=\frac{2}{\sqrt {\pi}}\left[\frac{1}{2}\sqrt \pi\right]=\color{red}{1}$$

• Thanks. But I don't know how to do a Laplace transform. Maybe there is not even a way to do it without it. Commented Jan 4, 2016 at 16:19
• There may be other methods of doing this but it is one of the easiest & simpliest methods Commented Jan 4, 2016 at 16:20
• @ndrizza Laplace Transforms typically are covered in a differential equations course, you could take a look at that or simplicity, you can google "Laplace Transform Table"
Commented Jan 4, 2016 at 16:22
• Alright. I'll have a look at it. Thank you! Commented Jan 4, 2016 at 16:22

Here is another solution

starting with $$\int_{-\infty}^{\infty} e^{-t^2} dt = \sqrt{\pi}$$

and with simple substitution generalizing to (for $$u>0$$)

$$f(u) = \int_{-\infty}^{\infty} e^{-ut^2} dt = \sqrt{\frac{\pi}u}$$

Now, take the derivative w.r.t. u and evaluate at $$u=1.$$

$$\frac{d f(u)}{du} \biggr\rvert_{u=1} = \int_{-\infty}^{\infty} t^2e^{-t^2} dt = \frac12 \sqrt{\frac{\pi}{u^3}} = \frac{\sqrt{\pi}}2$$

Or, evaluating at $$u=\frac12$$ will give

$$\int_{-\infty}^{\infty} t^2e^{-\frac12 t^2} dt = \sqrt{2\pi}$$

We know that, if $F'=f$, then $$\int_a^bxf(x)dx=bF(b)-aF(a)-\int_a^b F(x)dx$$

Now, note that if $F(x)=e^{-x^2/2}$ then $F'(x)=f(x)=-xe^{-x^2/2}$.

So, $$\int_{-\infty}^\infty x^2e^{-\frac{x^2}2}dx=-\lim_{x\to\infty}\left(2xe^{-\frac{x^2}2}-\int_{-x}^xF(t)dt\right)=\sqrt{2\pi}$$

Here are two solutions that exploit the same two tools in different orders:

1. It's a standard trick using elementary multivariable calculus and converting to polar coordinates (see, e.g., this answer) to show that the Gaussian integral has value $$\require{cancel}\int_{-\infty}^{\infty} e^{-t^2} dt = \sqrt{\pi} .$$ Now, applying integration by parts with $u = e^{-t^2}, dv = dt$ to the above integral gives $du = -2 t e^{-t^2} dt, v = t$ and hence $$\sqrt{\pi} = \cancelto{0}{\left.\left(e^{-t^2}\right)(t)\right\vert_{-\infty}^{\infty}} - \int_{-\infty}^{\infty} (t)(-2t e^{-t^2}) dt = 2 \int_{-\infty}^{\infty} t^2 e^{-t^2} dt,$$ and so $$\int_{-\infty}^{\infty} t^2 e^{-t^2} dt = \frac{\sqrt{\pi}}{2} .$$ Now, substituting $t = \frac{x}{\sqrt{2}}, dt = \frac{dx}{\sqrt{2}}$ in the integral gives $$\frac{1}{2 \sqrt{2}} \int_{-\infty}^{\infty} x^2 e^{-\frac{x^2}{2}} dx = \frac{\sqrt{\pi}}{2},$$ and multiplying by $\frac{2}{\sqrt{\pi}}$ gives the desired result: $$\color{#bf0000}{\boxed{\int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} x^2 e^{-\frac{x^2}{2}} dx = 1}} .$$
2. We can apply the "multivariable polar" trick directly to the integral at hand rather than to the Gaussian integral: If one denotes $$I := \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} x^2 e^{-\frac{x^2}{2}} dx ,$$ we have $$I^2 = \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} x^2 e^{-\frac{x^2}{2}} dx \cdot \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} y^2 e^{-\frac{y^2}{2}} dy = \frac{1}{2 \pi} \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} x^2 y^2 e^{-\frac{x^2 + y^2}{2}} dx \, dy .$$ Now, converting to polar coordinates gives \begin{align} I^2 &= \frac{1}{2 \pi} \int_0^{2 \pi} \int_0^{\infty} (r \cos \theta)^2 (r \sin \theta)^2 e^{-\frac{r^2}{2}} \cdot r \,dr \,d\theta \\ &= \frac{1}{2 \pi} \int_0^{2 \pi} \int_0^{\infty} r^5 e^{-\frac{r^2}{2}} \sin^2 \theta \cos^2 \theta \,dr \,d\theta \\ &= \frac{1}{2 \pi} \int_0^{2 \pi} \sin^2 \theta \cos^2 \theta \,d\theta \int_0^{\infty} r^5 e^{-\frac{r^2}{2}} dr . \end{align} Now, the first integral is a standard exercise that can be handled with double-angle identities and has value $\frac{\pi}{4}$. The second integral can be evaluated readily with the substitution $u = -\frac{r^2}{2}, du = -r \,dr$ and has value $8$, so $$I^2 = \frac{1}{2 \pi} \left(\frac{\pi}{4}\right) (8) = 1 .$$ On the other hand, the integrand in $I$ is everywhere nonnegative, and so again $I$ has value $$\color{#bf0000}{\boxed{\int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} x^2 e^{-\frac{x^2}{2}} dx = 1}}$$ as claimed.

Let's assume an integral $\int_{-\infty}^{\infty}x^2\frac{1}{\sqrt{2\pi }}e^{-{\alpha x^2}}\ dx$ you have $\alpha=1/2$, then $$\int_{-\infty}^{\infty}x^2\frac{1}{\sqrt{2\pi }}e^{-{\alpha x^2}}\ dx=-\int_{-\infty}^{\infty}\frac{1}{\sqrt{2\pi }}\frac{ \partial }{ \partial \alpha}e^{-\alpha x^2}\ dx=-\frac{1}{\sqrt{2\pi }}\frac{ \partial }{ \partial \alpha}\int_{-\infty}^{\infty}e^{-\alpha x^2}\ dx.$$ The letter is the well known Euler–Poisson integral, which is equal to $\sqrt{\frac{\pi}{\alpha}}$, so: $$-\frac{1}{\sqrt{2\pi }}\frac{ \partial }{ \partial \alpha}\int_{-\infty}^{\infty}e^{-\alpha x^2}\ dx=-\frac{1}{\sqrt{2\pi }}\frac{ \partial }{ \partial \alpha}\sqrt{\frac{\pi}{\alpha}}=\frac{1}{2\sqrt{2}}\alpha^{-3/2}.$$ After setting $\alpha=1/2$ you'll get the correct answer $\int_{-\infty}^{\infty}x^2\frac{1}{\sqrt{2\pi }}e^{-\frac{x^2}{2}}\ dx=1$.

\begin{align*} \int_{-\infty}^\infty x^2\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2} \; \mathrm{d}x&\overset{IBP}=\frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{\infty} e^{-\frac{1}{2}x^2} \; \mathrm{d}x\\ &=\frac{1}{\sqrt{\pi}}\int_{-\infty}^{\infty} e^{-x^2} \; \mathrm{d}x\\ &= \frac{\sqrt{\pi}}{\sqrt{\pi}}\\ &=\boxed{1} \end{align*} Where $$u=\frac{x}{\sqrt{2 \pi}}$$ and $$dv=xe^{-\frac{1}{2}x^2} \implies v=-e^{-\frac{1}{2}x^2}$$