expectation of $ \left(\sum_{i=1}^n {x_i} \right)^2 $ If $x_i$ is exponentially distributed $(i=1,...,n)$ with parameter $\lambda$ and $x_i$'s are mutually independent, what is the expectation of
$\left(\sum_{i=1}^n {x_i} \right)^2$
in terms of $n$ and $\lambda$ and possibly other constants?
Note: This question has gotten a statistical answer on https://stats.stackexchange.com/q/4959/2148. The readers would take a look at it too.
 A: In what follows, $x_j$ are assumed to be independent.
$$ E[x_0^2] = \int_0^{\infty} \lambda t^2 e^{-\lambda t}  dt = \frac{2}{\lambda^2} $$
$$ E[x_0 x_1] = \int_0^{\infty} \int_0^{\infty} \lambda^2 t_0 t_1 e^{-\lambda t_0} e^{-\lambda t_1 } dt_0 dt_1 = \frac{1}{\lambda^2} $$
$$ E[ (\sum_{j=0}^{n-1} x_j)^2 ] = n E[ x_0^2] + n(n-1) E[x_0 x_1] = \frac{ n^2 + n }{ \lambda^2 } $$
A: This problem is just a special case of the much more general problem of 'moments of moments' which are usually defined in terms of power sum notation. In particular, in power sum notation:  
$$s_1 = \sum_{i=1}^{n} X_i$$ 
Then, irrespective of the distribution, the original poster seeks $E[s_1^2]$ (provided the moments exist). Since the expectations operator is just the 1st Raw Moment, the solution is given in the mathStatica software by:

[ The '___ToRaw' means that we want the solution presented in terms of raw moments of the population (rather than say central moments or cumulants). ]
Finally, if $X$ ~ Exponential($\lambda$) with pdf $f(x)$:
f = Exp[-x/λ]/λ;      domain[f] = {x, 0, ∞} && {λ > 0};

then we can replace the moments $\mu_i$ in the general solution sol with the actual values for an Exponential random variable, like so:

All done.

P.S. The reason the other solution posted here yields an answer with $\lambda^2$  in the denominator rather than the numerator is, of course, because it is using a different parameterisation of the Exponential distribution. Since the OP didn't state which version he was using, I decided to use the standard distribution theory textbook definition Johnson Kotz et al … just to balance things out :) 
