295. A random variable $X$ in the interval $(0, \pi)$ is given by the probability density function $f(x)=(1 / 2) \sin x$; outside this interval, $f(x)=0$. Find the variance of $X$.
Solution. We will find the variance using the formula

$$
D(X)=\int_{a}^{b} x^{2} f(x) d x-[M(X)]^{2}
$$

Substituting here $M(X)=\pi / 2$ (the distribution curve is symmetric about the line $x=\pi / 2$), $a=0, b=x, f(x)=(1 / 2) \sin x$, we get

$$
D(X)=\frac{1}{2} \int_{0}^{\pi} x^{2} \sin x d x-\left[\frac{\pi}{2}\right]^{2}
$$

Integrating by parts twice, we find

$$
\int_{0}^{\pi} x^{2} \sin x \mathrm{~d} x=\pi^{2}-4
$$

Substituting (**) into (*), we finally get $D(X)=\left(\pi^{2}-8\right) / 4$.