Example 3 Let the domain of $f(x)$ be $R$, and for all $x, y \in R$ it satisfies $f(x+y)+f(x-y)=2 f(x) - \cos y, f(0)=A, f\left(\frac{\pi}{2}\right)=B$.


Let $x=0$, we get
$$
f(y)+f(-y)=2 f(0) \cos y,
$$

which means $f(x)+f(-x)=2 A \cos x$.
Let $x=\frac{\pi}{2}, y=\frac{\pi}{2}+u$, we get
$$
\begin{array}{l}
f(\pi+u)+f(-u) \\
=2 f\left(\frac{\pi}{2}\right) \cos \left(\frac{\pi}{2}+u\right),
\end{array}
$$

which means $f(\pi+x)+f(-x)=-2 B \sin x$.
Let $x=\frac{\pi}{2}+v, y=\frac{\pi}{2}$, we get
$$
f(\pi+v)+f(v)=2 f\left(\frac{\pi}{2}+v\right) \cos \left(\frac{\pi}{2}\right),
$$

which means $f(\pi+x)+f(x)=0$.
By (1)+(3)-(2), we get
$$
f(x)=B \sin x+A \cos x.
$$

Verification that $f(x)=B \sin x+A \cos x$ satisfies the equation is the solution.
(4) Verification Method
By observation, induction, conjecture the function's expression and verify that it satisfies the equation, then provide a proof.