Example 2 Given a positive integer $n$ and a positive number $M$. For all arithmetic sequences $a_{1}$, $a_{2}$, $a_{3}$, ..., satisfying the condition $a_{1}^{2}+a_{n+1}^{2} \leqslant M$, find the maximum value of $S=a_{n+1}+a_{n+2}+\cdots+a_{2 n+1}$.
(1999, National High School Mathematics Competition)
Analysis: Noting that $a_{1}^{2}+a_{n+1}^{2} \leqslant M$, let $a_{1}=$ $\sqrt{k} \cos \theta, a_{n+1}=\sqrt{k} \sin \theta$, where $0 \leqslant k \leqslant M, 0 \leqslant$ $\theta<2 \pi$. Then
$$
\begin{aligned}
S & =\frac{n+1}{2}\left(a_{n+1}+a_{2 n+1}\right)=\frac{n+1}{2}\left(3 a_{n+1}-a_{1}\right) \\
& =\frac{n+1}{2}(3 \sqrt{k} \sin \theta-\sqrt{k} \cos \theta) \\
& =\frac{(n+1) \sqrt{10 k}}{2} \cdot \sin (\theta-\varphi),
\end{aligned}
$$

where $\sin \varphi=\frac{1}{\sqrt{10}}, \cos \varphi=\frac{3}{\sqrt{10}}$. Therefore,
$$
S \leqslant \frac{(n+1) \sqrt{10 k}}{2} \leqslant \frac{(n+1) \sqrt{10 M}}{2},
$$

with equality holding if and only if $\sin (\theta-\varphi)=1$ and $k=M$. At this point, $\sin \theta=\cos \varphi=\frac{3}{\sqrt{10}}, \cos \theta=-\sin \varphi$ $=-\frac{1}{\sqrt{10}}$, i.e., $a_{n+1}=\frac{3}{\sqrt{10}} \sqrt{M}, a_{1}=$ $-\frac{1}{\sqrt{10}} \sqrt{M}, S_{\max }=\frac{(n+1) \sqrt{10 M}}{2}$.