5. Let $\frac{\pi}{4}<\theta<\frac{\pi}{2}$, then the maximum value of $S=\sin 2 \theta-\cos ^{2} \theta$ is $\qquad$.
5. Solution: Let $\lambda>0$ be a constant to be determined, then $S=\cos \theta(2 \sin \theta-$
$$
\begin{array}{l}
\cos \theta) \leqslant \frac{1}{4 \lambda} \cdot\left(\frac{\lambda \cos \theta+2 \sin \theta-\cos \theta}{2}\right)^{2} \\
=\frac{1}{4 \lambda} \cdot(2 \sin \theta+(\lambda-1) \cos \theta)^{2} \leqslant \frac{2^{2}+(\lambda-1)^{2}}{4 \lambda}\left[\sin ^{2} \theta\right. \\
\left.+\cos ^{2} \theta\right]=\frac{2^{2}+(\lambda-1)^{2}}{4 \lambda} .
\end{array}
$$

The conditions for both “ $\leqslant$ ” to hold simultaneously are
$$
\left\{\begin{array}{l}
\lambda \cos \theta=2 \sin \theta-\cos \theta \\
2: \sin \theta=(\lambda-1): \cos \theta
\end{array} \Rightarrow(\lambda+1)(\lambda-1)=4,\right.
$$

Thus, $\lambda=\sqrt{5}$,
$\frac{2^{2}+(\lambda-1)^{2}}{4 \lambda}=\frac{\sqrt{5}-1}{2}$, and $\theta=\arctan \frac{\sqrt{5}+1}{2}$,
Therefore, $S$ has a maximum value of $\frac{\sqrt{5}-1}{2}$.