Prove that $f$ has the maximum value on $[-a, a]$. Let $a &gt; 0$.
Let $f(x) := 2 x \sin \frac{1}{x} - \cos \frac{1}{x}$ for $x \in [-a, 0) \cup (0, a]$ and $f(0) := 0$.
Prove that $f$ has the maximum value on $[-a, a]$.
My attempt is the following:
Let $b \in (0, a)$.
Then, $f$ has the maximum value $\max f_{[b, a]}$on $[b, a]$.
Let $-c \in (-a, 0)$.
Then, $f$ has the maximum value $\max f_{[-a, -c]}$ on $[-a, -c]$.
If we can choose $b$ and $-c$ such that if $x \in (-c, b)$, then $f(x) \leq \max\{\max f_{[b, a]}, \max f_{[-a, -c]}\}$, then the proof is done.
Here's an idea for you. In a very small neighborhood of $\;x=0\;$ the function is bounded, since
$\;2x\sin\frac1x\xrightarrow[x\to0]{}0\;$ and $\;\left|\cos\frac1x\right|\le1\;$ , so say $\;|f(x)|\le M_1\;$ and $\;f(x_1)=M_1\;$ for $\;x,\,x_1\in(0,\,\epsilon)\;$ ,  with $\;\epsilon&gt;0\;$ .
Now, at $\;[\epsilon,\,a]\;$, the function $\;f(x)\;$ is continuous and thus, by Weierstrass theorems, it both
is bounded there and attains in that interval its maximum/minimum value, say
$$\;f(x_2)=M_2\ge f(x)\,,\,\,\forall\,x\in[\epsilon,\,a],\,x_2\in[\epsilon,a]\;$$
Finally, just put the above together...and get your proof.
Here is a rough proof.
Fix $a$.
As stated in the comments, we need only consider the interval $[0,a]$.
Let $\alpha = \min \{ \frac{a}{2}, \frac{1}{4\pi} \}.$
We break up the interval into two sets $A=[0,\alpha]$ and $B=[\alpha,a]$.  The set $B$ is compact, and $f(x)$ is continuous and bounded on $B$.  Therefore, $f(x)$ attains a maximum on $B$, call it $f^\star$.  $\forall x  \in A, f^\star \ge f(x),$ so $f^\star$ is the maximum on $[0,a]$ and thus on $[-a,a]$.