Example 1 Given real numbers $a, b, c, d$ satisfy: for any real number $x$,
$a \cos x + b \cos 2x + c \cos 3x + d \cos 4x \leqslant 1$.
Find the maximum value of $a + b - c + d$ and the values of the real numbers $a, b, c, d$ at this time.
(Ninth China Southeast Mathematical Olympiad)
Let
$$
\begin{array}{l}
f(x)=a \cos x+b \cos 2 x+c \cos 3 x+d \cos 4 x . \\
\text { By } f(0)=a+b+c+d, \\
f(\pi)=-a+b-c+d, \\
f\left(\frac{\pi}{3}\right)=\frac{a}{2}-\frac{b}{2}-c-\frac{d}{2},
\end{array}
$$

then \(a+b-c+d\)
$$
=f(0)+\frac{2}{3} f(\pi)+\frac{4}{3} f\left(\frac{\pi}{3}\right) \leqslant 3 .
$$

Equality holds if and only if \(f(0)=f(\pi)=f\left(\frac{\pi}{3}\right)=1\), i.e., \(a=1, b+d=1, c=-1\).
At this point, let \(t=\cos x(-1 \leqslant t \leqslant 1)\). Then
$$
\begin{array}{l}
f(x)-1 \\
=\cos x+b \cos 2 x-\cos 3 x+d \cos 4 x-1 \\
=t+(1-d)\left(2 t^{2}-1\right)-\left(4 t^{3}-3 t\right)+ \\
d\left(8 t^{4}-8 t^{2}+1\right)-1 \\
=2(t-1)(t+1)(2 t-1)[2 d t-(1-d)] \\
\leqslant 0 \\
\end{array}
$$

for any real number \(t \in[-1,1]\).
Thus, \(d>0\), and \(\frac{2 d}{2}=\frac{1-d}{1}\), i.e., \(d=\frac{1}{2}\).
Therefore, the maximum value of \(a+b-c+d\) is 3, and at this time,
$$
(a, b, c, d)=\left(1, \frac{1}{2},-1, \frac{1}{2}\right) \text {. }
$$