TikZ Integral Test Plot – Draw Integral Test Plot with TikZ

tikz-pgf

So I'm doing a report on convergence tests in LaTeX, and would like to produce a diagram demonstrating the integral test for convergence. I am somewhat new to LaTeX, and a total n00b when it comes to Tikz, so any help would be much appreciated.

I am essentially trying to produce something like this:

enter image description here

You might ask why not just use this image, right? Truthfully, I would like to learn TikZ, and would very much appreciate any help in coming up with this plot.

Furthermore, I would like to place inside each bar the corresponding term of the series: a_1, a_2, a_3, …, a_n

Any assistance would be much appreciated!

Best Answer

With tkz-fct and gnuplot

\documentclass[]{scrartcl}
\usepackage{tkz-fct}   

\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid   
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
                     opacity=.2,
                     color=green,
                     line width=1pt,
                     interval=1:8,
                     number=7] 
 \foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
 \node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};  
\end{tikzpicture}   
\end{document} 

enter image description here

Related Question