8

I know from the pstricks-add manual, that I can get a vizualization of upper and lower sums for the Riemannian integral like this:

\documentclass{standalone}

\usepackage{auto-pst-pdf}
\usepackage{pst-func}

\psset{xunit=0.7cm,yunit=0.7cm}
\psset{algebraic,plotpoints=100}
\begin{document}
\def\f(x){-1*(-x-1)*(x-5)*x/30*(x-7)}

      \begin{pspicture}(0,-2.5)(7.7,4) \psStep[StepType=infimum,linewidth=1.5pt](0,7){15}{\f(x)}
        \psplot[linewidth=1.5pt]{0}{7.7}{\f(x)}
        \psaxes[Dy=2]{->}(0,0)(0,-2)(7.7,4.7)[$x$,0][$y$,90]
      \end{pspicture}
      \begin{pspicture}(0,-2.5)(7.7,4) \psStep[StepType=supremum,linewidth=1.5pt](0,7){15}{\f(x)}
        \psplot[linewidth=1.5pt]{0}{7.7}{\f(x)}
        \psaxes[Dy=2]{->}(0,0)(0,-2)(7.7,4.7)[$x$,0][$y$,90]
      \end{pspicture}

\end{document}

with the following output:

enter image description here

But how can I get the picture without the vertical lines. I.e. how can I get automatically just a plot of the approximating step-function?

The solution should be compatible with the picture above since I also want to be able to add the vertical lines in a different color in a second picture.

1
  • By the way the macro \def\f(x){-1*(-x-1)*(x-5)*x/30*(x-7)} seems to have a useless (x). It should be \def\f(#1){-1*(-#1-1)*(#1-5)*#1/30*(#1-7)} to be useful. Nov 13, 2013 at 19:41

2 Answers 2

4

needs the latest pstricks-add.tex from http://texnik.dante.de/tex/generic/pstricks-add/

\documentclass{standalone}
\usepackage{pstricks-add}

\psset{xunit=0.7cm,yunit=0.7cm}
\psset{algebraic,plotpoints=100}
\begin{document}
\def\f(x){-1*(-x-1)*(x-5)*x/30*(x-7)}

\psset{noVerticalLines}%%%%%%%%%%%%%%

\begin{pspicture}(-1,-2.5)(8,5) 
   \psStep[StepType=infimum,linewidth=1.5pt,linecolor=red](0,7){15}{\f(x)}
   \psplot[linewidth=1.5pt]{0}{7.7}{\f(x)}
   \psaxes[Dy=2]{->}(0,0)(0,-2)(7.7,4.7)[$x$,0][$y$,90]
\end{pspicture}
\qquad
\begin{pspicture}(0,-2.5)(7.7,4) 
   \psStep[StepType=supremum,linewidth=1.5pt,linecolor=red](0,7){15}{\f(x)}
   \psplot[linewidth=1.5pt]{0}{7.7}{\f(x)}
   \psaxes[Dy=2]{->}(0,0)(0,-2)(7.7,4.7)[$x$,0][$y$,90]
\end{pspicture}

\end{document}

enter image description here

4
  • Thanks! Does this allow to use both in one picture, for example the step function in red and the Riemann rectangles a layer below this with gray dashed vertical lines or something like that?
    – student
    Nov 13, 2013 at 18:53
  • 1
    sure, use noVerticalLines in the macro itself, then it is only local. And use \psStep twice
    – user2478
    Nov 13, 2013 at 18:55
  • Where do I find this option? ;-) Nov 14, 2013 at 8:39
  • @MarcoDaniel: as I wrote, you need the development version from texnik.dante.de
    – user2478
    Nov 14, 2013 at 11:09
8

Just a cleaner code.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot,pst-node}

\psset{algebraic}
\def\f(#1){(#1+1)*(#1-5)*#1/35*(#1-7)}

\def\Left#1{%
\begin{pspicture}(-3,-1)(6,4)
    \psplot{-2}{5}{\f(x)}   
    \psset{linecolor=red,showpoints}
    \curvepnodes[plotpoints=#1]{-1.8}{4.8}{t|\f(t)}{A}
    \multido{\il=0+1,\ir=1+1}{\Anodecount}{\psline(A\il)(A\ir|A\il)}
    \rput[t](1.5,4){Left}
\end{pspicture}}

\def\Right#1{%
\begin{pspicture}(-3,-1)(6,4)
    \psplot{-2}{5}{\f(x)}
    \psset{linecolor=green,showpoints}
    \curvepnodes[plotpoints=#1]{-1.8}{4.8}{t|\f(t)}{A}
    \multido{\il=0+1,\ir=1+1}{\Anodecount}{\psline(A\il|A\ir)(A\ir)}
    \rput[t](1.5,4){Right}
\end{pspicture}}

\def\Center#1{%
\begin{pspicture}(-3,-1)(6,4)
    \psplot{-2}{5}{\f(x)}
    \psset{linecolor=blue,showpoints}
    \curvepnodes[plotpoints=#1]{-1.8}{4.8}{t|\f(t)}{A}
    %\multido{\il=0+1,\ir=1+1}{\Anodecount}{\psxline(A\il){.5(A\il)-.5(A\ir|A\il)}{.5(A\ir|A\il)-.5(A\il)}}
    \multido{\il=0+1,\ir=1+1}{\Anodecount}{\rput(A\il){\psline(!dt 2 div neg 0)(!dt 2 div 0)}}
    \rput[t](1.5,4){Center}
\end{pspicture}}

\begin{document}
    \foreach \macro in {Left,Right,Center}{\multido{\i=2+1}{5}{\csname\macro\endcsname{\i}}}
\end{document}

enter image description here

Notes

The following

\psxline(A\il){.5(A\il)-.5(A\ir|A\il)}{.5(A\ir|A\il)-.5(A\il)}

can be simplified as

\rput(A\il){\psline(!dt 2 div neg 0)(!dt 2 div 0)}

We have an accessible dt provided by \curvepnodes apparently, see this comment by Christoph.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .