Slope Optimization for Paraboloid Refer to this question and answer for background information.
I am trying to optimize the slope of the function $f(x,y)=x^2+y^2$ at point $(a,b)$ with direction $\theta$. We know that the slope of the function with these conditions is $2a\cos(\theta)+2b\sin(\theta)$. I am trying to figure out what direction I need to turn from the given $\theta$ in order for the slope to be the largest. Same for the slope to be the smallest.
My thoughts thus far are simply to take $\frac{\partial}{\partial\theta}\left[2a\cos(\theta)+2b\sin(\theta)\right]$ and set it equal to zero, solving for $\theta$. Then you can just subtract that from the given $\theta$ to find the angle necessary to turn. I do not, however, think this is correct. An explanation for why something of this nature would work $\textbf{or}$ an original solution would be greatly appreciated.
 A: The gradient vector is given by
$$\nabla f(a,b)=\left\langle f_x(a,b),f_y(a,b)\right\rangle.$$
The direction vector of the gradient can be found by dividing the gradient by its magnitude
$$\mathbf{u}=\frac{\nabla f(a,b)}{\Vert\nabla f(a,b)\Vert}=\langle\cos\psi,\sin\psi\rangle$$
where $\psi$ is the direction angle of the gradient.
The directional derivative in the direction $\theta$ at $(a,b)$ is the dot-product of the gradient and the direction vector $\langle\cos\theta,\sin\theta\rangle$
$$ D_\theta(a,b)=\nabla f(a,b)\cdot\langle\cos\theta,\sin\theta\rangle$$
The dot-product between two vectors $\mathbf{U},\mathbf{V}$ is given by
$$ \mathbf{U}\cdot\mathbf{V}= \Vert\mathbf{U}\Vert\cdot\Vert\mathbf{V}\Vert\cos\phi$$
where $\phi$ is the angle between the two vectors.
So the angle $\psi-\theta$ between the gradient vector $\nabla(a,b)$ and the direction vector $\langle\cos\theta,\sin\theta\rangle$ satisfies the equation
\begin{eqnarray} \nabla f(a,b)\cdot\langle \cos\theta,\sin\theta\rangle&=&
\Vert\nabla f(a,b)\Vert\cos(\psi-\theta)\\
D_{\psi-\theta}f(a,b)&=&\Vert\nabla f(a,b)\Vert\cos(\psi-\theta)
 \end{eqnarray}
As a result, when the directional derivative is taken in the direction $\theta=\psi$ it takes on its maximum value $\Vert\nabla f(a,b)\Vert$ since $\cos0=1$ and when the direction derivative is taken in the opposite direction of $\Vert\nabla f(a,b)\Vert$, the directional derivative takes on its smallest value -$\Vert\nabla f(a,b)\Vert$ since $\cos\pi=-1$.
To find the angle $\psi-\theta$ between $\theta$ and the gradient one just solves
$$ \cos(\psi-\theta)=\frac{\nabla f(a,b)}{\Vert\nabla f(a,b)\Vert}\cdot\langle \cos\theta,\sin\theta\rangle $$
for $\psi-\theta$.
