Example 1 A quadratic function $y=f(x)$, when $x=0, \frac{\pi}{2}, \pi$, its values are the same as those of $\sin x$, find this quadratic function.
(1979 Liaoning Province Competition Question)
Given $f(0)=0, f\left(\frac{\pi}{2}\right)=1, f(\pi)=0$ and using the Lagrange formula, we have
$$
\begin{array}{l}
f(x)=\frac{\left(x-\frac{\pi}{2}\right)(x-\pi)}{\left(0-\frac{\pi}{2}\right)(0-\pi)} f(0)+\frac{(x-0)(x-\pi)}{\left(\frac{\pi}{2}-0\right)\left(\frac{\pi}{2}-\pi\right)} f\left(\frac{\pi}{2}\right)+\frac{(x-0)\left(x-\frac{\pi}{2}\right)}{(\pi-0)\left(x-\frac{\pi}{2}\right)} f(\pi) \\
=-\frac{4}{\pi^{2}} x^{2}+\frac{4}{\pi} x, \text { which is the desired result. }
\end{array}
$$