Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does anyone know where I can find a template that will show Riemann sums converging to the definite integral, dynamically for a beamer presentation?

share|improve this question

2 Answers 2

With PSTricks.

GIF version:

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\def\f(#1){(#1+1)*(#1-1)*(#1-3.5)}

\psset{algebraic,plotpoints=100}

\begin{document}
\multido{\i=1+1}{20}{%
\begin{pspicture}(-1.5,-5.5)(4.5,4.5)
    \psStep[linewidth=0.4pt,linecolor=gray,fillstyle=solid,fillcolor=orange](-0.5,3.0){\i}{\f(x)}
    \psplot[linecolor=blue]{-1.0}{3.5}{\f(x)}
    \psaxes[linecolor=gray]{->}(0,0)(-1.5,-5.5)(4,4)[$x$,0][$y$,90]
\end{pspicture}}
\end{document}

Beamer version:

enter image description here

Read the given comments at the top!

% please compile it with pdflatex -shell-escape main.tex
% Filename for this code is main.tex
\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents*}{integral.tex}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\def\f(#1){(#1+1)*(#1-1)*(#1-3.5)}

\psset{algebraic,plotpoints=100}

\begin{document}
\multido{\i=1+1}{20}{%
\begin{pspicture}(-1.5,-5.5)(4.5,4.5)
    \psStep[linewidth=0.4pt,linecolor=gray,fillstyle=solid,fillcolor=orange](-0.5,3.0){\i}{\f(x)}
    \psplot[linecolor=blue]{-1.0}{3.5}{\f(x)}
    \psaxes[linecolor=gray]{->}(0,0)(-1.5,-5.5)(4,4)[$x$,0][$y$,90]
\end{pspicture}}
\end{document}
\end{filecontents*}

\immediate\write18{latex integral}
\immediate\write18{dvips integral}
\immediate\write18{ps2pdf integral.ps}
% do cleaning here if necessary!

\usepackage{animate}
\begin{document}
\begin{frame}{Definite Integral}
\begin{center}
    \animategraphics[controls,loop,autoplay,scale=0.5]{5}{integral}{}{}
\end{center}
\end{frame}
\end{document}
share|improve this answer
    
If you are using Windows operating system and you want to clean the auxiliary files generated for integral.pdf, you can add \makeatletter\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del integral.\x}}\makeatother below the comment % do cleaning here if necessary!. –  In PSTricks we trust Mar 31 '13 at 7:37

Let me borrow Karl's Students's idea.

Here is a tkz-fct demonstration. I borrowed the integration from Alain Matthes' answer in Tikz-PGF: Draw integral test plot. For this to work, you should have gnuplot installed and compile with pdflatex with -shell-escape enabled.

The .gif version

enter image description here

To create the .gif, you should install imagemagick first. After compiling

pdflatex -shell-escape tikzintegral

run

convert -delay 1 -loop 0 tikzintegral.pdf tikzintegral.gif

tikzintegral.tex:

\documentclass[tikz]{standalone}
\usepackage{tkz-fct}   
\usepackage{multido}

\begin{document}
\multido{\i=2+1}{20}{%
\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=\i]
 %\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} 

For the beamer presentation

\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{filecontents}

\begin{filecontents*}{tikzintegral.tex}
\documentclass[tikz]{standalone}
\usepackage{tkz-fct}   
\usepackage{multido}
\begin{document}
\multido{\i=2+1}{20}{%
\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=\i]
\end{tikzpicture}}
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex --shell-escape tikzintegral}

\usepackage{animate}

\begin{document}
\begin{frame}{Riemann Sum}
    \begin{center}
  \animategraphics[controls,loop,autoplay,scale=0.5]{5}{tikzintegral}{}{}
    \end{center}
\end{frame}
\end{document}

Note here that since you have compiled tikzintegral.tex earlier, if you are saving these codes in the same directory, you can just write:

\documentclass{beamer}
\usetheme{Warsaw}

\usepackage{animate}

\begin{document}
\begin{frame}{Riemann Sum}
    \begin{center}
        \animategraphics[controls,loop,autoplay,scale=0.5]{5}{tikzintegral}{}{}
    \end{center}
\end{frame}
\end{document}

Here is how the first page will look like.

enter image description here

share|improve this answer
3  
Doesn't it make sense to use figure in a frame? –  In PSTricks we trust Mar 31 '13 at 6:49
    
@Karl'sstudents I am used to putting \caption every time. :) –  hpesoj626 Mar 31 '13 at 7:00
    
Oh my ghost. I meant that floating does not make sense in a frame. Try adding \lipsum[1-20] before the figure and adding [allowframebreaks] to the frame; you will see that floating is not useful. –  In PSTricks we trust Mar 31 '13 at 7:11
    
Hmmm... Yes. You are right. I learned something new today, thanks to you. –  hpesoj626 Mar 31 '13 at 7:12
    
One more: You don't need -shell-escape in \immediate\write18{pdflatex -shell-escape tikzintegral} because there is no external application invocation in tikzintegral.tex. :-) –  In PSTricks we trust Mar 31 '13 at 7:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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