A-noncompact, Does there always exist a continuous function $f: A \to \mathbb R$ which is bounded but does not assume extreme values? It's well known that if $ A \subset \mathbb R$ is compact then every continuous function $f:A \to \mathbb R$ is bounded and assume extreme values .So the obvious question is:
Given any non compact set $A \subset \mathbb R$ does there always exist a continuous function $f: A \to \mathbb R$ which is bounded but does not assume extreme values?
Any ideas for constructing such function?
 A: A set $A \subset \mathbb{R}$ is compact iff is is bounded and closed. So if a set $A$ is not compact, it must be unbounded or not closed [or both].
If $A$ is not closed, there is at least one point $b \in A^c$ which is a limit point of A. Wlog $b = 0$ and we can consider the function
$$x \mapsto \begin{cases} \sin(\tfrac{1}{x}) (x + 1)^{-1} & x > 0 \\ 0 & x < 0 \end{cases}.$$
If $A$ is closed, it must be unbounded. If it is unbounded towards the top and the bottom, you can consider $x \mapsto \arctan(x)$. If it is not unbounded in both directions, we can wlog assume that it is bounded from below by $0$. Now choose a sequence of points $0 = x_0 < x_1 < x_2 < \ldots$ in $A$ with $x_n \to \infty$ and define the function $g: \mathbb{R}^+ \to [-1, 1]$ by $g(x_i) = (-1)^i$ and linearize it inbetween the $x_i$. The function $x \mapsto \arctan(x) g(x)$ is bounded, but it attains neither its maximum nor minimum.
If $A$ is not closed, it has a limit point $b \in A^c$. Wlog $b = 0$ and there exists a sequence $x_1 > x_2 > \ldots$ in $A$ that converges to $0$. Repeat the construction of $g$ from the unbounded case and consider the function
$$x \mapsto \begin{cases} g(x) (x + 1)^{-1} & x > 0 \\ 0 & x < 0 \end{cases}$$
A: Let $\langle X,d\rangle$ be any non-compact metric space, not necessarily a subspace of $\Bbb R$. Then $X$ is not countably compact, so $X$ has a countably infinite closed discrete subset $D=\{x_n:n\in\Bbb N\}$. Define
$$f:D\to\Bbb R:x_n\mapsto\begin{cases}
1-2^{-n},&\text{if }n\text{ is even}\\
-1+2^{-n},&\text{if }n\text{ is odd}\;.
\end{cases}$$
By the Tietze extension theorem there is a continuous $g:X\to[-1,1]$ such that $g\upharpoonright D=f$. Every metric space is perfectly normal, so $D$ is a zero set, and there is a continuous $\varphi:X\to[0,1]$ such that $\varphi(x)=0$ if and only if $x\in D$. Let $\psi:X\to[0,1]:x\mapsto 1-\varphi(x)$, and let
$$h:X\to\Bbb R:x\mapsto g(x)\psi(x)\;;$$
then $h$ is continuous, $\inf_{x\in X}h(x)=\inf_{x\in D}h(x)=-1$, $\sup_{x\in X}h(x)=\sup_{x\in D}h(x)=1$, and $h[X]\subseteq(-1,1)$, so $h$ attains neither its supremum nor its infimum.
Added: I’ve been asked to say something about how I thought of this construction. That’s a bit difficult, since the pieces were all just lying about in my head and came together without much effort on my part, but I’ll try. I know that countable compactness and compactness are equivalent for metric spaces, so I know right away that a non-compact metric space has a countably infinite closed discrete subset $D$. Because $D$ is discrete, any function from it to $\Bbb R$ will be continuous so I’ll begin by defining a bounded function from $D$ to $\Bbb R$ that doesn’t attain its supremum or infimum. There are may such; I chose to use the function $f$ above, but any other would have worked equally well.
This particular function $f$ takes values in $(-1,1)$ and has $-1$ and $1$ as its unattained extrema. If I can extend $f$ to a continuous $h:X\to(-1,1)$, I'll be done, so what do I know about extending continuous functions? Since $D$ is closed, the Tietze extension theorem applies, and it almost does what I want: it guarantees the existence of a continuous $g:X\to\Bbb R$ with the same extrema as $f$, which implies that $g[X]\subseteq[-1,1]$. Now I just have to make sure not to hit $-1$ or $1$. I can’t do that with $g$ itself, but if I can find a continuous function $\psi:X\to[0,1]$ that is $1$ only on $D$, the product $g\psi$ is guaranteed so map $X\setminus D$ into $(-1,1)$, and I’ll be home free. That requires that $D$ be a zero set in $X$, but I know that that’s true of every closed set in a metric space, so I’m done.
By the way, here’s an example to show that the result does not hold for arbitrary non-compact spaces. The ordinal space $\omega_1$ of all countable ordinals with the order topology is a standard example of a countably compact space that isn’t compact, so in particular it’s not metric. It happens that every continuous $f:\omega_1\to\Bbb R$ is eventually constant: there is an $\alpha_f<\omega_1$ such that $f(\alpha)=f(\alpha_f)$ whenever $\alpha_f\le\alpha<\omega_1$. The set $[0,\alpha_f]$ is a compact subset of $\omega_1$, so $f\upharpoonright[0,\alpha_f]$ attains its extrema, and $f(\alpha)=f(\alpha_f)$ for $\alpha\in\omega_1\setminus[0,\alpha_f]$, so $f$ has the same extrema as $f\upharpoonright[0,\alpha_f]$ and obviously attains them.
A: Either $A$ is not bounded, or $A$ is not closed. Suppose first $A$ is not bounded. Then WLOG there is a sequence $(a_n)$ in $A$ such that $a_1<a_2<\cdots \to \infty.$ Let $\{r_n:n\in \mathbb N\}$ be the rationals in $(0,1).$ Define
$$\tag 1\ f(x) = \begin{cases} f(x) = r_1,& x\in (-\infty,a_1] \\  f(a_n) = r_n ,& n\in \mathbb N \\ f(x)\,\text {  is piecewise linear},&x\in [a_1,\infty)\end{cases}$$
Then $f$ is continuous on $\mathbb R,$ hence on $A.$ We have $f(A)=\{r_n\},$ and this implies that $f$ has neither a minimum nor a maximum on $A.$ as desired.
Now assume $A$ is not closed. Then there is a sequence $(a_n)$ in $A$  such that $a_n\to a\notin A.$ WLOG, $|a_1-a|>|a_2-a| > \cdots \to 0.$
Set $b_n = 1/|a_n-a|.$  Then $b_1<b_2<\cdots \to \infty.$ Now define $f$ relative to $(b_n)$ exactly as we did in $(1).$ Then the function $g=f\circ (1/|x-a|)$ is continuous on $A.$ We again get $g(A)\supset\{r_n\},$ so as before $g$ has neither a minimum nor a maximum on $A.$
A: Let $A \subset \mathbb{R}$ be a noncompact set. Consider the function $f: A \to \mathbb{R}$ defined by $f(x) = \frac{1}{1+e^{-x}}$, the logistic function. Note that $f(x) \in (0,1)$ for all $x\in \mathbb{R}$ and therefore $f$ is bounded regardless of $A$. However, $f$ never assumes its extreme values on any noncompact set.
A: Take $f(x)=\frac{1}{1+x^2}$, $x\in (1,3)$ then clearly $f$ is bounded and $f$ does not assumes any extreme value.
