Checking the differentiability of piece-wise defined functions

I'm having trouble checking if a function is differentiable if it has a different definition for $x=0$. Here's an example:

$$f(x)=\begin{cases} 0 &x=0 \\ x\sin(\frac{1}{x}) & x\ne 0 \end{cases}$$

It is continuous over $\mathbb R$ so the contraposition of "If a function is differentiable it is continuous" cannot be used to check the differentiability.
Calculating the left and right differential gives the same value (obviously) if I use the second function, but I'm not sure if I can do that.

I know that $$f'(x) = \sin(\frac{1}{x})-\frac{1}{x}\cos(\frac{1}{x})$$ For all $x\in \mathbb R\setminus \{0\}$.

The function $x \sin (1/x)$ is differentiable away from the trouble point $x=0$, so, let's look just at $0$, using the definition of the derivative: $$\lim_{h\rightarrow 0} \frac{h\sin(1/h)-0}{h-0} = \lim_{h\rightarrow 0} \sin(1/h)$$ Does this limit exist? If yes, it $f$ is differentiable at $0$, otherwise it is not.

• Right, I was confused but I get it now. For some reason I kept thinking that since I was checking differentiability in x=0 that I couldn't use the definition of "f(x) for x =/= 0" in the definition of the derivative. – Joshua Aug 6 '15 at 21:00

The two one-sided derivatives at $x=0$ are:

$\lim\limits_{x\rightarrow0^-}{\dfrac{0-f(x)}{0-x}} = \lim\limits_{x\rightarrow0^-}{\dfrac{-x\sin(\frac{1}{x})}{-x}} = \lim\limits_{x\rightarrow0^-}{\sin(\frac{1}{x})}$

and

$\lim\limits_{x\rightarrow0^+}{\dfrac{f(x)-0}{x-0}} = \lim\limits_{x\rightarrow0^+}{\dfrac{x\sin(\frac{1}{x})}{x}} = \lim\limits_{x\rightarrow0^+}{\sin(\frac{1}{x})}$

However, both of these limits are undefined (since $\sin y$ is undefined as $y\rightarrow\infty$ and as $y\rightarrow-\infty$), so the function is not differentiable at $x=0$.

We have $$f'(0) =\lim_{h\to 0} \frac{h\sin\frac{1}{h} -0}{h}=\lim_{h\to 0}\sin\frac{1}{h}$$ but the last limit does not exist hence $f$ is not differentiable at $x=0.$ For $x\neq 0$ we have $$f'(x) = \sin\frac{1}{x} +x\cos\frac{1}{x} \cdot \left(-\frac{1}{x^2}\right)$$