Give an example of a function that is bounded and continuous on the interval [0, 1) but not uniformly continuous on this interval.

Here's some intuition:

The Heine-Cantor theorem tells us that any function between two metric spaces that is continuous on a compact set is also uniformly continuous on that set (see here for discussion). Next, if $f:X \rightarrow Y$ is a uniformly continuous function, it is easy to show that the restriction of $f$ to any subset of $X$ is itself uniformly continuous*. Therefore, because $[0,1]$ is compact, the functions $[0,1) \to \mathbb{R}$ that are continuous but not uniformly continuous are those functions that cannot be extended to $[0,1]$ in a continuous fashion.

For example, consider the function $f:[0,1) \to \mathbb{R}$ defined such that $f(x) = x$. We can extend $f$ to $[0,1]$ by defining $f(1) = 1$, and this extension is a continuous function over a compact set (hence it is uniformly continuous). So the restriction of this extension to $[0,1)$—i.e. the original function—is necessarily also uniformly continuous per (*) above.

How can we find a continuous function on $[0,1)$ that cannot be continuously extended to $[0,1]$? There are two ways:

$\qquad \bullet \quad$ Construct $f$ so that $\displaystyle \lim_{x \rightarrow 1} f(x) = \pm \infty$

$\qquad \bullet \quad$ Construct $f$ so that $\displaystyle \lim_{x \to 1} f(x)$ does not exist

Note that if $\displaystyle \lim_{x \to 1} f(x)$ exists, taking $f(1)$ to be that limit yields a continuous extension. Indeed, $\displaystyle \lim_{x \to c} f(x) = f(c)$ is literally one of the definitions for continuity at the point $x=c$.

The first bullet is ruled out by the stipulation that $f$ be bounded, so moving on to the second bullet, we need to make sure $\displaystyle \lim_{x \to 1} f(x)$ does not exist. One way of doing this (the only way I believe) is to have $f$ oscillate infinitely rapidly with non-vanishing amplitude as $x \to 1$. It looks like this is what you were trying to exploit, and what José Carlos Santos did (+1) in his answer (see graph below): $\displaystyle f(x) = \cos \left(\frac{1}{1-x} \right)$.

Generalizing his epsilon-delta argument, you can see that this condition is not only necessary, but also sufficient.

$\qquad \qquad \qquad \qquad$ enter image description here


Take $f(x)=\cos\left(\frac1{1-x}\right)$. If it was uniformly continuous, then, for each $\varepsilon>0$, there would be some $\delta>0$ such that $\lvert x-y\rvert<\delta\implies\bigl\lvert f(x)-f(y)\bigr\rvert<\varepsilon$. But this is not true. Take $\varepsilon=1$. Since there are values of $x$ arbitrarily close to $1$ such that $f(x)=1$ and there are values of $x$ arbitrarily close to $1$ such that $f(x)=-1$, then, no matter how small $\delta$ is, you will always be able to find examples of numbers $x,y\in[0,1)$ such that $\lvert x-y\rvert<\delta$ and that $\bigl\lvert f(x)-f(y)\bigr\rvert=2>\varepsilon$