Example 6. $15 x \in R$, find the maximum value of the following function
$$f(x)=|\sin x(a+\cos x)|$$
By Cauchy inequality and AM-GM inequality, we have
$$\begin{aligned}
f^{2}(x)= & \frac{1}{\lambda^{2}} \sin ^{2} x(a \lambda+\lambda \cos x)^{2} \leqslant \\
& \frac{1}{\lambda^{2}} \sin ^{2} x\left(\lambda^{2}+\cos ^{2} x\right)\left(a^{2}+\lambda^{2}\right) \leqslant \\
& \frac{1}{\lambda^{2}}\left(\frac{\sin ^{2} x+\lambda^{2}+\cos ^{2} x}{2}\right)\left(a^{2}+\lambda^{2}\right)= \\
& \frac{1}{\lambda^{2}}\left(\frac{1+\lambda^{2}}{2}\right)^{2}\left(a^{2}+\lambda^{2}\right)
\end{aligned}$$

Equality holds if and only if $\lambda^{2}=a \cos x, \sin ^{2} x=\lambda^{2}+\cos ^{2} x$, eliminating $x$ we get
$$2 \lambda^{4}+a^{2} \lambda^{2}-a^{2}=0$$

Solving this, we get
$$\lambda^{2}=\frac{1}{4}\left(\sqrt{a^{4}+8 a^{2}}-a^{2}\right), \cos x=\frac{1}{4}\left(\sqrt{a^{2}+8}-a\right)$$

Thus, when $x=2 k \pi \pm \arccos \left(\frac{1}{4}\left(a^{2}+8\right)-a\right), k \in \mathbf{R}, f(x)$ has the maximum value
$$f(x)_{\max }=\frac{\sqrt{a^{4}+8 a^{2}}-a^{2}+4}{8} \sqrt{\frac{\sqrt{a^{4}+8 a^{2}}+a^{2}+2}{2}}$$

Note: This method can be used to solve the maximum value problem of $\sin A+\sin B+k \sin C$ in $\triangle A B C$. For example, in $\triangle A B C$ we have
$$\sin A+\sin B+5 \sin C \leqslant \frac{\sqrt{198+2 \sqrt{201}}(\sqrt{201}+3)}{40}$$