# An elegant trick to compute moments of Gaussian RV

Assume we have a zero-mean Gaussian RV $\mathbf x$ with variance $\sigma^2$, and we want to compute its moments, i.e., $E\{\mathbf x^n\}$. The moments for odd $n$ are zero because the density function of our RV $f(x)$ is an even function. But how to compute the moments. i.e.,

$$E\{\mathbf x^n\} =\int\limits_{-\infty}^{\infty} x^n f(x) dx =\frac{1}{\sigma \sqrt{2\pi}}\int\limits_{-\infty}^{\infty} x^n e^{-x^2/2\sigma^2} dx $$

for even $n$? Of course this is not a very difficult integral (can be computed through integration by parts etc.), but there is a very elegant way of computing it and I thought it’s worth making a post about, because it may prove handy in other circumstances too.

Consider the following definite integral that we know how to compute:

$$\int\limits_{-\infty}^{\infty} e^{-\alpha x^2} dx = \sqrt{\frac{\pi}{\alpha}}. $$

Now differentiate this integral w.r.t. $\alpha$ $k$ times. It’s easy to see that differentiating both sides yields:

$$\int\limits_{-\infty}^{\infty} x^{2k} e^{-\alpha x^2} dx = \frac{1 \cdot 3 \cdots (2k-1) }{}\sqrt{\frac{\pi}{\alpha^{2k+1}}}. $$

Now just replace $\alpha$ with $\sigma$ and we have all we need to compute the moments.

#### What was the point of this post?

Of course the point wasn’t to compute moments for a Gaussian RV. The point is to show this trick that was used to compute the moments, which is not just aesthetically pleasing but can also be pretty useful in other contexts for two reasons. Firstly, note that this trick computes the derivative of a density $f(x)$ w.r.t. a parameter other than $x$. This is a pretty useful trick to have in your mental toolbox, because it can greatly simplify proofs (as in here) or even make them possible. For example, this trick is used in Price’s theorem — a very important theorem. Secondly, the idea of computing the derivative of both sides of an expression is also a useful trick worth keeping in the top shelf of the mind, as it is also used for various proofs.