301. A random variable $X$ is given by the probability density function $f(x)=x^{n} \mathrm{e}^{-x} / n!$ for $x \geqslant 0 ; f(x)=0$ for $x<0$. Find: a) the expected value; b) the variance of $X$.
Solution. a) Let's find the mathematical expectation:

$$
M(X)=\int_{0}^{\infty} x f(x) \mathrm{d} x=\frac{1}{n!} \int_{0}^{\infty} x \cdot x^{n} \mathrm{e}^{-x} \mathrm{~d} x=\frac{1}{n!} \int_{0}^{\infty} x^{n+1} \mathrm{e}^{-x} d x
$$

We will use the so-called gamma function, which is defined by the equation

$$
\Gamma(n)=\int_{0}^{\infty} x^{n-1} \mathrm{e}^{-x} \mathrm{~d} x
$$

As we see, the argument (an integer \( n \)), standing under the gamma function, is one more than the exponent of \( x \) under the integral sign. Therefore,

$$
\int_{0}^{\infty} x^{n+1} e^{-x} d x=\Gamma(n+2)
$$

Substituting (**) into (*), we get

$$
M(X)=\frac{\Gamma(n+2)}{n!}
$$

We will use the following property of the gamma function:

$$
\Gamma(n)=(n-1)!
$$

As we see, the gamma function of an integer argument is equal to the factorial of the argument decreased by one. Therefore,

$$
\Gamma(n+2)=(n+1)!
$$

Substituting (****) into (***), we get

$$
M(X)=\frac{(n+1)!}{n!}=\frac{n!\cdot(n+1)}{n!}=n+1
$$

b) Let's find the variance. Considering that

$$
M(X)=n+1, \int_{0}^{\infty} x^{n+2} e^{-x} \mathrm{~d} x=\Gamma(n+3)
$$

we get

$$
\begin{gathered}
D(X)=\int_{0}^{\infty} x^{2} f(x) \mathrm{d} x-[M(X)]^{2}=\frac{1}{n!} \int_{0}^{\infty} x^{2} \cdot x^{n} \cdot e^{-x} \mathrm{~d} x- \\
-(n+1)^{2}=\frac{1}{n!} \int_{0}^{\infty} x^{n+2} e^{-x} \mathrm{~d} x-(n+1)^{2}=\frac{\Gamma(n+3)}{n!}-(n+1)^{2}= \\
=\frac{(n+2)!}{n!}-(n+1)^{2}=\frac{n!(n+1)(n+2)}{n!}-(n+1)^{2}=n+1
\end{gathered}
$$

Thus, \( D(X)=n+1 \).