Solution (source code)

= Solution

Using the <probability density function> of the <Erlang distribution>, the <expected value> is
$$
\mathbb E X=\theta^2\int_0^\infty x^2e^{-\theta x}\,dx
=\frac1\theta\int_0^\infty u^2e^{-u}\,du
=\boxed{\frac2\theta}.
$$
Here $u=\theta x$, and two applications of <integration by parts> give $\int_0^\infty u^2e^{-u}\,du=2\int_0^\infty ue^{-u}\,du=2$. The boundary terms vanish because <exponential decay> dominates these powers.