Example 2 Given a positive integer $n$ and a positive number $M$. For all arithmetic sequences $a_{1}$, $a_{2}, a_{3}, \cdots$ 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)
Solution: Let the common difference be $d$, $a_{n+1}=\alpha$, then
$$
\begin{array}{l}
S=a_{n+1}+a_{n+2}+\cdots+a_{2 n+1} \\
=(n+1) \alpha+\frac{n(n+1)}{2} d .
\end{array}
$$

Thus, $\alpha+\frac{n d}{2}=\frac{S}{n+1}$.
Then
$$
\begin{aligned}
M & \geqslant a_{1}^{2}+a_{n+1}^{2}=(\alpha-n d)^{2}+\alpha^{2} \\
& =\frac{4}{10}\left(\alpha+\frac{n d}{2}\right)^{2}+\frac{1}{10}(4 \alpha-3 n d)^{2} .
\end{aligned}
$$

Since $\frac{1}{10}(4 \alpha-3 n d)^{2} \geqslant 0$, we have
$$
M \geqslant \frac{4}{10}\left(\frac{S}{n+1}\right)^{2} \text {. }
$$

Therefore, $|S| \leqslant \frac{\sqrt{10}}{2}(n+1) \sqrt{M}$.
And when $\alpha=\frac{3}{\sqrt{10}} \sqrt{M}, d=\frac{4}{\sqrt{10}} \frac{1}{n} \sqrt{M}$, we have
$$
\begin{aligned}
S & =(n+1)\left(\frac{3}{\sqrt{10}} \sqrt{M}+\frac{n}{2} \frac{4}{\sqrt{10}} \frac{1}{n} \sqrt{M}\right) \\
& =(n+1) \frac{5}{\sqrt{10}} \sqrt{M}=\frac{\sqrt{10}}{2}(n+1) \sqrt{M} .
\end{aligned}
$$

Since at this point $4 \alpha=3 n d$, we have
$$
\begin{array}{l}
a_{1}^{2}+a_{n+1}^{2}=\frac{4}{10}\left(\frac{S}{n+1}\right)^{2} \\
=\frac{4}{10} \times \frac{10}{4} M=M .
\end{array}
$$

Therefore, the maximum value of $S$ is $\frac{\sqrt{10}}{2}(n+1) \sqrt{M}$.