A continuous function on a half-closed interval I have this question:
If $f:[0,\infty) \to \mathbb R$ is continuous and $$\lim _{x\to \infty }\:f\left(x\right)\:=\:L$$ then $f$ has a maximum or a minimum on the interval.
I've already proved that this function (on the same terms and limit) is bounded on the interval.
I understand why this is true - because the limit can be below the function and then it won't have minimum or above the function and then it wont have maximum. 
I don't know how to write it formally.
 A: If $f$ is not a constant function there exists $a \geqslant 0$ such that $f(a) \neq L$. Let $M=f(a)$ and let us suppose that $M>L$ (an analoguous reasoning would apply if $M<L)$.
We want to prove that $f$ has a maximum.
Let $\epsilon=\frac{M-L}{2}>0$.
Since $\lim_{x\to \infty } f(x)=L$ you have the existence of $A > 0$ such that for all $x \geqslant A$, $f(x) \in [L-\epsilon, L+\epsilon]$. Then for all $x \geqslant A$, $f(x) \leqslant L+\frac{M-L}{2} < L + M -L = M$.
On $[0, A]$, $f$ is continuous then has a maximum $B \geqslant M$ (because $a \in [0, A]$). Consequently $f$ has a maximum on $[0, \infty)$.
If $f$ is constant, it should be equal to $L$ and $f$ has a maximum and a minimum.
If $M<L$ we would have proven that $f$ has a minimum on $[0, \infty)$. Note moreover that if there exists $a,\ b$ such that $f(a) \geqslant L$ and $f(b) \leqslant L$ then $f$ has a maximum and a minimum on $[0, \infty)$.
A: Take $\phi\colon[0,1) \to [0,+\infty)$, $\phi(x)=1/(1-x)-1$ (any continuous increasing unbounded function would work) and define
the function $g\colon [0,1]\to \mathbb R$ by
$$
  g(t) = \begin{cases}
   f(\phi(t)) & \text{if $t\in[0,1)$}\\
   L & \text{if $t=1$}
  \end{cases}.
$$
Clearly $g$ is continuous on $[0,1]$ hence by Weierstrass theorem has minimum and maximum. Either the minimum or the maximum is not achieved in $t=1$. Being $\phi$ increasing the corresponding point $\phi(t)$ is a minimum or maximum for $g$.
