Find $f'(x)$ when $f(x) = x^2 \cos(\frac{1}{x})$ Find $f'(x)$ when
$$
f(x) = \begin{cases}
x^2\cos(\frac{1}{x}),& x \neq 0\\
0, &x = 0\end{cases}$$
Ok, I know the derivative of $f$ and it is $2x\cos(\frac{1}{x})+\sin(\frac{1}{x})$. My question is, am I only supposed to find the derivative here or evaluate this at $0$? I mean what exactly is the reason behind this piecewise function if I don't evaluate this at $0$? Does it make sense? Also, when a question says to find out whether or not $f$ is differentiable for a piecewise function like this, what are we supposed to do, find $f'(x)$ or evaluate at $f'(0)$? I am sorry if these are very elementary level questions. But, I always get confused on terms like these. Any explanation would be much appreciated. Thanks. 
 A: For $x\ne 0$, use usual rules for evaluating derivatives.
For $x=0$, use definition of $f'(0)$:
$$
f'(0)=\lim_{h\to 0}\frac{f(h)-f(0)}{h} =\lim_{h\to 0}\frac{h^2\cos\frac1h-0}{h} = \lim_{h\to0} h\cos\frac1h = 0.
$$
We cannot use formula for $f'(x)$ with $x\ne 0$; $x^2\cos\frac1x$ is undefined at $x=0$.
A: Let  $$
f(x) = \begin{cases}
x^2\cos(\frac{1}{x}),& x \neq 0\\
0, &x = 0\end{cases}$$
As you said in your question, when $x$ is not 0, we have $$f^{'}(x)=2x\cos(\frac{1}{x})+\sin(\frac{1}{x})$$
When $x$ is 0, we must use the limit definition of the derivative. That is, $$f^{'}(x)=\lim_{h\rightarrow0}\dfrac{f(0+h)-f(0)}{h}$$ Since when evaluating this limit, $$0+h\neq 0$$ we have that $$f(0+h)=f(h)=h^2\cos(\frac{1}{h})$$
Therefore, $$f^{'}(0)=\lim_{h\rightarrow 0}h\cos{\dfrac{1}{h}}=0$$
In conclusion, $$f^{'}(x)=$$ \begin{cases}
2x\cos(\frac{1}{x})+\sin(\frac{1}{x}),& x \neq 0\\
0, &x = 0\end{cases}
A: Notice, Using first principle $$f'(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$ $$\implies f'(x)=\lim_{h\to 0}\frac{(x+h)^2\cos\left(\frac{1}{x+h}\right)-x^2\cos\left(\frac{1}{x}\right)}{h}$$ It is clear from given data that function, $f(x)$ changes its definition at $x=0$, hence to check the differentiability of function $f(x)$ at $x=0$, let's calculate the left hand derivative (LHD) & the right hand derivative (RHD) at $x=0$ as follows $$\implies LHD=\lim_{h\to 0^{-}}\frac{(0+h)^2\cos\left(\frac{1}{0+h}\right)-(0)^2\cos\left(\frac{1}{0}\right)}{h}$$ $$=\lim_{h\to 0^{-}}\frac{h^2\cos\left(\frac{1}{h}\right)}{h}=\lim_{h\to 0^{-}}h\cos\left(\frac{1}{h}\right)$$$$=\lim_{h\to 0}(-h)\cos\left(\frac{1}{-h}\right)=-\lim_{h\to 0}h\cos\left(\frac{1}{h}\right)=0$$  $$\implies RHD=\lim_{h\to 0^{+}}\frac{(0+h)^2\cos\left(\frac{1}{0+h}\right)-(0)^2\cos\left(\frac{1}{0}\right)}{h}$$ $$=\lim_{h\to 0^{+}}\frac{h^2\cos\left(\frac{1}{h}\right)}{h}=\lim_{h\to 0^{+}}h\cos\left(\frac{1}{h}\right)$$$$=\lim_{h\to 0}(h)\cos\left(\frac{1}{h}\right)=0$$   Thus, we find that $LHD=RHD=0$, hence function $f(x)$ is differentiable at $x=0$, we have $$f'(0)=0$$
While, $f'(x)$ for $x\neq 0$ can be simply determined using product rule as follows $$f'(x)=\frac{d}{dx}\left(x^2\cos\left(\frac{1}{x}\right)\right)$$ $$=2x\cos\left(\frac{1}{x}\right)-x^2\sin\left(\frac{1}{x}\right)\left(\frac{-1}{x^2}\right)$$ $$=2x\cos\left(\frac{1}{x}\right)+\sin\left(\frac{1}{x}\right)$$
