TITLE: Why is the expected value $E(X^2) \neq E(X)^2$?
QUESTION [28 upvotes]: I wish to use the Computational formula of the variance to calculate the variance of a normal-distributed function. For this, I need the expected value of $X$ as well as the one of $X^2$. Intuitively, I would have assumed that $E(X^2)$ is always equal to $E(X)^2$. In fact, I cannot imagine how they could be different.
Could you explain how this is possible, e.g. with an example?

REPLY [22 votes]: Let $EX=\mu$ and $E(X-\mu)^2=\sigma^2$, then
$$
EX^2 = E[X-\mu+\mu]^2=\\
=E(X-\mu)^2+2E[(X-\mu)\mu]+E(\mu^2)=\\=\sigma^2+2\mu E(X-\mu)+\mu^2=\\
=\sigma^2+\mu^2
$$
So $EX^2 =\sigma^2+\mu^2$, no matter the distribution, and $EX^2\ne(EX)^2$ unless the variance equals zero.