Interactive tool

Riemann sum explorer

Cover the region under a curve with rectangles or trapezoids and compare their total with the exact integral.

Pick a function and a rule, then move the slider to change the number of strips nn. The explorer adds up the strips and sets the total next to the exact value of the integral. Strips above the xx axis count as positive and strips below it count as negative, so the sum estimates signed area.

Rule
−0.250.250.50.7511.250.250.50.751xy
4

Δx = 0.25

  • Above the axis, counted as positive
  • Below the axis, counted as negative
Left sum
0.218750
Exact integral
0.333333Equals 1/3
Error
−0.114583The sum is too small
Simpson's rule
0.333333Error 0.000000

Things to try

  • Start with x2x^2 on [0,1][0, 1] and n=4n = 4. The left sum is 0.218750.21875 and the right sum is 0.468750.46875, so the exact area 13\frac{1}{3} lies between them. That holds for every nn, because x2x^2 is increasing there.
  • Stay with x2x^2 and go from n=4n = 4 to n=8n = 8. The left sum error goes from about −0.1146-0.1146 to about −0.0599-0.0599, roughly half. The midpoint error goes from −0.005208-0.005208 to −0.001302-0.001302, exactly a quarter.
  • Compare the midpoint and trapezoid errors for x2x^2, exe^x or 1x\frac{1}{x}. The trapezoid error is close to twice the midpoint error and has the opposite sign. For x2x^2 the ratio is exactly −2-2 at every nn.
  • With sin⁡x\sin x on [0,π][0, \pi] or the half circle 1−x2\sqrt{1 - x^2} on [−1,1][-1, 1], the left, right and trapezoid sums agree for every nn. The function is 00 at both ends, so the first left rectangle and the last right rectangle add nothing.
  • Pick x3−xx^3 - x on [−1,1.5][-1, 1.5] with the left rule and n=4n = 4. The sum is −0.073242-0.073242 even though the integral is 2564=0.390625\frac{25}{64} = 0.390625. The negative strips between 00 and 11 outweigh the positive ones for n=2n = 2, 33 and 44, and the left sum turns positive at n=5n = 5.
  • Watch Simpson’s rule on the three polynomials. For x2x^2, 4−x24 - x^2 and x3−xx^3 - x it gives the exact value at every even nn.
  • On the half circle Simpson’s rule loses to the midpoint rule at every even nn. The slope of 1−x2\sqrt{1 - x^2} grows without bound near x=±1x = \pm 1, and the error estimates behind Simpson’s rule need a smooth function.
  • For exe^x on [0,1][0, 1], find the smallest nn that brings the midpoint error under 0.00010.0001. It is n=27n = 27.

What you are seeing

The interval [a,b][a, b] is cut into nn pieces of equal width with the points xix_i,

Δx=b−an,xi=a+i Δx(i=0,1,…,n).\begin{gathered} \Delta x = \frac{b - a}{n}, \\[0.8em] x_i = a + i \, \Delta x \quad (i = 0, 1, \ldots, n). \end{gathered}

The left, right and midpoint rules sample ff at one point of each piece and add the rectangles,

Ln=∑i=1nf(xi−1) Δx,Rn=∑i=1nf(xi) Δx,Mn=∑i=1nf ⁣(xi−1+xi2)Δx.\begin{aligned} L_n &= \sum_{i=1}^{n} f(x_{i-1}) \, \Delta x, \\[0.8em] R_n &= \sum_{i=1}^{n} f(x_i) \, \Delta x, \\[0.8em] M_n &= \sum_{i=1}^{n} f\!\left(\frac{x_{i-1} + x_i}{2}\right) \Delta x. \end{aligned}

The trapezoid rule joins neighboring points of the graph with straight segments. It equals the average of the left and right sums,

Tn=Δx2[f(x0)+2f(x1)+⋯+2f(xn−1)+f(xn)]=Ln+Rn2.\begin{aligned} T_n &= \frac{\Delta x}{2} \bigl[ f(x_0) + 2f(x_1) + \cdots \\[0.4em] &\qquad + 2f(x_{n-1}) + f(x_n) \bigr] \\[0.8em] &= \frac{L_n + R_n}{2}. \end{aligned}

When nn is even, Simpson’s rule fits a parabola through each three neighboring points,

Sn=Δx3[f(x0)+4f(x1)+2f(x2)+⋯+4f(xn−1)+f(xn)].\begin{aligned} S_n = \frac{\Delta x}{3} \bigl[ & f(x_0) + 4f(x_1) + 2f(x_2) + \cdots \\[0.4em] & + 4f(x_{n-1}) + f(x_n) \bigr]. \end{aligned}

A product f(x) Δxf(x) \, \Delta x with f(x)<0f(x) < 0 is negative, which is why the strips below the axis are shaded differently and subtract from the total. A trapezoid whose top edge crosses the axis is split there, and each part is shaded by its sign.

The exact value comes from an antiderivative, for example

∫121x dx=ln⁡2≈0.693147.\int_1^2 \frac{1}{x} \, dx = \ln 2 \approx 0.693147.

The error shown is the sum minus the exact value, so a positive error means the sum is too big. Left and right sum errors shrink roughly like 1n\frac{1}{n}. Midpoint and trapezoid errors shrink like 1n2\frac{1}{n^2}, and Simpson errors like 1n4\frac{1}{n^4} for smooth functions.

These sums are built up in The Area Problem, Partitions and Riemann Sums and Integral Approximation Rules, and the formulas are on the calculus reference sheet. The videos are on the Calculus course page. For a first look at rectangle sums without calculus, see Area Approximation with Rectangles on the Precalculus course page.