Derivative of $f(x) = x^2 \sin(1/x)$ using the derivative definition derivative of $f(x) = x^2 \sin(1/x)$ using the derivative definition
When not using the derivative definition I get $\cos (1/x) + 2x \sin(1/x)$,
which WolframAlpha agrees to.
However when I try solving it using the derivative definition:
$$\lim_ {h\to 0} = \frac{f(x+h) - f(x)}{h} $$
I get:
$$2x \sin \left(\frac{1}{x+h} \right ) + h \sin \left(\frac{1}{x+h}\right)$$
which in return results in, as $h \to 0$:
$$2x \sin (1/x)$$
So what am I doing wrong when using the def of derivatives? 
 A: HINT:
$$\frac{u(x+h)v(x+h)-u(x)v(x)}h=\frac{u(x+h)v(x+h)-u(x)v(x+h)+u(x)v(x+h)-u(x)v(x)}h$$
$$=v(x+h)\frac{u(x+h)-u(x)}h+u(x)\frac{v(x+h)-v(x)}h$$
where $u(x),v(x)$ are functions of $x$
Setting $v(x)=\sin\dfrac1x,$
$$\frac{v(x+h)-v(x)}h=\frac{\sin\dfrac1{x+h}-\sin\dfrac1x}h$$
Using  Prosthaphaeresis Formula,this becomes
$$\frac{2\sin\dfrac{x-(x+h)}{2x(x+h)}\cos\dfrac{x+h+x}{2x(x+h)}}h$$
$$=-2\dfrac{\sin\dfrac h{2x(x+h)}}{\dfrac h{2x(x+h)}}\cdot\frac1{2x(x+h)}\cdot\cos\dfrac{2x+h}{2x(x+h)}$$
A: Typically, this problem is not presented quite how you've described. Instead, for $x \neq 0$ we can compute the derivative of your function with the product and chain rules. For $x=0$ of course your function is not defined, but because $\sin$ is bounded, it can be continuously extended by defining $f(0)=0$.
To find the derivative at zero, you can use the definition. This is less terrible than it would be in the general case, because your difference quotient is
$$\frac{h^2 \sin(1/h) - 0}{h} = h \sin(1/h)$$
for which the limit is straightforward to compute.
A: You're doing wrongly the computation:
\begin{align}
f(x+h)-f(x)&=(x+h)^2\sin\frac{1}{x+h}-x^2\sin\frac{1}{x}\\
&=x^2\left(\sin\frac{1}{x+h}-\sin\frac{1}{x}\right)+2hx\sin\frac{1}{x+h}+h^2\sin\frac{1}{x+h}
\end{align}
When you divide by $h$ you get
$$
\frac{f(x+h)-f(x)}{h}=
\frac{x^2}{h}\left(\sin\frac{1}{x+h}-\sin\frac{1}{x}\right)+2x\sin\frac{1}{x+h}+h\sin\frac{1}{x+h}
$$
and you're left with computing
$$
\lim_{h\to0}\frac{1}{h}\left(\sin\frac{1}{x+h}-\sin\frac{1}{x}\right)
$$
because the second summand above tends to $2x\sin(1/x)$ and the third summand tends to $0$. You'll reinsert $x^2$ later.
Now you can use the identity
$$
\sin\alpha-\sin\beta=2\cos\frac{\alpha+\beta}{2}\sin\frac{\alpha-\beta}{2}
$$
Setting $\alpha=1/(x+h)$ and $\beta=1/x$, we have
$$
\frac{\alpha+\beta}{2}=\frac{1}{2}\left(\frac{1}{x+h}+\frac{1}{x}\right)=
\frac{2x+h}{2x(x+h)}
$$
while
$$
\frac{\alpha-\beta}{2}=\frac{1}{2}\left(\frac{1}{x+h}-\frac{1}{x}\right)=
\frac{-h}{2x(x+h)}
$$
so your limit is
$$
\lim_{h\to0}\frac{2}{h}\cos\frac{2x+h}{2x(x+h)}\sin\frac{-h}{2x(x+h)}
$$
But
$$
\lim_{h\to0}2\cos\frac{2x+h}{2x(x+h)}=2\cos\frac{1}{x}
$$
so we just need to compute
$$
\lim_{h\to0}\frac{1}{h}\sin\frac{-h}{2x(x+h)}
$$
Set $k=-h/(2x(x+h))$, so
$$
2x^2k+2xhk=-h
$$
or $h(2xk+1)=-2x^2k$ that lends
$$
h=-\frac{2x^2k}{2xk+1}
$$
So this transformation is bijective (and bicontinuous) and $h\to0$ implies $k\to0$ so your limit is
$$
\lim_{h\to0}\frac{1}{h}\sin\frac{-h}{2x(x+h)}=
\lim_{k\to0}-\frac{2xk+1}{2x^2k}\sin k=
\lim_{k\to0}-\frac{2xk+1}{2x^2}\frac{\sin k}{k}=-\frac{1}{2x^2}
$$
In the end we get
$$
\lim_{h\to0}\frac{f(x+h)-f(x)}{h}=
x^2\left(-\frac{1}{2x^2}\right)\cos\frac{1}{x}+2x\sin\frac{1}{x}=
-\cos\frac{1}{x}+2x\sin\frac{1}{x}
$$
This assumes, of course, $x\ne0$. If your function is defined by
$$
f(x)=\begin{cases}
x^2\sin\dfrac{1}{x}&\text{for $x\ne0$}\\[1ex]
0&\text{for $x=0$}
\end{cases}
$$
we are left with the derivative at $0$, that is
$$
\lim_{h\to0}\frac{f(h)-f(0)}{h}=
\lim_{h\to0}\frac{1}{h}h^2\sin\frac{1}{h}=
\lim_{h\to0}h\sin\frac{1}{h}=0
$$
with an easy application of the squeeze theorem.
Of course using the chain rule is much simpler.
Now that you know that
$$
f'(x)=\begin{cases}
-\cos\dfrac{1}{x}+2x\sin\dfrac{1}{x}&\text{for $x\ne0$}\\[1ex]
0&\text{for $x=0$}
\end{cases}
$$
it should be easy to verify whether the derivative is continuous at $0$.
A: Problem:
$\frac{d}{dx}\left(x^2\sin\left(\frac{1}{x}\right)\right)$

Use the product rule, $\frac{d}{dx}\left(uv\right)=v\frac{du}{dx}+u\frac{dv}{dx}$, where $u=x^2$ and $v=\sin\left(\frac{1}{x}\right)$:
$=x^2\left(\frac{d}{dx}\left(\sin\left(\frac{1}{x}\right)\right)\right)+\left(\frac{d}{dx}\left(x^2\right)\right)\sin\left(\frac{1}{x}\right)$

Using the chain rule, $\frac{d}{dx}(\sin(\frac{1}{x}))=\frac{d\sin\left(u\right)}{du}\frac{du}{dx}$, where $u=\frac{1}{x}$ and $\frac{d}{du}(\sin(u))=\cos(u)$:
$=\left(\frac{d}{dx}\left(x^2\right)\right)\sin\left(\frac{1}{x}\right)+\boxed{\cos\left(\frac{1}{x}\right)\left(\frac{d}{dx}\left(\frac{1}{x}\right)\right)}x^2$

Use the power rule, $\frac{d}{dx}\left(x^n\right)=nx^{n-1}$, where $n=-1$: $\frac{d}{dx}\left(\frac{1}{x}\right)=\frac{d}{dx}\left(x^{-1}\right)=-x^{-2}$:
$=\left(\frac{d}{dx}\left(x^2\right)\right)\sin\left(\frac{1}{x}\right)+\boxed{-\frac{1}{x^2}}x^2\cos\left(\frac{1}{x}\right)$

Simplify the expression:
$=-\cos\left(\frac{1}{x}\right)+\left(\frac{d}{dx}\left(x^2\right)\right)\sin\left(\frac{1}{x}\right)$

Use the power rule, $\frac{d}{dx}\left(x^n\right)=nx^{n-1}$, where $n=2$: $\frac{d}{dx}\left(x^2\right)=2x$:

Answer:
  $$=-\cos\left(\frac{1}{x}\right)+\boxed{2x}\sin\left(\frac{1}{x}\right)$$

