This animation shows that f(x) is not differentiable at the origin. It shows the secant line through (0,f(0)) and (h,f(h)). If f(x) were differentiable, these secant lines should approach a tangent line as h approaches zero. You can see in this animation that this doesn't happen; the secant line continues to osciallate between y=x and y=-x.

What happens when you replace x with x2?

\begin{displaymath}f(x) = \left\{
x \sin{\left(\frac{1}{x}\ri...
...mbox{ if } x \neq 0\\
0, &\mbox{ if } x=0
\end{array}\right. .\end{displaymath}

This function is continuous at the origin; many books prove this as an application of the Squeeze Theorem. Because $\displaystyle -1 \leq \sin \left( \frac{1}{x} \right) \leq 1,$, it follows that $\displaystyle -\vert x\vert \leq \sin \left( \frac{1}{x} \right) \leq \vert x\vert.$. The Squeeze Theorem says

$\displaystyle \lim_{x \rightarrow 0} -\vert x\vert \leq$ $\displaystyle \lim_{x \rightarrow 0} x \sin \left( \frac{1}{x} \right) \leq \lim_{x \rightarrow 0}\vert x\vert$    
$\displaystyle 0 \leq$ $\displaystyle \lim_{x \rightarrow 0} x \sin \left( \frac{1}{x} \right) \leq 0$    

Hence $ \lim_{x \rightarrow 0} f(x) = f(0) = 0$, so $ f$ is continuous at $ x=0$.

However, $ f(x)$ is not differentiable at $ x=0$. We can verify this using the limit definition of the derivative:

$\displaystyle f'(0)$ $\displaystyle = \lim_{h \rightarrow 0} \frac{f(0+h) - f(0)}{h} = \lim_{h \rightarrow 0} \frac{f(h) - 0}{h}$    
  $\displaystyle = \lim_{h \rightarrow 0} \frac{h \sin \left(\frac{1}{x}\right) }{h} = \lim_{h \rightarrow 0} \frac{\sin \left(\frac{1}{x}\right)}{1}$    
  $\displaystyle = \lim_{x \rightarrow 0} \sin \left(\frac{1}{x}\right)$    
which does not exist. You can see this in the applet on the left. Move your mouse over the picture to the left to start the animation; you may also have to click on the picture before it starts.