Example 7 Let $A>0, B>0, a<b$, find the maximum and minimum values of the function $f(x)=A \sqrt{x-a}+B \sqrt{b-x}$.


Solve: From $x-a \geqslant 0$ and $b-x \geqslant 0$, we obtain the domain as $[a, b]$.
Also, from $f(x)=A \sqrt{x-a}+B \sqrt{b-x}$
$$
=\sqrt{A^{2}+B^{2}} \cdot \sqrt{b-a}\left(\frac{A}{\sqrt{A^{2}+B^{2}}} \cdot \sqrt{\frac{x-a}{b-a}}+\frac{B}{\sqrt{A^{2}+B^{2}}} \cdot \sqrt{\frac{b-x}{b-a}}\right),
$$

we can let $\cos \alpha=\frac{A}{\sqrt{A^{2}+B^{2}}}, \cos \beta=\sqrt{\frac{x-a}{b-a}}$, and $0<\alpha, \beta<\frac{\pi}{2}$, then
$$
f(x)=\sqrt{A^{2}+B^{2}} \cdot \sqrt{b-a} \cos (\alpha-\beta).
$$
Since $-\frac{\pi}{2}<\alpha-\beta<\frac{\pi}{2}$, we have
$$
f(x)_{\max }=\sqrt{A^{2}+B^{2}} \cdot \sqrt{b-a} \quad \text{when} \quad \alpha=\beta.
$$
At this time, $\sqrt{\frac{x-a}{b-a}}=\frac{A}{\sqrt{A^{2}+B^{2}}}$, thus
$$
x_{1}=a+\frac{A^{2}(b-a)}{A^{2}+B^{2}}>0, \quad b-x_{1}=\frac{B^{2}(b-a)}{A^{2}+B^{2}}>0,
$$
so $x_{1} \in[a, b]$,
thus $f(x)_{\max }=f\left(x_{1}\right)=\sqrt{\left(A^{2}+B^{2}\right)(b-a)}$.
Also, from $-\frac{\pi}{2}<\alpha-\beta<\frac{\pi}{2}$, we have
$$
f(x)_{\min }=\min \{A, B\} \quad \text{when} \quad \alpha-\beta=\pm \frac{\pi}{2}.
$$
For the function
$$
f(x)=A \cos x + B \sin x \quad (A>0, B>0)
$$

we have $f(x)_{\text {max }}=\sqrt{A^{2}+B^{2}}, f(x)_{\text {min }}=\min \{A, B\}$.
The above formulas (5-2) and (5-3) are very useful, and can be used to conveniently solve relevant problems (see Exercise A, questions 4 and 5).