Find a continuous function $f:[1,\infty)\to\Bbb R $ such that $f(x) >0 $, $\int_1^\infty f(x)\,dx $ converges and $\int_1^\infty f(x)^2\,dx$ diverges I'm trying to find an example of a continuous function $f:[1,\infty) \to \Bbb R $ such that 
$$f(x) >0 $$
$$\int_{1}^{\infty} f(x) \ dx \ \text{converges and } \int_{1} ^{\infty} f(x)^2 dx \ \text{diverges}.$$

Define $f$ by
$$ f(x) = \mathrm{e}^{-x} + \sum_{n=2}^{\infty} \max\{0, n - n^4|x - n|\}. $$
It is easy to check that
$$ \int_{1}^{\infty} f(x) \, \mathrm{d}x = \int_{1}^{\infty} \mathrm{e}^{-x} \, \mathrm{d}x + \sum_{n=2}^{\infty} \frac{1}{n^2} < \infty. $$
On the other hand,
$$ \int_{1}^{\infty} f(x) \, \mathrm{d}x \geq \sum_{n=2}^{\infty} \int \max\{0, (n - n^4|x - n|)^2 \} \, \mathrm{d}x = \sum_{n=2}^{\infty} \frac{2}{3n} = \infty. $$
The trick is to generate a train of picks. The following graph shows the summation part of $f$:

Picks are constructed to satisfy the following heuristics: Each pick at $x = n$ is of height $\sim n$ and width $\sim n^{-3}$, thus the area is of order $\sim n^{-2}$, when squared, however, its height gets squared and the area becomes of order $\sim n^{-1}$.
