Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 68 ยท Integrals

The Integral as Accumulated Change

Understand the definite integral as accumulated change: area under a curve, left, right and midpoint Riemann sums, and a numpy implementation.

Derivatives answer "how fast is this changing right now?" The integral answers the reverse question: if I know the rate at every moment, how much has accumulated in total? If a car's speedometer reads a different value every second, the integral of speed over time is the distance travelled. If a tank fills at a changing rate, the integral of the rate is the volume of water.

Geometrically, the integral is the area between a curve and the x-axis. These two pictures, accumulated change and area, are the same thing, and this lesson builds them from scratch by adding up thin rectangles.

Area by slicing

Take a function f(x) on an interval [a, b]. Cut the interval into n strips, each of width

dx = (b - a) / n

On each strip, approximate the area by a rectangle with height equal to the function value at some sample point. Add the rectangles. This sum is a Riemann sum:

S_n = f(x1)*dx + f(x2)*dx + ... + f(xn)*dx

The heights come from different choices of sample point:

  • Left sum: the left edge of every strip.
  • Right sum: the right edge.
  • Midpoint sum: the centre of the strip.
flowchart LR
    A["Split [a, b] into n strips"] --> B["Pick a height on each strip"]
    B --> C["Add rectangle areas"]
    C --> D["Let n grow without bound"]
    D --> E["Definite integral"]

The definite integral is the limit of Riemann sums as the strips get thinner.

The definite integral

When the number of strips goes to infinity and the width goes to zero, the sums approach a single number, if f is reasonable (continuous is enough). That number is the definite integral:

integral from a to b of f(x) dx = lim (n -> infinity) of S_n

In the symbol, the elongated S stands for "sum", dx is the infinitesimal width, and a, b are the limits. The variable x is a dummy name: the value is the same if you write t instead.

If f is negative somewhere, rectangles below the axis count as negative area. The integral therefore measures signed area, or net change. The area of sin(x) over [0, 2*pi] is zero because the hump above cancels the dip below.

Riemann sums with numpy

With arrays, every kind of Riemann sum takes only a few lines. Here we integrate f(x) = x**2 over [0, 3]. The exact value is 3**3/3 = 9, which we will prove in the Fundamental Theorem.

Python Left, right and midpoint sums

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Because x**2 is increasing on [0, 3], the left sum always underestimates and the right sum always overestimates, squeezing the true value between them. The midpoint rule is far more accurate for the same n, because overshoot and undershoot within a strip largely cancel.

Seeing the rectangles

A picture makes the approximation concrete. plt.bar draws rectangles; setting align="edge" anchors each bar at its left edge.

Python Draw a left Riemann sum

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Here the sine hump cancels the dip, so the exact area is just the constant part: 1.5 * 2*pi. Notice how well even eight rectangles do.

How fast do the sums converge?

For the left and right rules, doubling n roughly halves the error. For the midpoint rule, doubling n cuts the error by about four. This difference in order of accuracy matters a great deal in numerical work, and we will exploit it in Numerical Integration.

Python Error versus number of strips

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The "ratio" column is about 2 for the left rule (first order) and about 4 for the midpoint rule (second order).

From sums to the exact limit

The picture of rectangles becomes a definition once you say precisely what the limit means. Take any partition of [a, b] into strips, pick any sample point in each strip, and form the sum of f(sample) x width. The function is Riemann integrable if all such sums approach the same number as the widest strip shrinks to zero, whatever sample points you choose. Left, right and midpoint sums are just three particular choices.

A cleaner way to see why the limit exists for a nice function is to trap it between two sums. On each strip take the smallest value of f to form the lower sum, and the largest value to form the upper sum. Every Riemann sum lies between them. For continuous functions (and for any bounded function with only finitely many jumps) the gap between upper and lower sums shrinks to zero as the strips get thinner, so the integral is squeezed to a single number. A function that jumps wildly everywhere, such as "1 at rational x, 0 at irrational x", has upper sums stuck at 1 and lower sums stuck at 0 on every strip. It is not Riemann integrable, and the idea of area breaks down.

Sometimes the limit can be taken by hand. For f(x) = x**2 on [0, 3] with the right sum, strip k has height (3k/n)**2 and width 3/n, so S_n = (27 / n**3) (1**2 + 2**2 + ... + n**2). Using the sum-of-squares formula n(n + 1)(2n + 1)/6 this simplifies to

S_n = 9 + 27 / (2n) + 9 / (2 n**2)

and the limit as n grows is exactly 9. That is how integrals were evaluated before the Fundamental Theorem made it unnecessary.

Python The exact limit, upper and lower sums, and signed area

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The symbolic sum reproduces 9 + 27/(2n) + 9/(2n**2) and its limit 9. The lower and upper sums close in on 9 from both sides, and the gap shrinks by a factor of four each time n is multiplied by four, so it is proportional to 1/n: for a monotonic function the gap equals (f(b) - f(a)) dx, here 9 x 3 / n. The last lines show the distinction from earlier: the integral of sin over a full period is 0, while the total area between the curve and the axis is 4.

Properties worth knowing

Integrals obey a few rules that you will use constantly:

  • Linearity: the integral of c*f + g is c times the integral of f plus the integral of g.
  • Additivity over intervals: the integral from a to b plus the integral from b to c equals the integral from a to c.
  • Reversal: swapping the limits flips the sign.
  • Zero width: the integral from a to a is 0.
  • Bounds: if m <= f(x) <= M on [a, b], then the integral lies between m*(b - a) and M*(b - a).

The average value of a function over an interval is the integral divided by (b - a). This is the root of many engineering quantities, from mean power to RMS voltage (see Applications of Integrals).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the definite integral of a rate of change over [a, b] represent?

    Integrating a rate over an interval adds up all the small changes, giving the net change over that interval.
  2. 2. For an increasing function, how does the left Riemann sum compare with the true area?

    On each strip the left edge has the lowest value of an increasing function, so each rectangle falls short of the curve.
  3. 3. What is the width of each strip for [2, 10] with n = 4?

    dx = (b - a)/n = (10 - 2)/4 = 2.
  4. 4. Why is the integral of sin(x) over [0, 2*pi] equal to zero?

    The integral measures signed area. The positive hump and the equal negative dip cancel.

Summary

  • The definite integral is the limit of Riemann sums: it equals the signed area under f and the total accumulated change.
  • Left, right and midpoint rules differ only in where on each strip the height is measured.
  • Left and right sums have error proportional to dx; the midpoint rule's error is proportional to dx**2.
  • Linearity, additivity over intervals and sign reversal are the key properties.
  • Computing Riemann sums with numpy takes a few lines and gives a direct feel for convergence.

Next: The Fundamental Theorem of Calculus.