Example 8 Find the maximum and minimum values of the function $f(x)=2 x+\sqrt{1+x-x^{2}}$.

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
Solution: Since $f(x)=2 x+\sqrt{1+x-x^{2}}=2 x+$ $\sqrt{\frac{5}{4}-\left(x-\frac{1}{2}\right)^{2}}$,

we can let $x-\frac{1}{2}=\frac{\sqrt{5}}{2} \sin \theta, \theta \in\left[-\frac{\pi}{2}, \frac{\pi}{2}\right]$, then $x$ $=\frac{1}{2}+\frac{\sqrt{5}}{2} \sin \theta$. Thus,
$$
f(x)=g(\theta)=1+\sqrt{5} \sin \theta+\frac{\sqrt{5}}{2} \cos \theta=1+\frac{5}{2}
$$
$\sin (\theta+\varphi)$, where $\varphi=\arcsin \frac{1}{\sqrt{5}}$.
Since $\theta \in\left[-\frac{\pi}{2}, \frac{\pi}{2}\right]$, hence $\theta+\varphi \in$ $\left[\arcsin \frac{1}{\sqrt{5}}-\frac{\pi}{2}, \arcsin \frac{1}{\sqrt{5}}+\frac{\pi}{2}\right]$,
thus $\sin (\theta+\varphi) \in\left[-\frac{2}{\sqrt{5}}, 1\right]$,
which means $g(\theta) \in\left[1-\sqrt{5}, \frac{7}{2}\right]$,
therefore $f(x)_{\min }=1-\sqrt{5}, f(x)_{\max }=\frac{7}{2}$.