TITLE: Continuous and bounded function on the unit sphere of a Banach space may not attain its maximum.
QUESTION [5 upvotes]: Give an example of a Banach space and a continuous function $f$ on it such that $f$ is bounded on the unit sphere $S$ but $f$ cannot attain its maximum on S, i.e., $f(S)$ is not closed.

Obviously we need an infinite dimensional Banach space, but I have no idea about the approciate function. I have not found post on MSE which answers my question. Appreciate any help or hint!

REPLY [6 votes]: This is easily achieved with $f$ linear. For instance, we can take $$c_0=\{(x_n):\ \lim_nx_n=0\},\qquad\text{ with }\ \|x\|=\sup\{|x_n|:\ n \in \mathbb{N}\}.
$$
and $$f(x)=\sum_{k=1}^\infty \frac{x_k}{2^k}.
$$
Then $|f(x)|<1$ for all $x$ in the closed unit ball.

REPLY [3 votes]: Let $e_n$ be the standard basis for $\ell^2$ and consider the function $g: \ell^2 \to \mathbb{R}$ given by
\begin{align}
g(x)= \inf_{n \in \mathbb{N}}\,\left( \lVert x- e_n\rVert_{\ell^2(\mathbb{N})} + \frac{1}{n}\right) \, .
\end{align}
On the unit sphere $g$ can be made arbitrarily small but never exactly $0$. Thus, $g$ does not attain its minimum and so $-g$ does not attain its maximum (but it is bounded). $g$ is also continuous and so is $-g$.
Edit: This example can be made more general. Indeed, by replacing $\ell^2$ by a metric space $(X,d)$, $\lVert\cdot\rVert_{\ell^2}$ in the definition of $g$ by $d$, and $e_n$ by any sequence $x_n$ in $X$ which has no accumulation points. Such a sequence exists on the unit sphere of an infinite-dimensional Banach space by Riesz's lemma (see https://en.wikipedia.org/wiki/Riesz%27s_lemma#Some_consequences)