Show that exists a continuous function in $E$ that is not bounded
Solution 1:
Either $E$ is not closed or not bounded (or both).
(i) If $E$ is not closed, let $a \in \mathbb R$ be a limit point of $E$ that is not contained in $E$. Then $\displaystyle f:E \to \mathbb R, \quad f(x)= \frac{1}{x-a}$ is an unbounded function.
If, on the other hand, $E$ is not bounded, then $f:E \to \mathbb R, \quad f(x)=x$ is unbounded.
(ii) If $E$ is not closed, choose $a \in \mathbb R$ as above. Then (for example) $f(x)=e^{-(x-a)^2}$ works. (because $e^{-x^2}$ is a "bell" curve, continuous, bounded and only have one maximum)
If $E$ is not bounded from above, $f(x)= \arctan x$ works. If $E$ is not bounded from below, then you can take $f(x)=-\arctan x$.
(iii) $\displaystyle \ f(x)= \frac{1}{x-a}$ works for this case, too.
Solution 2:
Let $E$ be a non-compact subset of $\mathbb{R}$. Then we either have that $E$ is not bounded or $E$ is not closed. If the former holds, note that
- $f(x) = x^2$ is unbounded on $E$.
- $f(x) = \arctan(x)$ is bounded and has no maximum.
- The function from 1. also is not uniformly continuous on $E$.
If $E$ is not closed find $ p \notin E$ in its closure. Play with functions like $f(x) = \frac{1}{|x-p|}$ to construct functions as required.
Solution 3:
As you've noted, a subset of $\mathbb{R}^n$ is compact $\iff$ it is closed and bounded. So if $E$ is not compact, then either it is unbounded, or it is bounded but not closed.
If $E$ is unbounded, something like your $f(x) = \sqrt{x}$ example will work. However, you need to define it piecewise to ensure that it isn't taking invalid input from $E$ (negative numbers). You could also choose any continuous function $g$ on $\mathbb{R}$ such that $\displaystyle \lim_{x \rightarrow - \infty} g(x) = -\infty \text{ and } \lim_{x \rightarrow \infty} g(x) = \infty$ or vice-versa.
Now let's consider when $E$ is bounded but not closed. In this case, we can take advantage of functions like $\displaystyle \frac{1}{x}$. If $E$ were, say, $(0, 1]$, then $f(x) = \displaystyle \frac{1}{x}$ itself would work since $\displaystyle \lim_{x \rightarrow 0^+} f(x) = \infty$. Think about how to generalize this idea to arbitrary bounded-but-not-closed sets.
It is also worth thinking about whether a function $f:E \rightarrow \mathbb{R}$ is necessarily bounded when $E$ is compact.