Example 6. A continuous random variable $X$ is given by the probability density function $p(x)=\cos x$ in the interval $(0 ; \pi / 2)$; outside this interval, $p(x)=0$. Find the expected value of the function $Y=X^{2}$.
Solution. We will use formula (2.7.7). In this case, $p(x)=\cos x, f(x)=x^{2}, a=0, b=\pi / 2$. Therefore,

$$
\begin{gathered}
M\left(X^{2}\right)=\int_{0}^{\pi / 2} x^{2} \cos x d x=\int_{0}^{\pi / 2} x^{2} d(\sin x)=\left.x^{2} \sin x\right|_{0} ^{\pi / 2}-2 \int_{0}^{\pi / 2} x \sin x d x=\frac{\pi^{2}}{4}+ \\
+2 \int_{0}^{\pi / 2} x d(\cos x)=\frac{\pi^{2}}{4}+\left.2 x \cos x\right|_{0} ^{\pi / 2}-2 \int_{0}^{\pi / 2} \cos x d x=\frac{\pi^{2}}{4}-\left.2 \sin x\right|_{0} ^{\pi / 2}=\frac{\pi^{2}}{4}-2 \\
M\left(X^{2}\right)=\frac{\pi^{2}}{4}-2 \approx 0.467
\end{gathered}
$$