# How to plot integral as summation, as pictured?

I'm new to TikZ and pgfplots but would like to know how to plot the square as well as how to plot the arrows + delta x as well as arrow + delta A: I'd be most grateful if some of you had some examples I could learn from.

• Welcome to TeX.sx! I included your image as an picture rather than a link. Soon, you will have enough reputation to do it yourself. Oct 8 '12 at 14:58
• – Dror
Oct 8 '12 at 15:05
• @Qrrbrbirlbel: Thanks. Dror: It's a little useful, but I don't think it answers all my questions. Oct 8 '12 at 15:13
• also related (?) tex.stackexchange.com/questions/40780/… Oct 8 '12 at 15:14
• @cmhughes: Looks like I have the "square" part of my question answered. Thanks for the links. Oct 8 '12 at 15:18

To answer the specific questions, using TikZ:

1. To draw curved paths, you can use various methods, described in Section 51.3 Curves of the pgfmanual. Some examples using in=,out=, bend and controls=:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node at (2,2) (a) {A};
\node at (0,0) (b) {B};
\draw[red,->] (a) to[out=0,in=90] (b);
\draw[green,->] (a) to[out=180,in=90] (b);
\draw[blue,->] (a) to[out=-90,in=0] (b);
\node at (4,2) (c) {C};
\node at (2,0) (d) {D};
\draw[olive,->] (c) to[bend right] (d);
\draw[cyan,->] (c) to[bend left=90] (d);
\node at (7,2) (e) {E};
\node at (5,0) (f) {F};
\draw[magenta,->] (e) to[controls=+(90:1) and +(180:1)]  (f);
\end{tikzpicture}

\end{document} 1. The dashed rectangle and the arrows for \delta x can be obtained in a number of ways; for example,

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[dashed] (0,0) rectangle (2,3);
\node at (4,1.5) (delta) {$\delta x$};
\draw[<-] (delta) -- +(-30pt,0);
\draw[<-] (delta) -- +(30pt,0);
\end{tikzpicture}

\end{document} An here's one possibility for drawing the complete diagram, using the intersections library:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[scale=0.7,transform shape]

% a macro for the axes, the curve and the two vertical lines
\def\basic{%
\draw[->] (-0.3,0) -- (5,0) node[right] {$x$} coordinate (x axis);
\draw[->] (0,-0.3) -- (0,3) node[above] {$y$};
\draw [name path=curve] (0.5,2) .. controls (1.5,2.8) and (3.5,1) .. (4.5,2);
\path [name path=line 1] (1,0) -- (1,3);
\path [name path=line 2] (4,0) -- (4,3);
\path [name intersections={of=curve and line 1, by={a}}];
\path [name intersections={of=curve and line 2, by={b}}];
\draw (1,0) node[below] {$a$} -- (a);
\draw (4,0) node[below] {$b$} -- (b);
}

% the initial drawing
\basic
\node[above=10pt] at (b) {$y=f(x)$};

% the middle drawing
\begin{scope}[xshift=7cm]
\basic
\path [name path=line 3] (2.5,0) -- (2.5,3);
\path [name path=line 4] (2.8,0) -- (2.8,3);
\path [name path=line 5] (2.2,0) -- (2.2,3);
\fill [name intersections={of=curve and line 3, by={c}}] (c) circle (2pt) node[above right] {$P(x,y)$};
\path [name intersections={of=curve and line 4, by={d}}];
\path [name intersections={of=curve and line 5, by={e}}];
\draw[dashed] (2.5,0) -- (c);
\draw[dashed] (2.8,0) -- (d);
\draw[<->,shorten >=2pt,shorten <= 2pt] (2.2,0) -- node[left] {$y=f(x)$} (e);
\node at (2.65,-0.3) (delta) {$\delta x$};
\draw[<-] (delta) -- +(-20pt,0);
\draw[<-] (delta) -- +(20pt,0);
\end{scope}

% the rightmost drawing
\begin{scope}[xshift=14cm]
\draw[dashed] (0,0) rectangle (0.3,2);
\node at (0.15,-0.3) (delta) {$\delta x$};
\draw[<-] (delta) -- +(-20pt,0);
\draw[<-] (delta) -- +(20pt,0);
\draw[<->,shorten >=2pt,shorten <= 2pt] (-0.3,0) -- node[left] {$y=f(x)$} (-0.3,2);
\node at (1,2.3) (deltaA) {$\delta A$};
\draw[->] (deltaA) to[out=180,in=90] (0.15,1.8);
\end{scope}
\end{tikzpicture}

\end{document} • Very nice drawing! Can this also be done using PSTricks? (Well, of course it can, but how?) I would maybe like to use this in notes for my students later this year or next year, and I only use PSTricks for drawings. Nov 4 '12 at 17:46
• @SvendMortensen surely it can be done with PS-Tricks, but I don't use it, so I cannot provide the code. Your question won't be seen by many people here, so perhaps it would be best to repost it as a fresh question? Follow-up questions like this are more than welcome! You can link to this question to provide the background. Nov 4 '12 at 19:51
• @Gonzalo Medina: How about the area under the curve x = f (y)? (with TikZ) Nov 22 '13 at 9:37