Originally Posted by

**Chris L T521** In general, to find the mgf of a pdf, you evaluate $\displaystyle \int_{-\infty}^{\infty}e^{tx}f\!\left(x\right)\,dx$.

Becaue your pdf is defined as a piecewise function, notice that when we integrate $\displaystyle \tfrac{1}{2}xe^{tx}$, the bounds become 0 to 2.

So, $\displaystyle \int_{-\infty}^{\infty} e^{tx}f\!\left(x\right)\,dx=\tfrac{1}{2}\int_0^2 xe^{tx}\,dx$.

Integration by parts yields $\displaystyle \tfrac{1}{2}\left.\left[\frac{xe^{tx}}{t}-\frac{e^{tx}}{t^2}\right]\right|_0^2=\frac{e^{2t}}{t}-\frac{e^{2t}}{2t^2}+\frac{1}{2t^2}$

Can you take it from here and find the second moment?