# Why is my derivation of the variance of a normal distribution incorrect?

I have seen a proof of the variance of a standard normal distribution, but am getting an incorrect answer am and not sure why. Here is my reasoning.

$$\mathbb{V}[X] = \mathbb{E}[X^2] - \mathbb{E}[X]^2 = \mathbb{E}[X^2]$$

$$\mathbb{E}[X^2] = \frac{1}{\sqrt(2\pi)}\int_{-\inf}^{+inf} x^2 e^{-\frac{x^2}{2}} dx$$

Then do integration by parts and let $$u=x^2$$ and $$dv = e^{-\frac{x^2}{2}}$$ (In the proof I have seen, you choose $$u=x$$ and $$dv = x e^{-\frac{x}{2}}$$ and this makes sense to me and works out... )

Then

$$\frac{du}{dx} = 2x$$

and $$v = \sqrt(2 \pi)$$

as this is just the integral over the standard normal. Then the integral becomes

$$\mathbb{E}[X^2] =\frac{1}{\sqrt(2\pi)} \int_{-\inf}^{+inf} x^2 e^{-\frac{x^2}{2}} dx = \frac{1}{\sqrt(2\pi)} \left( x^2|_{-inf}^{inf} \sqrt(2 \pi) \ - \sqrt(2 \pi)\int_{-\inf}^{+inf} 2x dx\right ) = \left( x^2 - x^2\right)|_{-inf}^{inf} = 0$$

but this is oviously incorrect. Im sure I have just a stupid error but can't seem to find it.

• How do you get $v=\sqrt{2\pi}$? I think this is your mistake. The problem with choosing $dv=e^{-x^2/2}$ is that it doesn't have a primitive in terms of elementary functions. Aug 25, 2019 at 11:26
• I basically just did this: en.wikipedia.org/wiki/Gaussian_integral based on the notion that the definite integral can be evaluated... Sorry, your answer is partly out of my depth. Does this mean that when you can generally do integration by parts, you can only when the functions have elementary indefinite integrals? Aug 25, 2019 at 11:31
• It is still possible to do integration by parts with non-elementary functions. v needs to be a primitive of $dv$. One primitive is given by $v(x)=\int_0^x e^{-t^2/2}dt$. Aug 25, 2019 at 11:39
• The Gaussian integral you are refering to is a definite integral, but we need an indefinite integral. Aug 25, 2019 at 11:42
• Ok. That makes sense to me (sorry I was a bit lost about what a primitive was and was browsing wikipedia...). Thanks! :) Aug 25, 2019 at 11:43

Better way to solve that integral if you are familiar with gamma integrals. Are you? $$\dfrac{1}{\sqrt{2 \pi}}\int_{-\infty}^{\infty}x^2e^{\frac{-x^2}{2}}dx=\dfrac{2}{\sqrt{2 \pi}}\int_{0}^{\infty}x^2e^{\frac{-x^2}{2}}dx \because(\text{Even function})=\frac{2}{\sqrt{2 \pi}} \cdot \frac{\frac{\sqrt{\pi}}{2}}{\frac{1}{\sqrt{2}}}=1$$