Give an example of a continuous function $f : [0, ∞) \to [0, ∞)$ such that $\int_{0}^{\infty}f(x)dx$ exists but $f$ is unbounded.
Solution 1:
Building off your idea, but allowing most of the triangles to have zero height (otherwise it will not converge): Choose some divergent series. I'll assume we're dealing with the harmonic series $\sum \frac{1}{n}$. The nth triangle will have base $\frac{1}{n}$.
Now in general, start with $f \equiv 0$, i.e. suppose the general triangle we have is degenerate. But let the $2^n$th slot have a triangle of height $2^{n/2}$.
Or more generically: have some shape that has area $1$ from $0$ to $1$, then some shape that has area $\frac{1}{2}$ from $1$ to $2$, $\frac{1}{4}$ from $2$ to $3$, smoothing as necessary. You can make your function $0$ as much as you want, but you need to make your shapes get taller. You can think of fitting a triangle of height $k$ in the $k$th slot, making the base the necessary width to give area $\frac{1}{2^k}$ in that slot.
You can do many more along these lines.
Solution 2:
Successive triangles is definitely the way to go (for example, choosing the $n$th triangle centered at $n$ with height $n$ and width $1/n^3$ does the job) but mixtures of distributions provide regular examples which are rather natural (to probabilists, at least...). Thus, consider $$ f(x)=\sum_{n\geqslant1}n\,\varphi(n^3(x-n))\cdot\mathbf 1_{x\geqslant0}, $$ where $\varphi$ is any multiple of any regular PDF such that $\varphi(0)\ne0$, for example, $$ \varphi(x)=\mathrm e^{-x^2}. $$ Then $f(n)\geqslant n\varphi(0)$ hence $f$ is unbounded at infinity, the function $f$ is smooth, its support is the full halfline $[0,+\infty)$, and $f$ is integrable since $$ \int_0^\infty f(x)\,\mathrm dx\leqslant\int_\mathbb R\left(\sum_{n\geqslant1}n\,\varphi(n^3(x-n))\right)\,\mathrm dx=\sum_{n\geqslant1}\frac1{n^2}\cdot\int_\mathbb R\varphi(x)\mathrm dx. $$
Solution 3:
Consider the function $$f(x)=x^2\exp(-x^8\sin^2 x)$$
as seen here.
Solution 4:
I had the same desire expressed in dfeuer's comment.
From the answers to Integral of $\cos^{n}(x)$ on $[0,2\pi]$ for $n$ a positive integer and Stirling's approximation we get $$\int_0^{2\pi}\cos^{2n}x\,dx\sim\dfrac{2\sqrt\pi}{\sqrt n}.$$ Using this fact, we can show that $f(x) = x |\cos x|^{x^5}$ is an example. Note that $$\int_0^\infty f(x)\,dx=\sum\limits_{k=0}^\infty\int_{2\pi k}^{2 \pi(k+1)} x|\cos x|^{x^5}\, dx.$$ Because $t\mapsto t$ is increasing and $t\mapsto |\cos x|^t$ is decreasing for each $x$, we can bound each summand as follows:
$$\begin{align*} \int_{2\pi k}^{2 \pi(k+1)} x|\cos x|^{x^5}\, dx & \leq\int_{2\pi k}^{2\pi(k+1)} 2\pi(k+1)|\cos x|^{(2\pi k)^5}\,dx\\ & \leq 2\pi(k+1)\int_{2\pi k}^{2\pi(k+1)}|\cos x|^{2k^5}\,dx\\ &= 2\pi(k+1)\int_{0}^{2\pi}\cos^{2k^5} x\,dx\\ &\sim \dfrac{C}{k^{3/2}}, \end{align*}$$ where the last step follows from the afore mentioned result, and $C$ is a constant independent of $k$. Hence $\int_0^\infty f(x)\,dx<\infty$.