# Why is the angle that maximizes $a \cos(\theta) + b \sin(\theta)$ in the direction of $(a, b)$?

I'm wondering if there is an intuitive explanation to the result above. Mathematically, it is easy to prove: If we let $$x = a \cos(\theta) + b \sin(\theta)$$, then setting $$\frac{\mathbb{d}x}{\mathbb{d}\theta} = 0$$ tells us that $$\theta = \arctan(\frac{b}{a})$$. Thus $$\theta$$ is the angle between the positive x axis and the vector $$(a, b)$$. Another way to show this is to notice that $$x = (a, b) \cdot (\cos(\theta), \sin(\theta)) = ||(a,b)||\cos(\alpha)$$. If $$\cos(\alpha) = 1$$, then $$x$$ will be maximized and will be in the direction of $$(a, b)$$, since $$\alpha = 0$$.

At the same time, the answer just seems so simple that I can't help but wonder whether there's a more obvious way to look at it. Trigonometry is not really inherent to the problem, $$\cos(\theta)$$ and $$\sin(\theta)$$ can also be replaced by the components of some vector $$\vec{v}$$.

$$\frac{x}{\sqrt{a^2+b^2}} = \frac{a}{\sqrt{a^2+b^2}} \cos \theta + \frac{b}{\sqrt{a^2+b^2}} \sin \theta,$$ so if we let $$\varphi = \arctan \frac{b}{a},$$ we have $$\cos \varphi = \frac{a}{\sqrt{a^2+b^2}}, \quad \sin \varphi = \frac{b}{\sqrt{a^2+b^2}},$$ hence $$x = \sqrt{a^2+b^2} ( \cos \varphi \cos \theta + \sin \varphi \sin \theta) = \sqrt{a^2 + b^2} \cos (\theta - \varphi).$$ Since $$a, b$$ are constants, it follows that $$x$$ is maximized whenever $$\cos (\theta - \varphi) = 1$$, or $$\theta = \varphi + 2\pi k$$ for some integer $$k$$. This completes the proof.

Here is a geometric-intuitive way but also easy to verify analytically.

If you interpret $$z:=(a,b) = a+ib$$ as complex number, then the expression

$$a\cos \theta +b\sin \theta = \Re \left( (\cos \theta -i\sin \theta\right)\cdot (a+ib)) =\Re \left(e^{-i\theta}z\right)$$

is the real part of $$e^{-i\theta}z$$ after rotating $$z$$ counterclockwise by $$\theta$$.

Of course, you maximize the real part of $$e^{-i\theta}z$$ by rotating $$z$$ back to the positive real axis. Analytically this is clear because

$$e^{-i\theta}z=x+iy\Rightarrow x^2+y^2=|z|^2 = a^2+b^2$$

So, analytically, you maximize $$x^2$$ by minimizing $$y^2$$, which means that the imaginary part $$y$$ of $$e^{-i\theta}z$$ should become zero and the real part $$x$$ should be positive.

With $$z=|z|e^{i\phi}$$ you get

$$e^{-i\theta}z = e^{-i\theta}\cdot|z|e^{i\phi}=|z|e^{i(\phi-\theta)}=|z| \text{ for } \boxed{\theta = \phi}$$

Per the C-S inequality

$$a \cos\theta + b \sin\theta \le \sqrt{(a^2+b^2)(\cos^2\theta +\sin^2\theta)} = \sqrt{a^2+b^2}$$

where the equality occurs if $$(\cos\theta, \sin\theta)$$ and $$(a,b)$$ are in the same direction.