Let $f:\mathbb{R}\to\mathbb{R}, f(x)=\begin{cases}x^m \cdot \sin\left(\frac{1}{x}\right),\ x > 0 \\\ 0,\ x \leq 0\end{cases}$. Determine $m\in\mathbb{R}$ if $f$ is derivable once, but not twice on $\mathbb{R}$.
According to the book I'm working from, the answer should be $m\in(1,3]$, but that does not seem correct, and my answer is different. Here's what I tried:
If $f$ is differentiable, that means $f$ is continuous. This is obvious, as the limit towards $0$ coming from above is indeed $0$, just like the limit below and the value of the function in $0$. Then: $$f'(x)=\begin{cases}mx^{m-1}\sin\left(\frac{1}{x}\right)+x^m\cdot \cos\left(\frac{1}{x}\right)\cdot\frac{-1}{x^2}, \ x>0 \\\ 0, \ x<0\end{cases} \iff \\\ \iff f'(x)=\begin{cases}x^{m-2}(mx\sin\left(\frac{1}{x}\right)-\cos\left(\frac{1}{x}\right)), \ x>0 \\\ 0, \ x<0\end{cases} $$ For $f$ to be differentiable once, this means $f'(x) \in\mathbb{R}$ (that is, $f'(x)$ is finite, otherwise it has derivatives but is not differentiable, that is a distinction we learned to make in class BUT I suspect here I might be wrong) and the left and right limits of $f'(0)$ exist and are equal. $$\lim_{x\nearrow 0} f'(x)= 0 \text{ and } \lim_{x\searrow 0}f'(x) = \lim_{x\searrow 0} x^{m-2}\left(mx\sin\left(\frac{1}{x}\right)-\cos\left(\frac{1}{x}\right)\right)$$
For the second limit to be equal to $0$, $m > 2$. Then, for $x>0$ $$f''(x)=(m-2)x^{m-3}\left(mx\sin\left(\frac{1}{x}\right)-\cos\left(\frac{1}{x}\right)\right)+x^{m-2}\left(m\left(\sin\left(\frac{1}{x}\right)-\frac{1}{x}\cos\left(\frac{1}{x}\right)\right)-\frac{1}{x^2}\cdot\sin\left(\frac{1}{x}\right)\right)$$ and $$\lim_{x\searrow0}f''(x) =\lim_{x\searrow0} -(m-2)x^{m-3}\cos\left(\frac{1}{x}\right)-mx^{m-3}\cos\left(\frac{1}{x}\right)-x^{m-4}\sin\left(\frac{1}{x}\right)$$
For $f$ to not be differentiable a second time, that means that either the limit of the second derivative in $0$ goes to $\pm$infinity or the value of the limit above $0$ isn't equal to $0$. The second case isn't applicable here due to the trig functions, as they oscillate infinitely, so the only extra condition is $x<4$. Thus, $x\in(2,4)$.
However, as I mentioned, my workbook says the answer is $x\in(1,3]$. Graphing the function and its two derivatives with Desmos according to my values seems to be correct considering my conditions (that the first derivative is always finite, and the second isn't finite in $0$, for it to not be differentiable), so I'm totally lost between me being correct and the book being wrong or vice versa. Any help or hints about this conundrum are much appreciated! As well, if my method it completely incorrect, I would highly appreciate shedding some light on the right approach!
$f$ is smooth on $\Bbb R^*$ and at $0^-.$ The only problem is at $0^+.$
So, $f$ is differentiable once but not twice iff $1<m\le3.$
Your mistake seems to pretend that $f$ is differentiable once at $0$ iff $f'$ has a limit at $0,$ and twice iff $f''$ has a limit at $0.$