Example 4. The distribution law of a discrete random variable $X$ is given by the table

| $X$ | -2 | -1 | 0 | 1 | 2 |
| :---: | :---: | :---: | :---: | :---: | :---: |
| $P$ | 0.1 | 0.2 | 0.4 | 0.2 | 0.1 |

Calculate the variance of the random variable $X$ using formula (2.5.4) and formula (2.5.10).
Solution. First, we find the mathematical expectation of the random variable $X$:

$$
M(X)=-2 \cdot 0.1-1 \cdot 0.2+0 \cdot 0.4+1 \cdot 0.2+2 \cdot 0.1=0
$$

Next, we determine the distribution law of the random variable $(X-M(X))^{2}$:

| $(X-M(X))^{2}$ | $(-2-0)^{2}$ | $(-1-0)^{2}$ | $(0-0)^{2}$ | $(1-0)^{2}$ | $(2-0)^{2}$ |
| :---: | :---: | :---: | :---: | :---: | :---: |
| $P$ | 0.1 | 0.2 | 0.4 | 0.2 | 0.1 |

and find the variance of the random variable $X$ using formula (2.5.10):

$$
D(X)=4 \cdot 0.1+1 \cdot 0.2+0 \cdot 0.4+1 \cdot 0.2+4 \cdot 0.1=1.2.
$$

The square of the random variable $X$, i.e., $X^{2}$, is a new random variable that takes values equal to the squares of its values with the same probabilities as the random variable $X$.

The squares of the values of the random variable $X$ are: $(-2)^{2}=4$, $(-1)^{2}=1$, $0^{2}=0$, $1^{2}=1$, $2^{2}=4$, i.e., the variable $X^{2}$ takes the values $x_{1}=0$, $x_{2}=1$, $x_{3}=4$. The distribution law of the random variable $X^{2}$ can be written as:

| $X^{2}$ | 0 | 1 | 4 |
| :---: | :---: | :---: | :---: |
| $P$ | 0.4 | 0.4 | 0.2 |

The probability 0.4 for the value $x_{2}=1$ is obtained by the theorem of addition of probabilities with which the random variable $X$ takes the values -1 and 1. Similarly, the probability 0.2 for the value $x_{3}=4$ is obtained.

Using formula (2.4.3), we find

$$
M\left(X^{2}\right)=0 \cdot 0.4+1 \cdot 0.4+4 \cdot 0.2=1.2
$$

Therefore, by formula (2.5.4), we have

$$
D(X)=M\left(X^{2}\right)-(M(X))^{2}=1.2-0=1.2.
$$