\section{Higher Order Derivatives}
\begin{enumerate}[1.]
\item {\it
Let $f(x,y)=x\sin(xy^2)$.

\medskip

(a) Find all first and second order partial derivatives of $f$.}

\medskip

\begin{align*}
f_1(x,y) &=\sin(xy^2)+x\cos(xy^2)\cdot y^2
\\
f_2(x,y) &=x\cos(xy^2)\cdot 2xy= 2x^2y\cos(xy^2)
\\
f_{11}(x,y) &= y^2 \cos(xy^2) + \cos(xy^2)\cdot y^2 + x y^2 (-\sin(xy^2) \cdot y^2) \\
&=  2 y^2 \cos(xy^2)  - xy^4 \sin(xy^2) 
\\
f_{12}(x,y) &= 4xy \cos(xy^2) + 2x^2y (-\sin(xy^2) \cdot y^2)
\\
&=  4xy \cos(xy^2) - 2x^2y^3 \sin(xy^2)
\\
f_{22}(x,y)&=2x^2 \cos(xy^2) + 2x^2y  (-\sin(xy^2) \cdot 2xy) 
\\
&= 2x^2 \cos(xy^2)  -4x^3 y^2\sin(xy^2) 
\end{align*}
Since $f$ and all its derivatives are continuous, $f_{12}=f_{21}$.



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

\medskip

From (a),  $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.
$$

\item {\it A function $f(x_1,...,x_n)$ of $n$-many variables is said to be \textbf{harmonic} if it satisfies the equation,
$$
\frac{\partial^2 f}{\partial x_1^2}  + \cdots + \frac{\partial^2 f}{\partial x_n^2} = 0.
$$
Demonstrate that the following functions are harmonic. 

\medskip

(a) $f(x,y) = \frac{x}{x^2 + y^2}$ for $(x,y) \neq 0$;}

\medskip

We need to calculate the derivatives $f_{xx} (x,y)$ and $f_{yy} (x,y)$.  The first-order partials can be calculated by applying the quotient rule, giving
$$
f_x (x,y) = \frac{y^2 - x^2}{(x^2 + y^2)^2}, \, f_y (x,y) = \frac{-2xy}{(x^2 + y^2)^2}.
$$
A second application of the quotient rule gives,
$$
f_{xx} (x,y) = \frac{2x (x^2 - 3 y^2)}{(x^2 + y^2)^3},  \, f_{yy} (x,y) = -\frac{2x (x^2 - 3 y^2)}{(x^2 + y^2)^3}.
$$
Since $f_{xx} (x,y) = -f_{yy} (x,y)$ for any $(x,y) \neq (0,0)$, we see that $f(x,y)$ is indeed harmonic away from the origin.

\medskip

{\it (b) $f(x,y,z) = \frac{x}{(x^2 + y^2 + z^2)^{3/2}}$ for $(x,y,z) \neq (0,0,0)$ (a longer calculation);}

\medskip

We again need to calculate the partial derivatives $f_{xx} (x,y,z)$, $f_{yy} (x,y,z)$ and $f_{zz} (x,y,z)$ for $(x,y,z) \neq (0,0,0)$.  The differentiation in $x$ is the most complicated; the Quotient Rule gives
\begin{eqnarray*}
f_{x} (x,y,z) & = & \frac{(x^2 + y^2 + z^2)^{3/2} - x \cdot 2x \cdot 3/2 \sqrt{x^2 + y^2 + z^2}}{(x^2 + y^2 + z^2)^3} \\[1ex]
\quad & = & \frac{(x^2 + y^2 + z^2)^{3/2} - 3 x^2 \sqrt{x^2 + y^2 +z^2}}{(x^2 + y^2 + z^2)^3} \\[1ex]
\textrm{(cancelling common factors)} & = & \frac{x^2 + y^2 + z^2 - 3 x^2}{(x^2 + y^2 + z^2)^{5/2}} \\[1ex]
\quad & = & \frac{-x^2 + y^2  + z^2}{(x^2 + y^2 + z^2)^{5/2}}
\end{eqnarray*}
The differentiation in $y$ and $z$ are symmetric (since the numerator is not a function of $y$ or $z$).  Using the Quotient Rule (or simply the Chain Rule, if you are clever with negative exponents), one arrives at
$$
f_{y} (x,y) = - \frac{3 xy}{(x^2 + y^2 + z^2)^{5/2}}, \, \, f_{z} (x,y) = -\frac{3xz}{(x^2 + y^2 + z^2)^{5/2}}
$$
which is again symmetric in the variables $y$ and $z$. In particular, if we know $f_{yy} (x,y,z)$ we can perform the change of variables $y \mapsto z$ and $z \mapsto y$ to find $f_{zz} (x,y,z)$.  Using the Quotient Rule again gives
\begin{eqnarray*}
f_{yy} (x,y,z) & = & - \frac{3x (x^2 + y^2 + z^2)^{5/2} - (3xy) \cdot (2y) \cdot 5/2 (x^2 + y^2 + z^2)^{3/2}}{(x^2 + y^2 + z^2)^5} \\[1ex]
\quad & = & - \frac{3x (x^2 + y^2 + z^2)^{5/2} - 15 x y^2 (x^2 + y^2 + z^2)^{3/2}}{(x^2 + y^2 + z^2)^{5}} \\[1ex]
%\textrm{(cancelling common factors)} 
& = & - \frac{3x^3 + 3xy^2 + 3xz^2 - 15 x y^2 }{(x^2 + y^2 + z^2)^{7/2}} \\[1ex]
\quad & = & - \frac{3x (x^2 - 4 y^2 + z^2)}{(x^2 + y^2 + z^2)^{7/2}}
\end{eqnarray*}
Using the aforementioned change of variables $(y,z) \mapsto (z,y)$, we have
$$
f_{zz} (x,y,z) = - \frac{3x (x^2 + y^2 - 4z^2)}{(x^2 + y^2 + z^2)^{7/2}}
$$
Finally, we could calculate $f_{xx}(x,y,z)$ using the Quotient Rule,  which would give
$$
f_{xx} (x,y,z) = \frac{6 x^3 - 9x(y^2 + z^2)}{(x^2 + y^2 + z^2)^{7/2}}.
$$
Notice that $f_{xx}$, $f_{yy}$ and $f_{zz}$ all share a common denominator. So, to verify that $f(x,y,z)$ is harmonic, we need only add together the numerators. This yields
$$
\underbrace{6x^3 - 9x(y^2 + z^2)}_{\textrm{num.  of } f_{xx}} + \underbrace{(-3x(x^2 - 4y^2 + z^2))}_{\textrm{num. of } f_{yy}} +
\underbrace{(-3x(x^2 + y^2 - 4z^2))}_{\textrm{num. of } f_{zz}}
$$
and combining like terms shows that $f_{xx} + f_{yy} + f_{zz} = 0$ for any $(x,y,z) \neq (0,0,0)$.

\bigskip

{\it (c) $f(x_1,...,x_n) = \frac{1}{(x_1^2 + \cdots + x_n^2)^{n/2 - 1}}$ for $(x_1,...,x_n) \neq (0,...,0)$ and $n \geq 3$.}

\medskip

We rewrite
$$
f(x_1,...,x_n) =  \frac{1}{(x_1^2 + \cdots + x_n^2)^{n/2 - 1}} = (x_1^2 + \cdots + x_n^2)^{-n/2 + 1},
$$
and use the Chain Rule to determine for $(x_1,...,x_n) \neq (0,...,0)$ 
\begin{eqnarray*}
f_{j} (x_1,...,x_n) & = & \frac{\partial}{\partial x_j} \big[(x_1^2 + \cdots + x_n^2)^{-n/2 + 1} \big] \\[1ex]
\quad &=& -\frac{n - 2}{2} \frac{2x_j}{(x_1^2 + \cdots + x_n^2)^{n/2}} \\[1ex]
\quad & = & -\frac{(n - 2) x_j}{(x_1^2 + \cdots + x_n^2)^{n/2}}.
\end{eqnarray*}
Applying the derivative in $x_j$ again gives
\begin{eqnarray*}
f_{jj} (x_1,...,x_n) & = & -\frac{(n-2)(x_1^2 + \cdots + x_n^2)^{n/2} - ((n-2) x_j)(n x_j) (x_1^2 + \cdots + x_n^2)^{(n-2)/2} }{(x_1^2 + \cdots + x_n^2)^n} \\[1ex]
\quad & = & - \frac{(n-2)(x_1^2 + \cdots + x_n^2) - n(n-2) x_j^2}{(x_1^2 + \cdots + x_n^2)^{(n+2)/2}} \\[1ex]
\quad & = & - \frac{n - 2}{(x_1^2 + \cdots + x_n^2)^{(n+2)/2}} \bigg[(x_1^2 + \cdots + x_n^2) - n x_j^2\bigg]
\end{eqnarray*}
Notice that, the terms outside the large brackets are symmetric in the variables $x_1,...,x_n$. That is, regardless of the choice of $1 \leq j \leq n$, the same term will appear on the outside when we calculate $f_{jj}$. It then follows that
$$
f_{11} + \cdots + f_{nn} = 0
$$
because one has
$$
\sum_{j = 1}^{n} \bigg[(x_1^2 + \cdots + x_n^2) - n x_j^2\bigg] = n (x_1^2 + \cdots + x_n^2) - n (x_1^2 + \cdots + x_n^2) = 0.
$$

\begin{remark}
As you surely know by know: it is often an absolute pain to determine by brute calculation whether a given function $f(x_1,...,x_n)$ is harmonic. Fortunately, mathematicians have developed more nuanced tools in areas like Complex Analysis and Partial Differential Equations which given necessary or sufficient conditions for a function $f$ to be harmonic on some domain. More on this in later courses!
\end{remark}

\item 
{\it  Let $$F(x,y)= \left\{\begin{matrix}
\displaystyle{\frac{xy(x^2-y^2)}{x^2+y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$
Demonstrate carefully that both $F_{12} (0,0)$ and $F_{21} (0,0)$ exist and \underline{are not equal}.  Why does this not violate Theorem 2.5.2?

Hint: we advise that you proceed by obtaining the following in order:
\begin{itemize}
\item $F_1(0,y)$ for all $y\in\rr$ and $F_2(x,0)$ for all $x\in\rr$,
\item $F_{12}(0,0)$ and $F_{21}(0,0)$.
\end{itemize}
If done correctly, you will obtain that $F_{21}(0,0)=1$
and $F_{12}(0,0)=-1$.  }

\medskip
\bigskip


For $(x,y)\neq (0,0)$, we have 
\begin{align*}
F_1(x,y)&=\frac{\partial}{\partial x} \left[ \frac{xy(x^2-y^2)}{x^2+y^2}\right] \\
&=\frac{y(x^2-y^2)}{x^2+y^2} + \frac{xy\cdot 2x }{x^2+y^2} - \frac{xy(x^2-y^2)\cdot 2x}{(x^2+y^2)^2}\\
&=\frac{y(x^2+y^2-2x^2)(x^2-y^2)}{(x^2+y^2)^2}+  \frac{2x^2y}{x^2+y^2} \\
&=-\frac{y(x^2-y^2)^2}{(x^2+y^2)^2}+  \frac{2x^2y}{x^2+y^2}.
\end{align*}
When $x=0$ and $y\neq 0$, we get
\begin{align*}
F_1(0,y)
&=-\frac{y(-y^2)^2}{(y^2)^2}+  \frac{0}{y^2}= -\frac{y^5}{y^4}=-y.
\end{align*}
We also have $F(x,y)=-F(y,x)$, so that by symmetry, we have for $x\neq 0$
\begin{align*}
F_{2}(x,y)& =-F_{1}(y,x)=\frac{x(y^2-x^2)^2}{(x^2+y^2)^2}- \frac{2xy^2}{x^2+y^2},
\\
F_2(x,0) &= \frac{x(-x^2)^2}{(x^2)^2}- \frac{0}{x^2} = \frac{x^5}{x^4}=x.
\end{align*}
Also, we have $F(0,x)=F(y,0)=F(0,0)=0$. so that $F_1(0,0)=F_2(0,0)=0$.
Therefore the formulas $F_1(0,y)=-y$ and $F_2(x,0)=x$ are in fact valid for all $x$ and $y$, including $x=0$ and $y=0$.
It follows that 
$$
F_{12}(0,0)=\frac{d}{d y} F_1(0,y) \Big|_{y=0} = \frac{d}{dy} (-y)   \Big|_{y=0}  =-1,
$$
$$
F_{21}(0,0)=\frac{d}{d x} F_2(x,0)    \Big|_{x=0}   = \frac{d}{d x} (x)    \Big|_{x=0}  =1.
$$
(We used $\frac{d}{d y} $ notation here because $F_1(0,y)$ has only one variable left, but $\frac{\partial}{\partial y} $ would also
be acceptable in this context.)

\medskip

To explain why this function $f(x,y)$ does not violate Theorem 2.5.2, we calculate the mixed partial derivative $F_{12} (x,y)$ for $(x,y)\neq (0,0)$:
\begin{align*}
F_{12}(x,y)&=-\frac{(x^2-y^2)^2}{(x^2+y^2)^2}  -\frac{y(x^2-y^2)(-2y)}{(x^2+y^2)^2} -(-1) \frac{2y(x^2-y^2)^2(2y)}{(x^2+y^2)^3}\\
&\ \ \ \ + \frac{2x^2(x^2+y^2)-2x^2y\cdot 2y}{(x^2+y^2)^3}\\
&= \frac{(x^2-y^2)\big( -(x^2-y^2)(x^2+y^2)+2y^2(x^2+y^2)+2y^2(x^2-y^2)\big) }{(x^2+y^2)^3} 
\\
& \ \ \ \ + \frac{2x^2(x^2-y^2)}{(x^2+y^2)^3}\\
&=  \frac{(x^2-y^2)\big( y^4+5 x^2 y^2 + x^4 \big) }{(x^2+y^2)^3} 
=  \frac{\big( x^6 + 9x^4y^2 - 9 x^2y^4 - y^6 \big) }{(x^2+y^2)^3} 
\end{align*}
and similarly,
$$F_{21}(x,y)=-F_{12}(y,x)=
- \frac{(y^2-x^2)\big( y^4+10 x^2 y^2 + x^4 \big) }{(x^2+y^2)^3}=F_{12}(x,y)$$
The mixed partials $F_{12}$ and $F_{21}$ are equal for all $(x,y)\neq (0,0)$, but they are not continuous at $(0,0)$, e.g. 
$F_{12}(x,x)=0\not\to -1$ as $x\to 0$. Therefore the fact that $F_{12}(0,0)\neq F_{21}(0,0)$ does not contradict 
Theorem 2.5.2.

\medskip
\noindent
\textbf{Optional}: Let us try to visualize the above function.  If we make the change of variables to polar coordinates, notice that
$$
f(r \cos \theta, r \sin \theta) = \frac{r^4 \sin \theta \cos \theta (\cos^2 \theta - \sin^2 \theta) }{r^2} = r^2 \sin \theta \cos \theta (\cos^2 \theta - \sin^2 \theta).
$$
Using the trigonometric identities $2 \sin \theta \cos \theta = \sin (2 \theta)$ and $\cos^2 \theta - \sin^2 \theta = \cos (2 \theta)$, this becomes:
$$
f(r \cos \theta, r \sin \theta) = r^2 \frac{\sin 2 \theta \cos 2 \theta}{2} = r^2 \frac{\sin 4 \theta}{4}
$$
This leads to the graph shown below.

Consider also what happens when we try to evaluate the limit 
$$
\lim_{(x,  y) \rightarrow (0,0)} \frac{Q(0,0,  x, y)}{ x y} 
= \lim_{(x,  y) \rightarrow (0,0)} \frac{1}{ x y} \Big(f(x,y)-f(0,y)-f(x,0)+f(0,0)\Big)
$$ 
from Section 2.5. We have $f(0,y)=f(x,0)=f(0,0)=0$, so the above limit is
$$
\lim_{(x,  y) \rightarrow (0,0)} \frac{f(x,y)}{ x y}
=\lim_{(x,  y) \rightarrow (0,0)} \frac{x^2-y^2}{x^2+y^2}.
$$
This limit does not exist (consider the lines $x=0$ and $y=0$). This does not actually prove that the mixed partials are not equal (that's why we did the long calculation above!), but it does provide some intuition as to what might be going wrong.


\begin{figure}[H]\label{24fig1}
\centering
\includegraphics[width=.75\textwidth]{25solnfig1.png}
\caption{A graph of the function $f(x,y)$ from Problem $3$. }
\end{figure}

\end{enumerate}
