Prove $f$ attains its maximum 
Assume $f$ is  a  function  over  real  numbers  such  that $f(x)>0$  for  all $x$.   Suppose  that   $\displaystyle \lim_{x \to \infty} f(x)  =\lim_{x \to -\infty} f(x) = 0.$  Prove $f$ attains its maximum.

Firstly, I believe the question should say continuous function. Then it is easy to see that since we can consider some compact set $[N_1,N_2]$ for the function, the function must have a maximum on this interval, call it $M$. Then the maximum of the function is $\max\{M,0\}$ which exists. 
 A: Firstly, the claim is not correct for a general function $f: \mathbb{R} \to (0 , + \infty)$ where $\lim_{x \to \pm \infty} f(x) = 0$. For a counterexample, consider $f(x) = \begin{cases} 1/ |x| & x \neq 0 \\ 1 & x = 0\end{cases}$, which has no maximum despite satisfying the hypothesis. We must consider continuous functions. For the duration of this answer, we suppose $f$ is continuous, as well as satisfying the hypotheses you stated.-
Let $a = \max \{ f(x) : - 1 \leq x \leq 1 \} > 0 $, which exists by the extreme value theorem. If $\lim_{x \to \pm \infty} f(x) = 0$, then there exists $N \geq 0$ such that if $|x| > N$, then $0  \leq f(x) \leq a / 2$. Now, set $M = \max \{ f(x) : - N \leq x \leq N \}$, which also exists by the extreme value theorem. Since we suppose $N \geq 1$, it follows that $M \geq a$. Now, we note that $$\sup \{ f(x) : x \in \mathbb{R} \} = \max ( \sup \{ f(x) : - N \leq x \leq N \} , \sup \{ f(x) : |x| > N \}) = \max(M, \sup \{ f(x) : |x| > N \}) = M,$$ as $M \geq a \geq a / 2 \geq f(x)$ whenever $|x| > N$. But there exists $x \in [- N, N]$ such that $f(x) = M$, so $M = \sup \{ f(x) : x \in \mathbb{R} \}$ is in fact a maximum.
A: Yes, you're exactly right. As long as you're careful about what you're doing, that is how you do the proof. It's clearly false for non-continuous functions, for a counter example, consider $f(x)=|1/x|$ and $f(0)=0$
A: You are correct that the function MUST be continuous. As a simple counterexample, consider the function
\begin{equation}
    f(x)=\begin{cases}
    \dfrac{1}{(x-2)} & \text{if $x\geq4$}. \\
    \dfrac{-1}{(x-5)} & \text{$x<4$}.
    \end{cases}
   \end{equation}
Then this function never actually attains its maximum. 
So yes, you need $f(x)$ to be continuous. You also need a closed and bounded interval, $[a,b]$. To see a proof, look at the extreme value theorem, https://en.wikipedia.org/wiki/Extreme_value_theorem.
A: Yes, you do need continuity. Then, assuming $f$ is continuous, positive, and $\lim_{\pm\infty} f=0$ here is an outline:


*

*Since $f(x)>0$ for all $x$, then in particular $f(0) > 0$.

*Take $\varepsilon = \frac{f(0)}{2} > 0$. Using that the limits at $\pm\infty$ are $0$, use that with this $\varepsilon$ to argue that there exists $A>0$ such that $0 < f(x) \leq \varepsilon$ outside $[-A,A]$. 

*Apply the fact that every continuous function attains its maximum on a bounded closed interval to the interval $[-A,A]$. There is a maximum for $f$ on $[-A,A]$, call it $M$, attained at some point $x_0 \in[-A,A]$.

*Clearly, the maximum $M$ of $f$ on $[-A,A]$ satisfies $M \geq f(0) > \varepsilon$, so this is also a maximum on $\mathbb{R}$.
