Example 3 Solve the functional equation
$$
f(x+y)+f(x-y)=2 f(x) \cos y
$$
Given that the function equation involves two independent variables $x$ and $y$, let's assume one of the variables is a constant.
Let $x=0, y=t$, then (3) becomes
$$
f(t)+f(-t)=2 f(0) \cos t
$$

Let $x=\frac{\pi}{2}+t, y=\frac{\pi}{2}$, substituting into (3) we get
$$
f(\pi+t)+f(t)=0
$$

Let $x=\frac{\pi}{2}, y=\frac{\pi}{2}+t$, substituting into (3) we get
$$
f(\pi+t)+f(-t)=-2 f\left(\frac{\pi}{2}\right) \sin t,
$$

From (4), (5), and (6) we have
$$
f(t)=f(0) \cos t+f\left(\frac{\pi}{2}\right) \sin t \text {. }
$$

Let $a=f(0), b=f\left(\frac{\pi}{2}\right), t=x$, then $f(x)=a \cos x+b \sin x(a, b$ are constants).
Verification: $f(x+y)+f(x-y)$
$$
\begin{array}{l}
=a \cos (x+y)+b \sin (x+y)+a \cos (x-y)+b \sin (x-y) \\
=2 a \cos x \cos y+2 b \cos y \sin x \\
=2 f(x) \cos y .
\end{array}
$$