Show that if $f(0)=\displaystyle\lim_{x \rightarrow \infty}f(x)=0$ and $f$ is continuous then $f$ has a maximum in the interval $[0, \infty)$. Show that if $$f(0)=\displaystyle\lim_{x \to \infty}f(x)=0$$ and $f$ is continuous then $f$ has a maximum in the interval $[0, \infty)$.
It just seems so obvious! Yet I'm stuck... any hints would be much appreciated. 
 A: If $f$ is equal to $0$ everywhere, then the statement is trivial, so let's assume $f$ is not $0$ everywhere.
If $f(x)\leq 0$ for all $x$, then $f(0)$ is the maximum, so let's now see what happens if $f(x)>0$ for at least some $x$.
We then know there exists some $x_0>0$ for which $f(x_0)> 0$. Now, you can find such a value $M$ that for all $x>M$, you have $f(x) < \frac{f(x_0)}{2}$ (why?). You can also be sure that $f$ has a maximum on $[0,M]$ (why?), and that the maximum value on $[0,M]$ is actually the maximum on $[0,\infty)$ (why?)
A: If $f \leq 0$, then clearly the maximum exists and is attained at $0$. Suppose from now on there exists $x_0$ such that $f(x_0) > 0$, and let $\varepsilon = f(x_0)$. By definition of the limit, there exists $A$ such that $\forall x \geq A$, $f(x) \leq \frac{\varepsilon}{2}$. 
But, by continuity of $f$, it is bounded on $[0,A]$, and reaches a maximum there. Let $\beta$ be this maximum, reached at $x^\ast \in [0,A]$. Then, $\beta \geq \varepsilon$ (why?), and thus it is also the maximum of $f$ on $[0,\infty)$.
A: Hint: Since $\lim_{x\to \infty} f(x) = M$ exists, for any $\epsilon > 0, \exists R > 0$ such that
$$
|f(x) - M| < \epsilon \quad\forall x \geq R
$$
Hence,
$$
|f(x)| \leq M+\epsilon \quad\forall x \in [R,\infty)
$$
Now what happens on $[0,R]$?
Now since $M = 0$, you can choose $\epsilon$ carefully so that the max is attained.
