# Testing the differentiability of a piecewise function

I had a multivariable calculus test yesterday and this was one of the questions:

Let $f:\mathbb{R}^2\rightarrow\mathbb{R}$ be defined as follows:

$\displaystyle f(x,y)=\begin{cases} \frac{\sin^2(xy)(e^{y^2+(x^2+y^2)^{3/2}}-1)}{(y^2+(x^2+y^2)^{3/2})^2} & \text{if } x \neq 0\\ 0 & \text{if } x = 0 \end{cases}$

Is $f$ differentiable at the origin?

Here's what I thought: If $f$ is differentiable, then $z=0$ is its tangent plane at the origin since $f_x(0,0)=f_y(0,0)=0$; therefore, if $f$ is differentiable, then:

\begin{align*}&\lim_{(x,y)\to(0,0)}\frac{\sin^2(xy)(e^{y^2+(x^2+y^2)^{3/2}}-1)}{\|(x,y)\|(y^2+(x^2+y^2)^{3/2})^2}=\\ &\lim_{(x,y)\to(0,0)}\frac{\sin^2(xy)}{\|(x,y)\|(y^2+(x^2+y^2)^{3/2})}\frac{e^{y^2+(x^2+y^2)^{3/2}}-1}{y^2+(x^2+y^2)^{3/2}}=0\;.\end{align*}

The limit is indeed $0$ since the second fraction tends to $1$ (using a substitution and applying L'Hôpital's rule) and the first one tends to $0$ because, given $\epsilon>0$, choosing $\delta<\epsilon$: $$\frac{|\sin^2(xy)|}{\|(x,y)\|(y^2+(x^2+y^2)^{3/2})}\leq\frac{x^2y^2}{\|(x,y)\|\,y^2}\leq\frac{|x|\,\,\|(x,y)\|}{\|(x,y)\|}=|x|<\delta<\epsilon$$

However, I plotted the original function using Mathematica and it seems that it's not differentiable, but I can't find the mistake in my reasoning.

-
Condition for Differentiability:If the partial derivatives, $f_x$ and $f_y$, of a function $f$ exist and are continuous on a small disk centered at the point $(a, b)$, then $f$ is differentiable at $(a, b)$. –  pedja Oct 10 '11 at 4:30

This is an ${\bf Edit}$ to my previous answers.

There are two questions here:

1. Is Fernando's reasoning correct?

2. Why are there problems in plotting the function $f$ near $(0,0)$?

Ad 1: As others have remarked the reasoning is correct and leads to the correct result that $f$ is differentiable at $(0,0)$ and has derivative $df(0,0)=0$ there. The cancelling of the factor $y^2$ (which could be $0$) is a little bit fishy, but this can be repaired by noticing that $${y^2\over y^2+r^3}\leq 1\qquad \bigl(r:=\sqrt{x^2+y^2}>0\bigr)\ .$$

Ad 2: There is the possibility that $f$ is differentiable at $0$, but is not continuously differentiable there. Consider in this regard the one-variable example $f(t):=t^2\sin{1\over t}$, $\>f(0):=0$. In this case we have $f'(0)=0$, but $f'(t)= 2t\sin{1\over t}-\cos{1\over t}\not\to 0$ $\ (t\to 0)$.

In order to investigate the continuity of $df$ we are going to simplify our function $f$ considerably (this is already hinted at in Fernando's reasoning):

There are entire functions $z\mapsto g(z)$ and $z\mapsto h(z)$ with $g(0)=h(0)=1$ such that $$\sin^2 z=z^2 \>g(z)\ ,\quad e^z-1=z \>h(z)\qquad\forall z\ .$$

This means that up to a very smooth factor which is approximately $1$ in the neighborhood of $(0,0)$ we can replace $f$ by the following simpler function: $$f(x,y):={x^2y^2\over y^2+r^3} \qquad \bigl(r:=\sqrt{x^2+y^2}>0\bigr)\ .$$ We now look at the partial derivatives of this new $f$. The computation gives $$f_x={r\sin^2\phi\cos\phi\bigl(r-(2+3r)\sin^2\phi\bigr)\over(r+\sin^2\phi)^2}\ ,$$ where we have used the substitution $(x,y):=(r\cos\phi,r\sin\phi)$. As $r>0$ there is a $\tau\in{\mathbb R}$ with $\sin\phi=\tau\sqrt{r}$. It follows that $$|f_x|\leq {r^3\tau^2(1+3 \tau^2)\over r^2(1+\tau^2)^2}\leq C r$$ for some $C>0$ which does not depend on $r$ or $\tau$. Therefore $\lim_{(x,y)\to(0,0)}f_x(x,y)=0=f_x(0,0)$.

A similar computation gives $$f_y={r^2\sin\phi\cos^2\phi (2-3\sin^2\phi)\over(r+\sin^2\phi)^2}\ .$$ We again write $\sin\phi=\tau\sqrt{r}$ and then have $$|f_y|\leq {2r^{5/2}|\tau|\over r^2(1+\tau^2)^2}\leq C\sqrt{r}$$ for some $C>0$ which does not depend on $r$ or $\tau$. Therefore $\lim_{(x,y)\to(0,0)}f_y(x,y)=0=f_y(0,0)$ as well.

All in all we havce proven that the given function $f$ is in fact continuously differentiable in all of ${\mathbb R}^2$. So where are the problems in plotting $f$ coming from? Plotting $f_x$ and $f_y$ as a function of $\phi$ for very small $r>0$ shows sharp peaks (of small amplitude), which indicates that the second derivatives of $f$ are no longer bounded. Maybe the used surface plotting programs don't like that.

-
Shouldn't it be $\bar{g}^2$? And I think you are missing a (second) factor of $r^2 \cos \phi \sin \phi$ in the numerator. (He has $\sin^2 (xy)$, not $\sin (xy)$.) This I think invalidates your argument. –  Craig Oct 13 '11 at 19:12
@Craig: Thank you. I had indeed overseen the ${}^2$ there and now have edited my answer accordingly. –  Christian Blatter Oct 16 '11 at 21:05
You still have a problem. $2|\sin \phi| \sqrt{r} \leq \sin^2 \phi + r$ => $1/(\sin^2 \phi + r) \leq 1/(2|\sin \phi | \sqrt{r})$. So $|\tilde{f}(r,\phi)| \geq (1/2 + o(1)) * r^{3/2} |\sin \phi | \cos^2 \phi$. Not $\leq$. –  Craig Oct 16 '11 at 23:13
@Craig: I think what I wrote is correct. –  Christian Blatter Oct 17 '11 at 7:26
Okay, I'll buy that. –  Craig Oct 17 '11 at 13:21
show 1 more comment

@J.M.: Plot3D[(Sin[x y]^2 (E^(y^2 + (x^2 + y^2)^(3/2)) - 1))/(y^2 + (x^2 + y^2)^(3/2))^2, {x, -0.01, 0.01}, {y, -0.01, 0.01}], under Mathematica 7.0.0 –  Fernando Martin Oct 16 '11 at 4:10
Your reasoning seems ok with me but the plot too : using Mathematica 8.0.1 we clearly see that is is not differentiable on the x-axis except at $(0,0)$ where it is perfectly flat. That is also why you should be careful when using the partial derivatives since here $f_y(x\neq 0,0)$ is not defined as you can easily see on the plot or prove. But your reasoning works well because you directly show that the limit of $\frac{f(x,y)}{\|(x,y)\|}$ is $0$.