I'm looking for an example of a function with the following properties:
- $f$ is continuous over $\Bbb R$;
- $f\in L^2(\Bbb R)\setminus L^1(\Bbb R)$;
- $f(n)=n$ for all $n\ge1$, $n\in \Bbb N$.
My attempt
We can consider $f=0$ for $x\le0$, my idea was to take advantage of the fact that $(1/n)_{n\ge 1}\in \ell^2\setminus \ell^1$. So I considered the graph of a triangle with height $n$ and base $1/2n^2$, namely for all $n\ge1$ I drew a straight line from the point $(n-1/4n^2,0)$ to $(n,n)$ and then from $(n,n)$ to $(n+1/4n^2,0)$. Outside this graph I thought to put $f(x)=0$. Now, we have $\int |f(x)|\mathrm dx=\sum _{n\ge 1}\frac1n $ so $f\notin L^1$, but when I considered $\int |f(x)|^2\mathrm dx$ I also found a divergent integral. Does anyone have an idea on how to correct $f(x)$ so that $f\in L^2 $?
Suffices to consider $f$ on $[0,\infty)$.
Then, $f+g\in (C[0,\infty)\cap L_2[0,\infty))\setminus L_1[0,\infty)$
For example, consider $a_n=\frac{1}{2n^4}$. On $[n-a_n,n]$ define $g$ linearly so that $g(n-a_n)=0$ and $g(n)=n-\frac1n$, and then linear again on $[n,n+a_n]$ so the $g(n+a_n)=0$. Outside $\bigcup_{n\geq1}[n-a_n,n+a_n]$, set $g=0$. We have that $$\int^\infty_0g=\sum_{n\geq1}a_n(n-\frac1n)<\infty$$ and $$\int^\infty_0g^2=\frac23\sum_n\big(n-\frac1n\big)^2a_n<\infty$$
Then $f+g\in (C([0,\infty))\cap L_2([0,\infty))\setminus L_1([0,\infty)$.