# Integrate $x^2 e^{-x^2/2}$

Is it possible to integrate $$\int_0^{\infty} x^2 e^{-x^2/2}\, \mathrm dx$$ by hand?

The answer is $$\frac{1}{2\sqrt{2}}$$ My apologies if this does not meet the standards of this blog. I will delete it if requested.

• Try to do it by parts twice...or even once. – DonAntonio Sep 30 '16 at 18:46
• I think you might be able to compare it to the gamma function? – Jam Sep 30 '16 at 18:47
• ok, I am little rusty with calculus what do we set our u and dv at? – Wolfy Sep 30 '16 at 18:47
• It seems that your answer is wrong: see wolframalpha.com/input/?i=integrate+x^2+e^%28-x^2%2F2%29+from+x%3D0+to+infty – Emilio Novati Sep 30 '16 at 19:19

By the Feynman trick we have:

$$I = \lim_{a\to 1}\int_0^{+\infty} -2\left(\frac{\text{d}}{\text{d}a} e^{-(a x^2)/2}\right)\ \text{d}x = \lim_{a\to 1}-2\frac{\text{d}}{\text{d}a}\int_0^{+\infty} e^{-(ax^2)/2}\ \text{d}x = \lim_{a\to 1} -2 \frac{\text{d}}{\text{d}a}\sqrt{\frac{\pi}{2a}}$$

Hence

$$I = \lim_{a\to 1}-2\left(-\frac{1}{2} \sqrt{\frac{\pi }{2}} \left(\frac{1}{a}\right)^{3/2}\right)$$

And our integral is simply

$$I = \sqrt{\frac{\pi }{2}}$$

Which is the result of your integral.

• Very nice trick! – Babak Sep 30 '16 at 19:06
• @Babak Thank you! I really love that trick too, and finally I could use it :D – Von Neumann Sep 30 '16 at 19:16
• Nitpick: the LHS should not be $I(a)$ but $I$: it does not depend on $a$. Or you want to drop the $\lim_{a\to 1}$ there? – Clement C. Sep 30 '16 at 19:31
• @FourierTransform +1 Feynman's Trick comes to the rescue for all of the even powered moments. – Mark Viola Sep 30 '16 at 20:00
• @Lovsovs I forgot it, thanks! Going to edit – Von Neumann Sep 30 '16 at 20:26

Hint: $u = x$, $dv = xe^{-x^2/2}dx$

No tricks, just the Gamma integral: Substituting $x = \sqrt{2t}$ gives $$\int_0^\infty x^2 e^{-x^2/2} \,dx = \sqrt{2\vphantom{X}} \int_0^\infty t^{1/2} e^{-t} \,dt = \sqrt{2\vphantom{X}}\,\Gamma\Bigl(\frac32\Bigr) = \sqrt{\frac\pi2}.$$

• Actually the Gamma function is a trick too :) But I give +1 because I love the Gamma function! – Von Neumann Sep 30 '16 at 19:17
• And how does one evaluate the Gamma function at half integers? Using the functional relationship $\Gamma(x+1)=x\Gamma(x)$ boils it down to evaluating $\Gamma(1/2)$. And would you do that? – Mark Viola Sep 30 '16 at 19:55
• @Dr.MV For this we can evaluate the Gaussian integral $\int_0^\infty e^{-x^2}\,dx = \sqrt\pi/2$ with another method, and then substituting $x = \sqrt{t}$ gives $\int_0^\infty e^{-x^2}\,dx = \Gamma(1/2)/2$. – arkeet Sep 30 '16 at 20:00
• @arkeet Yes, I know that. I just want others to be aware that the evaluation of the integral of interest using the Gamma function requires that one evaluate the Gamma function. – Mark Viola Sep 30 '16 at 20:02
• Yes, that is the point. But if you want to avoid the function, the integral can be reduced to the Gaussian integral more directly by grixor's answer. – arkeet Sep 30 '16 at 20:04

Using a standard probability distribution:

If you know the Gaussian distribution $\mathcal{G}(\mu,\sigma)$: its pdf is $f_{\mu,\sigma}\colon\mathbb{R}\to\mathbb{R}$ defined by $$f_{\mu,\sigma}(x) = \frac{1}{\sqrt{2\pi}\sigma} e^{-\frac{(x-\mu)^2}{2\sigma^2}}$$ and you want to compute, for $X\sim\mathcal{G}(0,1)$, \begin{align*} \int_{0}^\infty x^2e^{-\frac{x^2}{2}}dx &= \frac{1}{2}\cdot\sqrt{2\pi}\int_{-\infty}^\infty x^2f_{0,1}(x)dx = \frac{\sqrt{2\pi}}{2} \mathbb{E}[X^2] = \frac{\sqrt{2\pi}}{2}\left( \mathbb{E}[X^2]-\mathbb{E}[X]^2\right) \\&= \frac{\sqrt{2\pi}}{2}\operatorname{Var}X = \frac{\sqrt{2\pi}}{2}\cdot 1 \\&= \sqrt{\frac{\pi}{2}} \end{align*} where for the first step we used the fact that $x\mapsto x^2e^{-\frac{x^2}{2}}$ is an even function (hence the factor $\frac{1}{2}$ and the change of bounds in the integral).

• Clement, how are you my friend. This is a fine approach. But it might prompt, of course, one to ask, "how does one calculate the variance (or any moment) of the normal (Gaussian) distribution in terms of the parameters $\mu$ and $\sigma$ of the corresponding density function?" – Mark Viola Sep 30 '16 at 19:59
• Indeed, it is circular (and I fully admit it). But assuming the variance and expectation of a Gaussian are known (which only requires to compute the integral once in a lifetime), this allows one to (re)derive such results very cheaply. – Clement C. Sep 30 '16 at 20:03
• And that is the rationale for my giving a +1, well deservedly! – Mark Viola Sep 30 '16 at 20:04

\begin{align} u&=x^2/2 \\ \mathrm{d}u&=x\mathrm{d}x \\ \int x^2e^{-x^2/2}\,\mathrm{d}x &=\int \frac{x^2e^{-u}}{x}\,\mathrm{d}u \\&=\int \sqrt{2u}e^{-u}\,\mathrm{d}u \\&=\sqrt{2}\int u^{1/2}e^{-u}\,\mathrm{d}u \\\int_0^\infty x^2e^{-x^2/2}\,\mathrm{d}x&=\sqrt{2}\:\Gamma\left(\frac{1}{2}+1 \right)* \\&=\sqrt{2}\frac{\sqrt{\pi}}{2} \\&\quad \text{* where \Gamma(z) is the gamma function \int_0^\infty u^{z-1}e^u\mathrm{d}u} \end{align}

• And how does one evaluate the Gamma function at half integers? Using the functional relationship $\Gamma(x+1)=x\Gamma(x)$ boils it down to evaluating $\Gamma(1/2)$. And would you do that? – Mark Viola Sep 30 '16 at 19:55

As a first step note that $$I=\int x e^{-\frac{x^2}{2}}dx$$ can be integrated with the substitution $$-\frac{x^2}{2}=t \quad \rightarrow \quad xdx=-dt$$ and we have: $$I=-\int e^t dt = -e^t+C=-e^{-\frac{x^2}{2}}+C$$

now you can write your integral as: $$J=\int_0^{\infty} x^2 e^{-x^2/2}dx=\int_0^{\infty} x d\left(-e^{-\frac{x^2}{2}} \right)$$

and, integrating by part: $$J=\left[-xe^{-x^2/2}\right]_0^{\infty}+\int_0^{\infty}e^{-x^2/2}dx$$

The first part is obviously $=0$. For the second, using the definition of the Error function, we have: $$\int_0^{\infty}e^{-x^2/2}dx=\left[\sqrt{\frac{\pi}{2}}\mbox{erf}(x/\sqrt{2})\right] _0^{\infty}$$

and, since $\mbox{erf}(0)=0$ and $\lim _{x\to \infty}\mbox{erf}(x)=1$ we have $J=\sqrt{\frac{\pi}{2}}$.