Derivative of $\frac{1}{2} x + x^2 sin{\frac{1}{x}}$ How do you evaluate the derivative of:
$h(x) = \frac{1}{2} x + x^2 \sin{\frac{1}{x}}$ at $x=0$? It seems that the answer is $\frac{1}{2}$ but I don't know how to take care of the $x^2 \sin{\frac{1}{x}}$.
When you differentiate $h$, you get $h'(x) = \frac{1}{2} + 2x\sin{\frac{1}{x}} - \cos{\frac{1}{x}}$ and at $x=0$, $\cos{\frac{1}{x}}$ is not well defined.
 A: You're right that $x^2 \sin\left(\frac 1 x\right)$ is not defined at $x=0$. But we can get over this discontinuity. 
Think about it like we're approaching $x=0$ from the left and the right. That's like taking:
$$\lim_{x\to 0} \left|x^2 \sin\left(\frac 1 x\right)\right|$$
Here's the big trick: we know that $\sin$ can only take values on the interval $[-1,1]$. So the absolute value of the sine function is always less than or equal to $1$. So $|\sin\left( \frac 1 x \right)| \leq 1$, regardless of the value of $x$. This means that:
$$\left|x^2 \sin\left(\frac 1 x\right)\right| \leq \left|x^2\right|$$
So:
$$\lim_{x \to 0} \left|x^2 \sin\left(\frac 1 x\right)\right| \leq \left|x^2\right|$$
And you know that $\lim_{x \to 0} |x^2| = 0$. So 
$$\lim_{x \to 0} \left|x^2 \sin\left(\frac 1 x\right)\right| \leq 0$$
But the smallest value the absolute value of anything can take is $0$. So that inequality holds only if the limit of the left side is $0$. So we conclude:
$$\lim_{x \to 0} \left|x^2 \sin\left(\frac 1 x\right)\right| = 0$$
Now we use a definition of the derivative at $0$:
$$h'(0) = \lim_{t \to 0} \frac{h(t) - h(0)}{t-0}$$
So what's $h(0)$? From the argument we developed above, we know that $\lim_{x \to 0} \left|x^2 \sin\left(\frac 1 x\right)\right| = 0$, and the other part of $h(0)$ is $\frac 1 2 \cdot 0 = 0$. So $h(0) = 0$.
So 
$$h'(0) = \lim_{t \to 0} \frac{h(t)}{t} = \lim_{t \to 0} \frac{\frac 1 2t + t^2 \sin \left( \frac 1 t \right)}{t} 
= 
\lim_{t \to 0}
\frac{\frac 1 2t}{t} + \frac{t^2 \sin \left( \frac 1 t \right)}{t}
=
\lim_{t \to 0}
\frac 1 2 + t \sin \left( \frac 1 t \right)
$$
And we established previously that $\lim_{t \to 0} t \sin \left( \frac 1 t \right) = 0$. And $\lim_{t \to 0} \frac 1 2 = \frac 1 2$, clearly.
So to conclude, $h'(0) = \frac 1 2$.
A: Let us assume that we complete the definition of $h$ so that it is continuous (i.e., $\lim_{x\to 0}h(x)=0$, so we define $h(0)=0$).
With that, we may compute the derivative using the limit definition:  $\lim_{x\to 0}\frac{h(x)-h(0)}{x-0}=\lim_{x\to 0}\frac{\frac{1}{2}x+x^2\sin\frac{1}{x}}{x}=\lim_{x\to 0}\left(\frac{1}{2}+x\sin\frac{1}{x}\right)=\frac{1}{2}$ (using the squeeze theorem).
This is an interesting example, because $\lim_{x\to 0} h'(x)$ is undefined, and so $h'(x)$ is not a continuous function even though it is defined for all $x$.
