Does anybody know a function $f$ that is continuous on $[0, \infty)$, so that $\int_{0}^{\infty} f(x)dx$ converges but $\int_{0}^{\infty} f(x)^2dx$ diverges? Thanks
EDIT: Sorry! I meant that $f$ is also continuous there.
Does anybody know a function $f$ that is continuous on $[0, \infty)$, so that $\int_{0}^{\infty} f(x)dx$ converges but $\int_{0}^{\infty} f(x)^2dx$ diverges? Thanks
EDIT: Sorry! I meant that $f$ is also continuous there.
A simple function with this property is $f(x)=\sin(x)/\sqrt{x}$, whose graph looks like so:
A simple appeal to the alternating series test shows that the integral converges, as $$\int_0^{\infty} f(x) dx = \sum_{k=0}^{\infty}\int_{k\pi}^{(k+1)\pi} f(x) dx.$$
To see that the integral of $f(x)^2$ diverges, let's take a look at a graph of $f(x)^2$:
Each dashed rectangle that you see lives over an interval of the form $[k\,\pi+\pi/6,k\,\pi+5\pi/6]$, which has length $4\pi/6$ or $2\pi/3$. The height of each rectangle is $$\frac{\sin^2(k\,\pi+5\pi/6)}{k\,\pi+5\pi/6} = \frac{1/4}{k\,\pi+5\pi/6}.$$
Thus, the sum total of the areas of those rectangles is $$\sum_{k=0}^{\infty} \frac{\pi/6}{k\,\pi+5\pi/6} = \infty.$$
As those rectangles lie wholly under the graph of the squared function, the improper integral must diverge as well.
Notice that the following integral converges, and to the particular value.
$$\int_0^\infty\sin(x^2+2x+1)dx\approx3.16389$$
On the other hand,
$$\int_0^\infty\sin^2(x^2+2x+1)dx$$
does not converge.
We can find a continuous function $f$ with values in $[0, \infty)$ that satisfies the condition. Indeed, consider a function that:
on every interval of $[n,n+1]$ takes the value $n$ on an interval of length $1/n^3$ centered at $n+\frac{1}{2}$ and decreases to $0$ outside the central subinterval of length $\frac{2}{n^3}$. Then
$$\int_0^{\infty} f(x) dx \le 2 \sum_{n=1}^{\infty} \frac{n}{n^3} < \infty$$ but $$\int_0^{\infty)} f^2(x) dx \ge \sum_{n=1}^{\infty} \frac{n^2}{n^3} = \infty$$
In a similar way (say with subintervals of length $\frac{1}{n^2 \log^2 n}$, $n\ge 2$, and values $n$) we find $f\ge 0$ continuous on $[0, \infty)$ such that $\int_{0}^\infty f(x) d x < \infty$, but $\int_0^{\infty} f^s(x) dx = \infty$ for all $s> 1$.
Take the function $f$ whose restriction to $[n,n+1[$ is the constant function $(-1)^{n+1}{1\over\sqrt {n+1}}$. It converges, but not $f^2$.
If you want $f$ to be continue, you can find $f_n:[n,n+1]$ such that $f_n(n)=f_{n+1}(n+1)=0$, $f_n\geq 0$ if $n$ is odd, $f_n\leq 0$ if $n$ is even and $\int_n^{n+1}f(x)dx=(-1)^{n+1}{1\over\sqrt {n+1}}$ by using bump functions.
Can someone tell me what's wrong with the following? From @MarkMcClure's comment, there must be something wrong. It could must be a subtle point of improper Riemann integrals.
If $f$ is continuous on $[0,\infty)$ and $\int_0^\infty f < \infty$, then $f(x) \to 0$ as $x \to \infty$, so there's some sufficiently large $R$ such that $f(x) \leq 1$ for $x > R$. Then $\int_R^\infty f^2 \leq \int_R^\infty f$; in particular, $\int_R^\infty f^2 < \infty$ (it exists). Since $f^2$ is the composition of continuous functions and $[0,R]$ is compact, $\int_0^R f^2$ also exists. Hence $\int_0^\infty f^2$ doesn't diverge.