Riemann sum in this visualization
A Riemann sum approximates the integral of over . Split the interval into subintervals , pick a sample point in each, and add up . This page uses equal subintervals, so every piece has the same width:
The general definition allows subintervals of different widths and any sample point in each, and takes the limit as the widest subinterval, , goes to 0; with equal subintervals, as here, is the same as .
Each yellow rectangle stands on one subinterval and reaches up to , the yellow dot on the curve; adds up their signed areas, so a rectangle below the x-axis counts as negative, and a rectangle may stick out above the curve or fall short of it. The rule decides where the sample point sits: the left endpoint , the right endpoint , or the midpoint. The trapezoid sum joins and with a chord instead, and equals the average of the left and right sums:
n → ∞ doubles step by step up to , so every piece splits in two (from an that is not a power of two, the first step goes up to the next power of two). For an integrable function the sums approach the definite integral, shown in blue:
The page takes the integral from an antiderivative , exactly, never from a sum with a large ; the error is minus that value.
Things to notice
- The area is signed. Where a piece hangs below the x-axis; it is hatched and counts as negative. Over the two arches of cancel, and the integral is 0.
- For an increasing function the left sum is too small and the right sum too large; for a decreasing one it is the other way round. The integral lies between the two.
- How fast the error shrinks depends on the rule. For a smooth function and large , the left and right errors behave like and the midpoint and trapezoid errors like , so each doubling eventually halves or quarters them. Early on the factor can differ (1.6 for the first left sums of on ), and when the leading term cancels the error falls faster: for on the left and right errors already go like . The error chart in the readout bar has both scales logarithmic, so the factor shows as the slope of each line: its base-2 logarithm, slope 1 for a factor of 2 and slope 2 for a factor of 4. Left and right fall gently, midpoint and trapezoid about twice as steeply, except where the leading term cancels.
- The midpoint and trapezoid errors usually have opposite signs. For the midpoint error is exactly of the trapezoid error, for every .
- The definition of the integral allows unequal pieces and any sample point in each; equal pieces with a fixed rule are the special case drawn here. The limit must be the same for every such choice as the widest piece shrinks to 0.
- Strictly, the trapezoid sum is not a Riemann sum (no single sample point per piece), but as the average of the left and right sums it has the same limit. The rectangle and trapezoid rules of numerical integration are these sums.
Controls
- Drag the dotted lines and , or their marks on the bottom edge, turn the two wheels under Interval, or type the endpoints: π, 2π, π/2 and e are understood. The keys under the wheels put them on exact values.
- The rule keys choose where the sample point sits; under each key stand that rule's sum and its error at the current , so the four can be compared at a glance. The chart between the sum and the integral shows the size of the error against for all four rules.
- The knob sets to 1, 2, 4 … 256, one stop per doubling; its arrow keys go to the next stop. Any other up to 10 000 can be typed. n → ∞ doubles step by step up to 256 (first up to the next power of two) and stays there; pressed at 256 it starts again at 1. Presentation mode opens a full-screen view for projectors (Space runs n → ∞, ← → halve and double n, H hides the answers).
Related
- D18Fundamental theorem of calculus
- D01Limit
- D34SeriesPlanned
- E18Double integralPlanned
Further reading: Wikipedia: Riemann sum; OpenStax, Calculus Volume 1, 5.1 Approximating Areas; OpenStax, Calculus Volume 2, 3.6 Numerical Integration.