Let $f:\mathbb{R}\rightarrow\mathbb{R}$ be given by $$f(x)=\begin{cases}x\sin(\frac{1}{x}), \quad x\neq 0\\ 0, \quad x=0 \end{cases}$$ Show that $f$ has a local maximum and a local minimum in $(-\frac{1}{m},\frac{1}{m})$ for every positive integer $m\geq 1$.
My idea was to consider the set $A=[-\frac{1}{m},\frac{1}{m}]$. Since $A$ is compact, and $f$ is continuous on $A$, by the extreme value theorem, $f$ attains a maximum and a minimum in $A$. Then I wanted to show by Rolle's theorem that the extremum values cannot be attained at the end-points. This is evident if $f$ is differentiable on $(-\frac{1}{m},\frac{1}{m})$ but I can show that for $x\neq 0$, $f$ is differentiable since $f(x)=a(x)\cdot b(c(x))$ where $a(x)=x,b(x)=\sin x, c(x) = 1/x$ which are all "well-behaved" away from $0$ and hence $f$ is differentiable by application of the product rule and chain rule. The problem arises at $x=0$ where $f$ is not differentiable. So this approach fails.
Any hints on an alternative method to prove this?
The derivative of $f$ (away from $x=0$, where $f$ is not differentiable) is
$$f'(x) = \sin \left( \frac 1x\right) - \frac 1x \cos \left( \frac 1x\right).$$
Thus $f'(x) = 0$ if
$$ \tan \left( \frac 1x \right) = \frac 1x.$$
Then it is easy to see graphically that there are infinitely many critical point (say, let $y = 1/x$, then you are looking for the intersection of the two graphs $z = \tan y$ and $z=y$).
Rigorously that can be proved by intermediate value theorem: in the interval
$$ 2n\pi < y < 2n \pi + \frac \pi 2,\ \ n\neq 0,$$
the function $g = \tan y - y$ has
$$ g(2n\pi ) = -2n\pi <0, \ \ \lim_{y \to 2n\pi + \frac \pi 2} g(y) = +\infty,$$
thus there is $y^+_n$ in the interval $(2n\pi, 2n\pi + \pi/2)$ so that $g(y_n^+) = 0$. So there is a sequence $\{x_n^+ = 1/y_n^+\}$ so that $x_n^+ \to 0$ and $f'(x_n^+) = 0$.
The second derivative of $f$ is
$$f''(x) = -\frac{1}{x^3} \sin \left( \frac 1x\right).$$
Since $y_n^+ = 1/x_n^+ \in (2n\pi, 2n\pi + \pi/2)$, $\cos (y_n^+) >0$ and thus
$$ f''(x_n^+) <0, \ \ \ \forall n.$$
Hence $x_n^+ $ is a local maximum.
As a result, for all $m>0$, one can find $n$ large enough so that $|x_n^+|< 1/m$, hence there is a local maximum in $(-1/m, 1/m)$.
One can similarly find a sequence of local minimum tending to zero, by examining $g$ in the intervals $((2n + 1)\pi, (2n+1) \pi + \pi/2)$. I will leave the details to you.