For a continuous random variable X with density f, the mean is the probability-weighted average of its possible values. mu=E(X)= _all xxf(x),dx, provided the expectation is finite. For a function g, apply the function to each value before weighting by the density: E[g(X)]= _all xg(x)f(x),dx, provided this expectation is finite. In particular, E(X2)= _all xx2f(x),dx. This is generally different from [E(X)]2. Integrate over the support of the density. For a piecewise density, add the integrals over its separate intervals.