0

Does anyone know how to make relatively simple diagrams like the images below? Is there a some sort of "template" I could use perhaps? I'd like to code my Calculus notes but I'm not sure how to make the diagrams. It's Left approximation, right approximation, and middle approximation, respectively. Alas...

Example 1

Example 2

Example 3

  • 2
    Show the community that you've tried at least something. It goes a long way rather than just requesting people do-it-for-you. – Werner Nov 18 '14 at 1:24
  • 2
    search for riemann on this site – percusse Nov 18 '14 at 1:41
  • 2
  • I'd highly recommend you spend the afternoon necessary to get a basic handle on PGF/Tikz and PGFPlots (the manuals for both are excellent!). They will draw figures like these in LaTeX, but will also make every figure you draw for the rest of your professional life look neater. – Ubiquitous Nov 18 '14 at 10:29
7

Quick and dirty:

\documentclass[tikz,border=5]{standalone}
\tikzset{declare function={y(\x)=4-\x^2;},
  plot fill/.style={fill=purple!75},
  plot/.style={draw=black!80, thick},
  bar/.style={fill=cyan, draw=white, thick},
  marking/.style={fill=cyan!50!black, draw=cyan!50!black},
  axis/.style={thick, draw=black!65, stealth-stealth}
}
\begin{document}
\begin{tikzpicture}[x=1.5cm, line cap=round, line join=round] 
\foreach \k [count=\z] in {0, 1/4, 1/2}{
\begin{scope}[shift=(0:\z*3)]
\path [plot fill] plot [domain=0:2] (\x,{y(\x)}) -| cycle;
\foreach \x in {0, 1/2, 1, 3/2}
   \path [bar]  (\x,0) |- (\x+1/2, {y(\x+\k)}) |- cycle;
\path [plot]  plot [domain=0:2] (\x,{y(\x)});
\path [axis] (0,4.5) |- (2.5,0);
\foreach \t [count=\x from 0] in {0,\frac{1}{2},1,\frac{3}{2},2}
  \path [axis, -] (\x/2,0) -- ++(0,-3pt) node [below] {$\t$};
\foreach \y in {0,4}
  \path [axis, -] (0,\y) -- ++(-3pt, 0) node [left] {$\y$};
\foreach \x in {0, 1/2, 1, 3/2}
   \path [marking]  (\x+\k, {y(\x+\k)}) circle [radius=1.5pt];
\end{scope}
}
\end{tikzpicture}
\end{document}

enter image description here

4

I can suggest this solution, using my package xpicture. You can add colors, if you want, but for a more sophisticated design use the tikzpicture package.

enter image description here

\documentclass{standalone}
  \usepackage{xpicture}
  \usepackage{ifthen}
\begin{document}
\newqpoly{\f}{4}{0}{-1}               % Define f(x)=4-x^2
\referencesystem(0,0)(2,0)(0,1)       % Change reference system to get a larger x-unit
\setlength{\unitlength}{1cm}
\renewcommand{\xunitdivisions}{2}     % x-Tics at every half unit 
\begin{Picture}(-1,-1)(3,5)
  \cartesianaxes(-0.1,-0.1)(2.1,4.1)
  \printxticlabel{0.5}{1/2}
  \printxticlabel{1.5}{3/2}
  \PlotFunction[20]{\f}{0}{2}         % Plot f(x)
  \COPY{0}{\x}
  \whiledo{\lengthtest{\x pt}<2 pt}{% % Loop to plot Taylor sum
      \COPY{\x}{\xzero}
      \f{\xzero}{\yzero}{\Dyzero}     % yzero=f(xzero)
      \ADD{0.5}{\x}{\x}
      \Polyline(\xzero,0)(\xzero,\yzero)(\x,\yzero)(\x,0)
   }
\end{Picture}

\begin{Picture}(-1,-1)(3,5)
  \cartesianaxes(-0.1,-0.1)(2.1,4.1)
  \printxticlabel{0.5}{1/2}
  \printxticlabel{1.5}{3/2}
  \PlotFunction[20]{\f}{0}{2}
  \COPY{0}{\x}
  \whiledo{\lengthtest{\x pt}<2 pt}{%
      \COPY{\x}{\xzero}
      \ADD{0.5}{\x}{\x}
      \f{\x}{\y}{\Dy}                 % y=f(x)
      \Polyline(\xzero,0)(\xzero,\y)(\x,\y)(\x,0)
  }
  \end{Picture}

  \begin{Picture}(-1,-1)(3,5)
  \cartesianaxes(-0.1,-0.1)(2.1,4.1)
  \printxticlabel{0.5}{1/2}
  \printxticlabel{1.5}{3/2}
  \PlotFunction[20]{\f}{0}{2}
  \COPY{0}{\x}
  \whiledo{\lengthtest{\x pt}<2 pt}{%
      \COPY{\x}{\xzero}
      \ADD{0.5}{\x}{\x}
      \ADD{0.25}{\xzero}{\xm} 
      \f{\xm}{\ym}{\Dym}              % ym=f(xm)      
      \Polyline(\xzero,0)(\xzero,\ym)(\x,\ym)(\x,0)
  }
  \end{Picture}
  \end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.