I am doing some practice problems and I need to find a constant $a$ such that
$$ f(x) = \begin{cases} \hfill x\left(1+2x\sin\left(\frac{1}{x}\right)\right) \hfill & \text{ $x \neq 0$} \\ \hfill a \hfill & \text{ $x = 0$} \\ \end{cases} $$
is differentiable everywhere.
To approach this problem, I believe I would need to differentiate $f$ and then take the limit of the derivative at zero. However I'm not sure how that would work since the sine function doesn't have a limit at infinity.
For a function to be differentiable at a point, it is necessary (but not sufficient) that the function be continuous at that point. To answer your question, we must first find a constant $a$ such that your function becomes continuous. Next, we check to see if the function is differentiable at that point.
One possible way to approach the first part (continuity) is to upper bound and lower bound the function and show that the limit of both bounds approach the same constant $a$.
For example, note that $$-1\leq\sin(\frac{1}{x})\leq1$$ From this, we can claim $$x(1-2x)\leq x(1+2x\sin(\frac{1}{x}))\leq x(1+2x)$$
Next we can take the limit as $x$ approaches $0$. For the left hand side, $\lim_{x\to0} x(1-2x)=0$, and for the right hand side, $\lim_{x\to0} x(1+2x)=0$. It follows that $$0\leq \lim_{x\to0}x(1+2x\sin(\frac{1}{x}))\leq 0$$ So your constant $a$ must be equal to $0$.
We can check our results with the following graph. In the figure, the blue plot is $x(1+2x)$. The green plot is x(1-2x). The red plot is $x(1+2x\sin(\frac{1}{x}))$.
To show differentiability, we use the definition of the derivative $$f'(b)=\lim_{h\to0}\frac{f(b+h)-f(b)}{h}$$ plugging in $b=0$ (with $f(0)=0$), we find, $$f'(0)=\lim_{h\to0}\frac{h(1+2h\sin\frac{1}{h})-0}{h}=1$$ Which follows from L'Hopital's rule. You could also solve by rearranging the expression $$\lim_{h\to0}\frac{h(1+2h\sin\frac{1}{h})-0}{h}= \lim_{h\to0}\left(1+\frac{2h^2\sin\frac{1}{h}}{h}\right)$$ $$= 1+\lim_{h\to0}2h\sin(\frac{1}{h})=1+0$$