Uniformly convergent on each compact set of $\mathbb R$ but not on $\mathbb R$

As the title says, I am looking for a sequence of function which is uniformly convergent on all compact sets of $$\mathbb R$$ but not on $$\mathbb R$$.

I thought $$f_n(x) = \frac{x}{n}$$ is such a function since for any x in a bounded and closed subset of $$\mathbb R$$. $$\sup(f_n(x)-f(x)) \to 0$$ as $$n\to\infty$$. But since $$\mathbb R$$ is unbounded $$x$$ can get infinitely large thus the function sequence does not uniformly converge on $$\mathbb{R}$$. I wanted to check if my understanding is correct. Thank you

• Yes - good example. – RRL Jan 6 at 8:38
• Check my edits to improve your MathJax skills. – RRL Jan 6 at 8:41
• Here is another example of what you are looking for where it is a little more difficult to prove uniform convergence on the compact intervals. – RRL Jan 6 at 8:52
• @RRL thanks a lot – Kaan Yolsever Jan 6 at 8:59
• Another, more difficult example, is $f_n(x)=\sum_{j=0}^nx^j/j!$ with $f(x)=e^x.$ A theorem in analysis is that if a power series in $x$ converges at every $x$ then the convergence is uniform on any compact set. But $f_n$ is a polynomial and $e^x-p(x)\to \infty$ as $x\to \infty$ for any polynomial $p.$ – DanielWainfleet Jan 30 at 23:21

As explained above in the post, the answer is {$$f_n(x) = \frac{x}{n}; n \geq 1$$ and $$x \in \mathbb R$$}