Calculus inequality involving sine and cosine community! I saw the following inequality in a calculus assignment, which I thought was harder to prove than I expected: For every $x\in\mathbb{R},$$$(\sin x + a \cos x)(\sin x + b \cos x)\leq 1+(\frac{a+b}{2})^2.$$
By means of a graphing device, I noticed that when $a=b$, $f(x)=(\sin x + a\cos x)(\sin x + b \cos x)$ has  $1+(\frac{a+b}{2})^2$ as its maximum, but in other cases the maximum of  $f$ is strictly less (and sometimes far less) than this number. I'd appreciate any kind of help :)
 A: $$|\sin x+a\cos x|=\left|\sqrt{1+a^2}\left( \frac{1}{\sqrt{1+a^2}}\sin x+\frac{a}{\sqrt{1+a^2}}\cos x \right)\right|=|\sqrt{1+a^2}(\cos \theta \sin x+\sin \theta \cos x)|=|\sqrt{1+a^2}( \sin(x+\theta) )|\le \sqrt{1+a^2}.$$ So the maximum value of $\sin x+a\cos x=\sqrt{1+a^2}.$ 
\begin{align*}
|(\sin x+a\cos x)(\sin x+b\cos x)|& = |\sin x+a\cos x||\sin x+b\cos x|\\
& \le \sqrt{1+a^2}\sqrt{1+b^2}=\sqrt{(1+a^2)(1+b^2)}\\
& \le \frac{(1+a^2)+(1+b^2)}{2} \tag{1}\\
&=1+\frac{a^2+b^2}{2}
\end{align*}
In $(1)$,  I have used AM-GM Inequality.
A: 
For any trig0nometric expression of the form $$A\sin x+B\cos x=\sqrt{A^2+B^2}\left(\dfrac{A}{\sqrt{A^2+B^2}}\sin x+\dfrac{B}{\sqrt{A^2+B^2}}\cos x\right)$$ 
  can be written in the form $\sqrt{A^2+B^2}\sin(x+\phi)$ with $\tan\phi=B/A$ and hence $\vert A\sin x+B\cos x|\le\sqrt{A^2+B^2}$ for any $A,B\in\Bbb{R}.$
  In fact these bounds are sharp. 

Here I will use above fact to give a pure trig-solution (without calculus).
First observe that
\begin{align}
f(x)& = (\sin x+a \cos x)(\sin x+b \cos x) \\
 & = \sin^2x+(a+b)\sin x\cos x+ab\cos^2x\\ 
 & =\dfrac{1}{2}\left((1-\cos 2x)+(a+b)\sin 2x+ab(1+\cos 2x)\right) \\
 & =\left(\dfrac{a+b}{2}\right)\sin2x+\left(\dfrac{ab-1}{2}\right)\cos 2x+\left(\dfrac{ab+1}{2}\right).\\
\end{align}
Hence $$-\sqrt{\left(\dfrac{a+b}{2}\right)^2+\left(\dfrac{ab-1}{2}\right)^2}\le f(x)-\left(\dfrac{ab+1}{2}\right)\le\sqrt{\left(\dfrac{a+b}{2}\right)^2+\left(\dfrac{ab-1}{2}\right)^2}.$$ Therefore the function has the maximum value
$$\left(\dfrac{ab+1}{2}\right)+\sqrt{\left(\dfrac{a+b}{2}\right)^2+\left(\dfrac{ab-1}{2}\right)^2}$$
and minimum value
$$\left(\dfrac{ab+1}{2}\right)-\sqrt{\left(\dfrac{a+b}{2}\right)^2+\left(\dfrac{ab-1}{2}\right)^2}.$$
A: Thank you all. Today I was looking at some old stuff and found this exercise, which was given to me by a student I was tutoring. Now with a fresher view I simply noticed that completing the square we have $$f(x)=(\sin x +a\cos x)(\sin x+b\cos x)=(\sin x+(\frac{a+b}{2})\cos x)^2-(\frac{a-b}{2})^2\cos^2x,$$
and thus $f(x)\leq (\sin x+(\frac{a+b}{2})\cos x)^2=(\sqrt{1+(\frac{a+b}{2})^2}\sin(x+\phi))^2\leq 1+(\frac{a+b}{2})^2.$
