SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 2.5.1 Area and Riemann sumsConcept · 30 min
      2. 2.5.2 AntiderivativesConcept · 25 min
      3. 2.5.3 The fundamental theorem of calculusConcept · 30 min
      4. 2.5.4 Practice set: integrationPractice set · 25 min
      5. 2.5.5 Case study: present value of a continuous cash flowCase study · 35 min

Level 2, Single-variable calculus 2.5 Integration Lesson 1 of 5

ConceptLesson 2.5.1 in Level 2, Single-variable calculus. About 30 minutes.

Area and Riemann sums

What area under a curve means

The area under the graph of ff from x=ax = a to x=bx = b is the region between the curve and the xx-axis over that stretch. Its units are height units times width units.

That makes area more than geometry. A car at 60 km per hour for 2 hours covers 60×2=12060 \times 2 = 120 km. That is the area of a rectangle of height 60 and width 2 under the graph of its speed.

When the speed changes, the region under the speed graph is no longer a rectangle, but its area is still the distance. No school formula gives the area under a curve. So this lesson cuts the region into thin strips, covers each with a rectangle, and adds up the rectangles.

Rectangles under x2x^2

Take f(x)=x2f(x) = x^2 from 0 to 1. Cut [0,1][0, 1] into n=4n = 4 strips of equal width Δx=1−04=14\Delta x = \frac{1 - 0}{4} = \frac{1}{4}. Each strip gets a rectangle whose height is the value of ff at one point of the strip.

heights taken atpointsheightstotal area
left ends0,14,12,340, \frac{1}{4}, \frac{1}{2}, \frac{3}{4}0,116,14,9160, \frac{1}{16}, \frac{1}{4}, \frac{9}{16}0.21875
right ends14,12,34,1\frac{1}{4}, \frac{1}{2}, \frac{3}{4}, 1116,14,916,1\frac{1}{16}, \frac{1}{4}, \frac{9}{16}, 10.46875
midpoints18,38,58,78\frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}164,964,2564,4964\frac{1}{64}, \frac{9}{64}, \frac{25}{64}, \frac{49}{64}0.328125

Each total is the sum of the four heights times the width 14\frac{1}{4}. For the left ends, (0+116+14+916)×14=732=0.21875\left(0 + \frac{1}{16} + \frac{1}{4} + \frac{9}{16}\right) \times \frac{1}{4} = \frac{7}{32} = 0.21875. The three totals differ, so each is only an estimate of the area.

Writing the sum with Σ

Number the strips i=1,2,…,ni = 1, 2, \ldots, n. Strip ii runs from xi−1x_{i-1} to xix_i, where xi=a+i Δxx_i = a + i\,\Delta x, so x0=ax_0 = a and xn=bx_n = b. Write xi∗x_i^* (read "x i star") for the point where strip ii takes its height.

Rule: Riemann sum

Δx=b−an,xi=a+i Δx∑i=1nf(xi∗) Δx\begin{gathered} \Delta x = \frac{b - a}{n}, \quad x_i = a + i\,\Delta x \\[4pt] \sum_{i=1}^{n} f(x_i^*)\,\Delta x \end{gathered}

Each term is one rectangle: height f(xi∗)f(x_i^*) times width Δx\Delta x. The left sum takes xi∗=xi−1x_i^* = x_{i-1}, the right sum xi∗=xix_i^* = x_i, and the midpoint sum the middle of the strip, xi−1+xi2\frac{x_{i-1} + x_i}{2}.

Every term has the same width, so Δx\Delta x comes out in front: ∑f(xi∗) Δx=Δx∑f(xi∗)\sum f(x_i^*)\,\Delta x = \Delta x \sum f(x_i^*). That is the constant multiple rule of lesson 0.2.2, and it is why each total above is "add the heights, then multiply by 14\frac{1}{4}".

Try it

riemann is the rule above, for all three choices of point. The cell prints the three totals of the table.

np.arange(n) numbers the strips 0,1,…,n−10, 1, \ldots, n - 1, because Python counts from 0. So the strip numbered i starts at a+i Δxa + i\,\Delta x.

⌘/Ctrl + Enter runs the cell

Too large or too small?

For a rising curve, the left sum is too small and the right sum too large. For a falling curve it is the other way round.

On a strip where ff rises, the left end is the lowest point. So the left rectangle sits under the curve and misses a sliver of area, while the right rectangle pokes above it. x2x^2 rises on [0,1][0, 1], so the left sum 0.21875 is too small and the right sum 0.46875 too large.

1x\frac{1}{x} falls on [1,2][1, 2]. With 4 strips its left sum is 0.759524 and its right sum 0.634524. The exact area is ln⁡2≈0.693147\ln 2 \approx 0.693147 (lesson 2.5.3 shows why), so now the left sum is too large and the right sum too small.

Rule: Which way the error goes

f rising: left sum<area<right sumf falling: right sum<area<left sum\begin{gathered} f \text{ rising: left sum} < \text{area} < \text{right sum} \\ f \text{ falling: right sum} < \text{area} < \text{left sum} \end{gathered}

The exact area is trapped between the two sums. A curve that rises and then falls follows neither line. For sin⁡x\sin x on [0,π][0, \pi] with 4 strips, both sums are 1.896119, under the exact area 2.

The midpoint sum lands on a side that depends on how the curve bends (lesson 2.4.2). It is too small for x2x^2 (0.328125) and 1x\frac{1}{x} (0.69122), which bend up. It is too large for sin⁡x\sin x on [0,π][0, \pi] (2.052344), which bends down.

The gap between the left and right sums has a simple formula. Both use the heights at x1,…,xn−1x_1, \ldots, x_{n-1}; only the two ends differ. So the right sum minus the left sum is Δx (f(b)−f(a))\Delta x\,\big(f(b) - f(a)\big): for x2x^2 with 4 strips, 14×(1−0)=0.25\frac{1}{4} \times (1 - 0) = 0.25.

Try it in the explorer. It starts with the four left rectangles of the table: switch to right ends and midpoints and compare the totals. Then pick 1x\frac{1}{x} on [1,2][1, 2] and watch the left and right sums swap sides, and finally raise nn towards 100.

Explore

Add rectangles and change where each takes its height. The total area of the rectangles closes in on the exact area under the curve.

00.5100.51
Width of each
1 ÷ 4 = 0.25
Total of 4 rectangles
0.21875
Exact area
1/3 = 0.333333
Error
−0.114583 (an underestimate)

Thinner strips, smaller errors

As the strips get thinner, all three sums close in on the same number. For x2x^2 on [0,1][0, 1]:

strips nn41010010000
left sum0.218750.2850.328350.333283
right sum0.468750.3850.338350.333383
midpoint sum0.3281250.33250.3333250.333333

The left and right errors shrink in step with Δx\Delta x. Ten times as many strips cut the left error about ten times, from 0.04833 at n=10n = 10 to 0.00498 at n=100n = 100. The midpoint error shrinks with Δx2\Delta x^2: ten times as many strips cut it a hundred times, from 0.00083 to 0.0000083.

So the midpoint sum is the one to use when you estimate an area in code. Lesson 2.8.2 builds Simpson's rule, which is faster still.

The same limit by algebra

For the right sum of x2x^2 on [0,1][0, 1], the points are xi=inx_i = \frac{i}{n} and the width is 1n\frac{1}{n}. Pulling 1n3\frac{1}{n^3} out in front leaves the sum of the first nn squares.

Rn=∑i=1n(in)21n=1n3∑i=1ni2=(n+1)(2n+1)6n2\begin{aligned} R_n &= \sum_{i=1}^{n} \left(\frac{i}{n}\right)^2 \frac{1}{n} \\ &= \frac{1}{n^3}\sum_{i=1}^{n} i^2 \\ &= \frac{(n + 1)(2n + 1)}{6n^2} \end{aligned}

The last line uses the formula ∑i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^{n} i^2 = \frac{n(n + 1)(2n + 1)}{6}, which the Proof Gym proves by induction. For n=4n = 4 it gives 4×5×96=30\frac{4 \times 5 \times 9}{6} = 30, the sum 1+4+9+161 + 4 + 9 + 16 of lesson 0.2.2. Then R4=4596=0.46875R_4 = \frac{45}{96} = 0.46875, the right sum in the table.

As n→∞n \to \infty, the top (n+1)(2n+1)(n + 1)(2n + 1) grows like 2n22n^2 and the bottom is 6n26n^2, so Rn→26=13R_n \to \frac{2}{6} = \frac{1}{3} (the biggest power wins, lesson 2.1.3). The error is Rn−13=3n+16n2R_n - \frac{1}{3} = \frac{3n + 1}{6n^2}, about 12n\frac{1}{2n}: it halves each time nn doubles.

Try it

Each line prints nn, the left, midpoint and right sums, then the algebra's formula for the right sum. The last two numbers agree.

round(…, 6) keeps six decimal places, as in the table.

⌘/Ctrl + Enter runs the cell

The definite integral

When the sums for every choice of point settle on one number, that number is the definite integral. They do for every continuous ff (lesson 2.1.2) on a closed interval [a,b][a, b].

Rule: Definite integral

∫abf(x) dx=lim⁡n→∞∑i=1nf(xi∗) Δx\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^{n} f(x_i^*)\,\Delta x

The sign ∫\int is a stretched S, for "sum". f(x)f(x) is the integrand, aa and bb are the lower and upper limits of integration, and dxdx recalls the width Δx\Delta x. So ∫01x2 dx=13\int_0^1 x^2\,dx = \frac{1}{3}.

A definite integral is a number, in height units times width units. For the car, ∫0260 dt=120\int_0^2 60\,dt = 120 km.

The letter inside is a placeholder, like the index of a sum in lesson 0.2.2: ∫01x2 dx\int_0^1 x^2\,dx and ∫01t2 dt\int_0^1 t^2\,dt are the same number. If ff blows up inside [a,b][a, b], as 1x\frac{1}{x} does at 0, the sums need not settle. Lesson 2.6.3 deals with such integrals.

Signed area

Where ff is negative, the integral counts the area as negative. Below the axis, each height f(xi∗)f(x_i^*) is negative, so each term f(xi∗) Δxf(x_i^*)\,\Delta x is negative too.

So the integral adds the area above the axis and subtracts the area below. This is the net, or signed, area. The total area counts every piece as positive.

The region between y=xy = x and the axis from −1-1 to 2. The integral is the net area, 2−0.5=1.52 - 0.5 = 1.5; the total area is 2+0.5=2.52 + 0.5 = 2.5.

Both triangles can be checked with 12×base×height\frac{1}{2} \times \text{base} \times \text{height}: 12×2×2=2\frac{1}{2} \times 2 \times 2 = 2 above the axis, and 12×1×1=0.5\frac{1}{2} \times 1 \times 1 = 0.5 below it. So ∫−12x dx=1.5\int_{-1}^{2} x\,dx = 1.5.

A net area of zero does not mean there is no area. On [0,2π][0, 2\pi], the dip of sin⁡x\sin x below the axis is a mirror image of the hump above it, so they cancel: ∫02πsin⁡x dx=0\int_0^{2\pi} \sin x\,dx = 0. Each piece has area 2 (the explorer gives this exact area for sin⁡x\sin x on [0,π][0, \pi]), so the total area is 4.

Rule: Net and total area

net=area above−area belowtotal=area above+area below\begin{gathered} \text{net} = \text{area above} - \text{area below} \\ \text{total} = \text{area above} + \text{area below} \end{gathered}

The integral ∫abf(x) dx\int_a^b f(x)\,dx is the net area. The total area is the integral of ∣f(x)∣|f(x)|, which flips the parts below the axis up. Lesson 2.5.3 finds both exactly.

Try it

Midpoint sums with 1200 strips for both examples. Each line prints the net area, then the total area from np.abs.

Unrounded, the total area of sin⁡x\sin x is 4.0000046. The midpoint sum is a little too large, because both humps of ∣sin⁡x∣|\sin x| bend down. round(…, 4) keeps four decimal places.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. Height times width. Each term is f(xi∗) Δxf(x_i^*)\,\Delta x. Adding the heights alone forgets the width.
  2. The width is b−an\frac{b - a}{n}, not 1n\frac{1}{n}. With 4 strips on [0,2][0, 2], Δx=0.5\Delta x = 0.5.
  3. Count the points. nn strips have n+1n + 1 edges. The left sum uses the first nn of them, the right sum the last nn.
  4. "The left sum is too small" holds only for a rising curve. For a falling curve it is too large.
  5. A net area of 0 does not mean no area. sin⁡x\sin x on [0,2π][0, 2\pi] has net area 0 and total area 4.
  6. A Riemann sum is an estimate. The integral is its limit as n→∞n \to \infty.

Riemann sums and integrals

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • The area under ff from aa to bb is in height units times width units; under a speed graph it is a distance.
  • A Riemann sum ∑i=1nf(xi∗) Δx\sum_{i=1}^{n} f(x_i^*)\,\Delta x adds rectangles of width Δx=b−an\Delta x = \frac{b - a}{n}, with heights at the left ends, the right ends or the midpoints.
  • For a rising ff the left sum is too small and the right sum too large; for a falling ff the reverse. They differ by Δx (f(b)−f(a))\Delta x\,\big(f(b) - f(a)\big).
  • Left and right errors shrink like Δx\Delta x, midpoint errors like Δx2\Delta x^2.
  • The definite integral ∫abf(x) dx\int_a^b f(x)\,dx is the limit of the sums as n→∞n \to \infty.
  • The integral is the net area: area below the axis counts as negative. The total area counts every piece as positive.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.