\section{Gradients and Directional Derivatives}
\begin{enumerate}[1.]
\item {\it
Find all points $(x,y,z)$ on the surface $xy+z^2=20$ where the tangent plane to that surface is 
perpendicular to the vector $2\ii + 3\jj +4\kk$.}


\medskip

Let $f(x,y,z)= xy+z^2$.
The tangent plane at $(x,y,z)$ is perpendicular to $\nabla f (x,y,z)=\langle y, x, 2z\rangle$.
We also want it to be perpendicular to the vector $2\ii + 3\jj +4\kk$. This means that for some $\lambda$
we have
$$
\langle y, x, 2z\rangle = \lambda \langle 2,3,4\rangle,
$$
therefore $y=2\lambda$, $x=3\lambda$, $2z=4\lambda$ so that $z=2\lambda$. The point also has to lie on
the surface $f(x,y,z)=xy+z^2 = 20$, so that
$$
(3\lambda)(2\lambda) + (2\lambda)^2 = 6\lambda^2 + 4\lambda^4 = 10 \lambda^2 = 20,
$$
$$
\lambda^2 = 2,\ \ \lambda = \pm \sqrt{2}.
$$
This corresponds to two points, $(3\sqrt{2}, 2\sqrt{2}, 2\sqrt{2})$ and $(-3\sqrt{2}, -2\sqrt{2}, -2\sqrt{2})$.


\medskip

\item {\it Let $f(x,y)=x\sin(xy^2)$.

\medskip

(a)  Find the equation of the tangent plane to the surface $z=f(x,y)$ at the point
where $x=\pi$, $y=1$.}

\medskip

We have $f_1(x,y)=\sin(xy^2)+x\cos(xy^2)\cdot y^2$ and $f_2(x,y)=x\cos(xy^2)\cdot 2xy$, so that
$f_1(\pi,1)=\sin\pi + \pi \cos\pi\cdot 1 = 0 - \pi = -\pi$ and
$f_2(\pi,1)=\pi\cos\pi\cdot 2\pi = -2\pi^2$. We also have $f(\pi,1)=\pi\sin\pi =0$.
Therefore the tangent plane is
$$
z=-\pi(x-\pi)-2\pi^2(y-1)=-\pi x -2\pi^2 y +3\pi^2.
$$


{\it (b) Find the directional derivative of $f$ at $(\pi,1)$ in the direction of the vector 
${\bf v}={\bf i}- 3{\bf j}$.}

\medskip

The unit vector in the direction of ${\bf v}$ is $\displaystyle{ {\bf u}=\frac{\bf v}{|{\bf v}|}
= \frac{1}{\sqrt{10}}{\bf i} -  \frac{3}{\sqrt{10}}{\bf i} }$. From (a), we have
${\nabla f (\pi,1)}=-\pi {\bf i}- 2\pi^2 {\bf j}$. Therefore
$$
D_{{\bf u}}f(\pi,1)= \nabla f (\pi,1) \cdot {\bf u}= 
\frac{1}{\sqrt{10}}(-\pi) -  \frac{3}{\sqrt{10}}(-2\pi^2)
= \frac{\pi }{\sqrt{10}}(6\pi-1) 
$$


{\it (c)  Find a vector {\bf w} in the $xy$-plane tangent to the level curve of $f$ at $(\pi,1)$. (The answer might not be unique. Any non-zero tangent vector will suffice.)}


\medskip

The tangent vector should be perpendicular to ${\nabla f (\pi,1)}=-\pi {\bf i}- 2\pi^2 {\bf j}$.
For example, we could take ${\bf w}= 2\pi^2 {\bf i} -\pi  {\bf j}$.

\medskip



\item {\it  Let $f(x,y)=xe^{x-2y}$.

\medskip

(a)  Find the directional derivative of $f$ at $(x,y)=(2,1)$ in the direction of the vector $3{\bf i}-{\bf j}$.}

\medskip
 
We have
\begin{align*}
&f_1(x,y)=e^{x-2y}+xe^{x-2y},\ \ f_1(2,1)=e^0+2e^0=3,
\\
&f_2(x,y)=-2xe^{x-2y},\ \ f_2(2,1)=-4e^0=-4,
\end{align*}
so that $\nabla f(2,1)=3\ii-4\jj$. We also need a unit vector in the direction of $3{\bf i}-{\bf j}$:
$$
{\bf v}=\frac{3{\bf i}-{\bf j}}{\sqrt{3^2+1^2}} = \frac{3{\bf i}-{\bf j}}{\sqrt{10}}.
$$
Therefore
$$
D_{\bf v}f(2,1)=(3\ii-4\jj)\cdot \frac{3{\bf i}-{\bf j}}{\sqrt{10}}
= \frac{3\cdot 3 +(-4)(-1)}{\sqrt{10}}=\frac{13}{\sqrt{10}}.
$$

\medskip

{\it  (b) Find a unit vector ${\bf u}$ such that $D_{\bf u}f(2,1)=0$.}

\medskip

The vector ${\bf u}$ should be perpendicular to $\nabla f(2,1)=3\ii-4\jj$, and should have length 1.
We can take
$$
{\bf u}=\frac{4\ii+3\jj}{\sqrt{4^2+3^2}}= \frac{4\ii+3\jj}{5}.
$$

\medskip

\item {\it 
Let $f(x,y)$ be a differentiable function such that $f(2,5)=3$, $f_x(2,5)=4$, and
$D_{\bf u} f(2,5) = 1$, where ${\bf u}$ is the unit vector in the direction of $\ii-\sqrt{3}\jj$.
Find the equation of the plane tangent to the graph of $z=f(x,y)$ at $(x,y)=(2,5)$.}



\medskip

We are given that 
$f(2,5)=3$, $f_x(2,5)=4$, and
$D_{\bf u} f(2,5) = 1$, where
$$
{\bf u} = \frac{ \ii-\sqrt{3}\jj }{| \ii-\sqrt{3}\jj |}
= \frac{ \ii-\sqrt{3}\jj }{\sqrt{1+3}} = \frac{1}{2}\ii- \frac{\sqrt{3}}{2}\jj .
$$
From the gradient formula,
$$
1= D_{\bf u} f(2,5) = \nabla f(2,5)\cdot {\bf u} = \frac{1}{2} (4) - \frac{\sqrt{3}}{2}
f_y(2,5),
$$
so that
$$
\frac{\sqrt{3}}{2} f_y(2,5) = - 1 + 2 = 1,\ \ 
f_y(2,5) = \frac{2}{\sqrt{3}}.
$$
Therefore the equation of the tangent plane is
$$
z=3+4(x-2) +\frac{2}{\sqrt{3}}(y-5) .
$$

\item {\it 
The tangent plane to the graph of $z=f(x,y)$ at $(x,y)=(3,4)$ has the equation
$x-6y-2z=1$. 

(a) Find the directional derivative $D_{\bf u} f(3,4)$ if $\displaystyle \uu=\frac{\sqrt{3}}{2}\,\ii
-\frac{1}{2}\, \jj$. }

\medskip

We rewrite the equation of the tangent plane as $z=\frac{1}{2}x-3y-\frac{1}{2}$. Reading the partial derivatives from this, we get $\nabla f (3,4) =\langle 1/2,-3\rangle$. Therefore 
$$D_\uu f(3,4)=\frac{1}{2}\cdot \frac{\sqrt{3}}{2} -3(-\frac{1}{2})=\frac{\sqrt{3}}{4} +\frac{3}{2}.$$

\medskip

{\it (b) Is there a unit vector ${\bf v}$ such that $D_{\bf v} f(3,4)=4$?
If yes, find it. If no, explain why.}

\medskip

The largest possible value of $D_{\bf v} f(3,4)$ is $|\nabla f (3,4)|=\sqrt{(1/2)^2+3^2}=\sqrt{9.25}$.
This is less than 4 (since $9.25<16$). Hence there is no such ${\bf v}$.

\bigskip

\item {\it 
The surfaces $4x^2+y^2=z^2$ and $xy=z+1$ intersect in a curve that contains the point
$P=(2,3,5)$. Find the equation of the line tangent to that curve at $P$.}



\medskip

The direction vector ${\bf v}$ of the line has to be tangent to both surfaces, therefore
perpendicular to the normal vectors to both surfaces. The surfaces can be represented as
level surfaces $f(x,y,z)=0$ and $g(x,y,z)=0$, where $f(x,y,z)=4x^2+y^2-z^2$ and $g(x,y,z)=xy-z$.
The normal vectors at $P$ are
$$
{\bf n}_1 = \nabla f(2,3,5),\ \ {\bf n}_2 = \nabla g(2,3,5).
$$
We have
$$
\nabla f(x,y,z)= \langle 8x, 2y, -2z \rangle,\ \ 
 \nabla g(x,y,z)= \langle y, x, -1 \rangle,\ \ 
$$
so that
$$
{\bf n}_1 = \langle 16, 6, -10 \rangle,\ \
{\bf n}_2 = \langle 3, 2, -1 \rangle.
$$
A vector perpendicular to both normals is
$$
\frac{1}{2}{\bf n}_1 \times {\bf n}_2 = 
\left| \begin{matrix}
\ii& \jj & \kk \\
8 & 3 & -5 \\
3 & 2 & -1 \\      
            \end{matrix}\right|   
= (-3+10)\ii - (-8+15)\jj + (16-9)\kk = 7\ii -7\jj +7\kk.						
 $$
For convenience, we will use $\ii-\jj+\kk$ for the direction vector ${\bf v}$.
The line is parallel to ${\bf v}$ and passes through $(2,3,5)$, so it has
the parametric equations
$$
x=2+t,\ \ y=3-t,\ \ z=5+t.
$$


\bigskip





\item {\it 
Let 
$$g(x,y)=\left\{\begin{matrix}
\displaystyle{\frac{x^2y}{x^6+ y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$
Find the directional derivative $D_{\bf u} g(0,0)$, if ${\bf u}$ is the unit vector in the
direction of $3\ii +4\jj$. (This function is not differentiable or even continuous at $(0,0)$, so you have to 
use the definition of the directional derivative.) }


\medskip

We have $\textbf{u} = \frac{1}{5} \big( 3 \textbf{i} + 4 \textbf{j} \big)$. Then
\begin{align*}
D_{\bf u} g(0,0) &= \lim_{h \to 0^+} \frac{g( 0 + 3h/5, 0 + 4h/5 ) - g(0, 0)}{h}\\
&= \lim_{h \to 0^+} \frac{g( 3h/5, 4h/5 )}{h}\\
&= \lim_{h \to 0^+} \frac{ (\frac{3}{5} h )^2 (\frac{4}{5} h) }{ h \big( (\frac{3}{5} h)^6 + (\frac{4}{5} h)^2\big)}\\
&= \lim_{h \to 0^+} \frac{ (\frac{3}{5} h )^2 (\frac{4}{5} h) }{ h^3 \big( (\frac{3}{5})^6 h^4 + (\frac{4}{5})^2\big)}\\
&= \lim_{h \to 0^+} \frac{ (\frac{3}{5})^2 (\frac{4}{5}) }{ \big( (\frac{3}{5})^6 h^4 + (\frac{4}{5})^2\big)}\\
&= \frac{9}{20}.
\end{align*}

\noindent
Additional notes: 

1) To see that $g$ is not continuous at $(0,0)$, let $y=x^3$, then $g(x,x^3)=\frac{x^5}{2x^6} = \frac{1}{2x}$ 
does not have a limit as $x\to 0$. In fact, $g$ is not even bounded near $(0,0)$!

2) And yet, the directional derivative $D_{\bf u} g(0,0)$ exists for every unit vector ${\bf u}$. The proof is similar to the above, but with general $u_1$ and $u_2$ instead of $3/5$ and $4/5$).

\bigskip


\item 
{\it Let
$$f(x,y)=\begin{cases}
\displaystyle{\frac{3xy^2-y^3}{x^2 + y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{cases}
$$

(a) Is $f$ differentiable at $(0,0)$? Prove your answer. }

\medskip

We have $f(x,0)=\frac{0}{x^2}=0$ for $x\neq 0$, and
$f(0,y)=\frac{-y^3}{y^2}=-y$ for $y\neq 0$. 
Combining this with $f(0,0)=0$, we get $f(x,0)=0$ and
$f(0,y)=-y$ for all $x,y$. Differentiating in $x$ and $y$ respectively, we get
$f_1(0,0) =0$ and $ f_2(0,0) =-1$. Hence the linear approximation at $(0,0)$ is $L(x,y)=-y$.

For differentiability, we need 
$$
\lim_{(x,y)\to(0,0)} \frac{f(x,y)-L(x,y)}{|(x,y)-(0,0)|}
= \lim_{(x,y)\to(0,0)} \frac{f(x,y)+y}{\sqrt{x^2+y^2}}=0.
$$
We have for $x \neq 0$, $y \neq 0$,

\begin{equation*}
\frac{f(x,y)+y}{\sqrt{x^2+y^2}} = \frac{3xy^2-y^3+y(x^2+y^2)}{(x^2+ y^2)\sqrt{x^2+y^2}}
= \frac{3xy^2+x^2y}{(x^2+ y^2)\sqrt{x^2+y^2}}.
\end{equation*}
When $x=y$, the last fraction is equal to
$$
\frac{3x^3+x^3}{2x^2\sqrt{2x^2}}=\frac{2x}{\sqrt{2x^2}}=\frac{\sqrt{2}\,x}{|x|}.
$$
This has a limit $\sqrt{2}$ as $x\to 0^+$ and $-\sqrt{2}$ as $x\to 0^-$. In particular, the limit is not 0, so that the function is not differentiable at $(0,0)$.



\medskip

{\it (b) Find the directional derivative $D_{\bf u}f(0,0)$ for a general unit vector $\displaystyle {\bf u}=u_1{\bf i}+u_2{\bf j}$. If it does not exist, explain why.}



\bigskip

By definition,
\begin{align*}
D_{\bf u}f(0,0) &= \lim_{h\to 0^+} \frac{f(hu_1,hu_2)-f(0,0)}{h}\\
&= \lim_{h\to 0^+} \frac{1}{h}\cdot \frac{3h^3 u_1u_2^2 - h^3 u_2^3}{h^2u_1^2+h^2u_2^2}\\
&= \lim_{h\to 0^+} \frac{3u_1u_2^2 - u_2^3}{u_1^2+u_2^2}\\
&= \frac{3u_1u_2^2 - u_2^3}{u_1^2+u_2^2}.
\end{align*}





\item {\it 
Let 
$$f(x,y)=\left\{\begin{matrix}
\displaystyle{\frac{x^5}{x^4+y^4}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$
Find the general formula for  $D_{\bf u}f(0,0)$, where ${\bf u}=(u_1,u_2)$ is a 
unit vector, in terms of $u_1,u_2$.}

\medskip

We calculate from the definition:
\begin{align*}
D_\uu f(0,0)&=\lim_{t\to 0^+}\frac{1}{t}(f(t\uu)-f(0,0))
=\lim_{t\to 0^+}\frac{1}{t}\Big(\frac{t^5u_1^5}{t^4u_1^4+t^4u_2^4}-0\Big)
\\
&=\lim_{t\to 0^+}
\frac{1}{t}\frac{tu_1^5}{u_1^4+u_2^4}=\frac{u_1^5}{u_1^4+u_2^4}.
\end{align*}

\bigskip













\item 
{\it   Suppose that $f(x,y)$ is a function defined for all $(x,y)$ in a neighbourhood of $(a,b)$. 
Suppose also that
$$
D_{{\bf u}}f(a,b) = 2,\ \ D_{{\bf v}}f(a,b) = 3,\ \
$$
where 
$$ {\bf u}= \frac{\sqrt{3}}{2}\,{\bf i} +  \frac{1}{2}\,{\bf j},\ \ \ 
 {\bf v}= \frac{\sqrt{3}}{2}\,{\bf i} -  \frac{1}{2}\,{\bf j},
 $$ 
 and that $f_1(a,b)=-1$. Prove that $f$ is not differentiable at $(a,b)$.}


\medskip

We will prove this by contradiction.
If $f$ were differentiable at $(a,b)$, we would have the formula
$$D_{\bf w} f = f_1(a,b) w_1 + f_2(a,b) w_2= -w_1+  f_2(a,b) w_2$$
for all unit vectors ${\bf w}=\langle w_1,w_2 \rangle$. Applying this formula to
the vectors ${\bf u}$ and ${\bf v}$, we would have
$$ 
D_{\bf u}f(a,b)= -\frac{\sqrt{3}}{2} +  \frac{1}{2}\,f_2(a,b) = 2,
$$
$$
D_{\bf v}f(a,b) = -\frac{\sqrt{3}}{2} -  \frac{1}{2}\,f_2(a,b) =3.
$$
Therefore $f_2(a,b) = 4+\sqrt{3}$ from the first equation and $f_2(a,b)  = -6 - \sqrt{3}$ from the second equation, a contradiction. It follows that $f$ cannot be differentiable at $(a,b)$.


\medskip

\item {\it Is there a differentiable function $f:\rr^2\to \rr$ such that 
 $D_{\bf u}f(0,0)=u_1^2-u_2^2$ for every unit vector ${\bf u}=(u_1,u_2)$?
If yes, find it. If no, explain why.}


\medskip

If there were such a function, we would have $f_x(0,0)=D_{\bf i}f(0,0)=1^2-0^2=1$ and $f_y(0,0)=D_{\bf j}f(0,0)=0^2-1^2=-1$, hence
$$\nabla f(0,0)=(1,-1).$$
From the dot product formula, we would then have
$D_{\bf u}f(0,0)=\nabla f(0,0)\cdot {\bf u}=u_1-u_2$ for all $\uu$. But this
is not consistent with $D_{\bf u}f(0,0)=u_1^2-u_2^2$. For example, if
$\uu=-{\bf i}$, the dot product formula gives $D_{-\bf i}f(0,0)=-1-0=-1$, 
and the formula in the text of the problem gives $D_{-\bf i}f(0,0)=1^2-0^2=1$. Therefore there is no such function.

\medskip





\end{enumerate}