I have seen counterexamples of continuous functions $f$ such that they are in $L^2(\mathbb{R})$ and $|f(x)|\rightarrow \neq 0$ as $|x|\rightarrow \infty$. Now I was wondering what would happen if we have a smooth function . Will we have in this case that $|f(x)|\rightarrow 0$ as $|x|\rightarrow \infty$?
Any help is appreciated, Thanks in advance.
Let $u$ be a fixed smooth bump function supported on $[0,1]$. Then you can consider $$ f(x) = \begin{cases} 0 & \text{when }x<0 \\ u(n^2(x-n)) & \text{when } n\le x<n+1 \end{cases} $$ This function is clearly smooth and $L^2$: $$ \int_{-\infty}^\infty f^2(x)dx = \sum_{n=1}^{\infty} \frac{1}{n^2} \int_0^1u^2(x)dx = \frac{\pi^2}{6}\int_0^1u^2(x)dx $$
However $f(x)$ has no limit as $x\to\infty$, since the value keeps oscillating between $0$ and $\max u$.
You can even find analytic examples, such as $$ f(x) = e^{-(x^2\sin x)^2} $$ though it takes a bit more footwork to convince oneself that that is $L^2$.