Example 8. Independent trials are conducted, in each of which event $A$ occurs with probability $p$. The trials continue until the first occurrence of event $A$. The random variable $X$ is the number of trials conducted. Find the mathematical expectation of the random variable $X$.
Solution. Possible values of this random variable: $x_{n}=n, \quad n=1,2,3, \ldots$. The event $X=n$ means that the event $A$ does not occur in the first $n-1$ trials, but occurs in the $n-$th trial. The probability of such an outcome is

$$
P(X=n)=\underbrace{q q \ldots q}_{n-1 \text { times }} \cdot p=p q^{n-1}, \quad(q=1-p) .
$$

Therefore, the distribution law of the random variable $X$ can be represented by the table

| $X$ | 1 | 2 | 3 | $\ldots$ | $n$ | $\ldots$ |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| $P$ | $p$ | $p q$ | $p q^{2}$ | $\ldots$ | $p q^{n-1}$ | $\ldots$ |

We find the mathematical expectation of this variable:

$$
\begin{aligned}
& M(X)=1 \cdot p+2 \cdot p q^{2}+3 \cdot p q^{2}+\ldots+n p q^{n-1}+\ldots= \\
& =p\left(1+2 q+3 q^{2}+\ldots+n q^{n-1}+\ldots\right)
\end{aligned}
$$

The series written in parentheses is obtained by term-by-term differentiation of the geometric series

$$
q+q^{2}+q^{3}+\ldots+q^{\prime \prime}+\ldots=\frac{q}{1-q}=\frac{1}{1-q}-1
$$

Therefore,

$$
M(X)=p\left(\frac{1}{1-q}-1\right)^{\prime}=p \frac{1}{(1-q)^{2}}=\frac{p}{p^{2}}=\frac{1}{p}
$$