1

I'm looking for a way to illustrate Trapezoidal rule. I've seen this code to illustrate Riemann sums (Riemann sum with pgfplots -- can't seem to make graph look right) but I don't see how to adapt it.

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
        xtick={0,1,3,5,7,9,11,13,15,17},ytick={0,...,1.5},
        xmax=18,ymax=1.2,ymin=0,xmin=0,
        enlargelimits=true,
        axis lines=middle,
        clip=false,
        domain=0:17,
        axis on top
        ]

\addplot [draw=red, fill=red!10, ybar interval, samples=9, domain=1:17]
        {x^-1}\closedcycle;
\addplot [draw=green, fill=green!10, ybar interval, samples=9, domain=17:1]
        {x^-1}\closedcycle;

\addplot[smooth, thick,domain=1:17,samples=40]{x^-1};

\end{axis}
\end{tikzpicture}
\end{document}

Do you have any suggestion ?

1
  • Yes ! Thank you very much (I didn't had the english word Trapezium :-S)
    – Yoshi
    Commented Jan 28, 2017 at 11:35

0

Browse other questions tagged .