What is the moment generating function from a density of a continuous random variable? Let X be a random variable with probability density function $$f(x)=\begin{cases}xe^{-x} \quad \text{if } x>0\\0 \quad \text{ } Otherwise.\end{cases} $$
  Determine the mgf of X whenever it exists.
I know that $M(t) = E(e^{tx}) =\int e^{tx}f(x)~dx$ but not sure what to do from there.
Thanks for the help.
 A: We begin, as you indicated, with the integral 
$\int_{-\infty}^\infty e^{tx}f(x)dx$  In order to find this integral, we may proceed as follows:
$$
\int_{-\infty}^\infty e^{tx}f(x)dx 
= \int_0^\infty x e^{tx} e^{-x}dx  
=\int_0^\infty x e^{(t-1)x}dx
$$
From there, use integration by parts. That is, we have $\int u\,dv = uv - \int v\, du$. For this problem, we choose $u = x$ and $dv = e^{(t-1)x}dx$.  Applying the rule gives us
$$
\begin{align}
\int_0^\infty xe^{(t-1)x}dx &=
\left[\frac{1}{t-1}x e^{(t-1)x}\right]_0^\infty 
- \int_0^\infty \frac{1}{t-1} e^{(t-1)x}dx\\
&= \frac{1}{t-1} \left[x e^{(t-1)x}\right]_0^\infty - 
\frac{1}{(t-1)^2}\left[e^{(t-1)x}\right]_0^\infty\\
&= \frac{1}{t-1} \cdot 0 - \frac{1}{(t-1)^2}\cdot (-1)\\
&= \frac{1}{(t-1)^2}
\end{align}
$$
A: Hint: $M(t)=\int\limits_{-\infty}^{+\infty}e^{tx}f(x)\,dx=\int\limits_0^{+\infty} xe^{tx}e^{-x}\,dx=\int\limits_0^{+\infty}xe^{(t-1)x}\,dx$
A: Hint: You can use Leibniz integral rule:
$$
M(t)=\int_0^\infty e^{(t-1)x}dx\implies \frac{d}{dt}M(t)=\int_0^\infty xe^{(t-1)x}dx
$$
A: If I might add that this is a special case of the Gamma Distribution that takes the the general form $$ f(x) =\begin{cases}\begin{align} \frac{1}{\Gamma(a) \beta^a} x^{a-1} e^{-x/{\beta}}\quad \text{if}\quad  0<x<\infty \\ 0\quad \text{otherwise}\ \end{align} \end{cases}   $$ 
The MGF for this distribution is $$\frac{1}{\left( 1-\beta t \right)^a} $$
For your case $a=2\ \text{and}\ b=1 $ and there you go.
I fear that Omnomnomnom has made a mistake in his integral above. In his second line of the derivation of the MGF after integrating by parts, he made a mistake in the minus sign in the second integral. The minus sign in the end shouldn't be there.
