# Variance of a continuous uniformly distributed random variable

I would like to calculate the variance of a uniformly distributed continuous random variable. The probability density function of a uniformly distributed continuous random variable is $$f_{X}(x) = \frac{1}{b-a}.$$

To obtain the variance, my book suggests to first calculate the second moment $$E[X^{2}]=\int_{-\infty}^{\infty}\frac{x^{2}}{b-a}dx.$$

However, I fail to see where the expression comes from. The expected value of a random variable is $$E[X] = \int_{-\infty}^{\infty} xf_{X}(x)dx.$$

So, when calculating $E[X^{2}]$ the density part remains the same and $X^{2}$ somehow translates to $x$ in the integral to be raised to the second power. Why does that happen?

• This question should be tagged as [self-study] please edit to add such tag.
– Tim
Oct 16, 2015 at 10:51

$$E[X^{2}]=\int_{-\infty}^{\infty}\frac{x^{2}}{b-a}dx.$$ is from law of unconscious statistician. You can search the proof of the theorem.
Simply say, suppose $Y=g(X)$
then $$E(Y)=\int_{-\infty}^{\infty} g(x)f(x)dx$$
Now $g(x)=x^2$
$$E(Y)=E[g(X)]=E(X^2)=\int_{-\infty}^{\infty}\frac{x^2}{b-a}dx$$