Counter example for improper integrals I'm trying to find a function $f(x)$ over $[1,\infty)$ such that $f(x)$ is non-negative and continuous.
Also, $\int_{1}^{\infty}f(x)dx$ has to converge, while $\int_{1}^{\infty}(f(x))^2dx$ diverges.
 I'm terrible at finding counter-examples, where do we start?
 I do know that if $f(x)$ was monotonically decreasing, $(f(x))^2$ would definitely converge. So we're trying to find a function $f(x)$ such that $f(x)$ is not  monotonically decreasing, although I can't think of any functions.


How do you approach this kind of questions? I think I just don't know enough functions to solve this quickly. Any help appreciated.
 A: HINT: The idea is to make the graph have higher and higher triangular peaks that get narrower and narrower. We want to try to do this so that the total area of the peaks is finite, but squaring the function leads to peaks whose total area is infinite.
Make $f(x)=0$ except in intervals $(n-\epsilon_n,n+\epsilon)$ around integers $n\ge 2$. Make $f(n)=n$ for integers $n\ge 2$. On the interval $[n-\epsilon_n]$ the function should be linear and increasing, and on the interval $[n,n+\epsilon_n]$ it should be linear and decreasing. Thus, the graph mostly runs along the $x$-axis but has triangular bumps at each integer $n\ge 2$. The area under the curve is then
$$\sum_{n\ge 2}n\epsilon_n\;,\tag{1}$$
and the area under the squared curve is is easily worked out by elementary calculus. Now choose the numbers $\epsilon_n$ so that the sum $(1)$ converges, but the area under the squared curve is infinite.
A: Take a continuous function which connects with segments the points:   $(0,0)$ and $(n-1/n^3,0)$, $(n,n)$, $(n+1/n^3,0)$ for any integer $n\geq 2$. Hence you have that 
$$\int_{1}^{\infty}f(x)dx=\sum_{n\geq 2}\frac{n\cdot2/n^3}{2}=\sum_{n\geq 2}\frac{1}{n^2}<+\infty$$ 
because it is the sum of the areas of the triangles with height $n$ and base length $2/n^3$. 
On the other hand it is easy to see that 
$$\begin{align*}
\int_{1}^{\infty}f(x)^2dx&=\sum_{n\geq 2}2\int_{n-1/n^3}^{n}\left[n^4\left(x-\left(n-\frac{1}{n^3}\right)\right)\right]^2dx\\
&=\sum_{n\geq 2}2n^8\int_{0}^{1/n^3}t^2dt=\frac{2}{3}\sum_{n\geq 2}\frac{1}{n}=+\infty
\end{align*}$$
