Calculus · Eqora guide

Trapezoidal rule for unevenly spaced data

Estimate an integral from unevenly spaced readings. Use each actual interval width, check the units and see how curvature affects the error.

Woman in a mustard coat checking a hose beside an orange pump on a river dock at dawn

A pump report gives four flow readings. At 0, 2, 5 and 6 minutes, the flow is 4, 8, 6 and 2 liters per minute, respectively. You want to estimate how much water passed through the hose during those six minutes. Adding the four numbers would give a sum of rates, with units of liters per minute. The volume depends on how long the pump ran between readings.

The trapezoidal rule treats the rate as changing along a straight segment between each pair of consecutive readings. Multiply each time gap by the average of its two endpoint rates, then add the results. Keeping those gaps visible matters here because the middle gap is three minutes and the last one is only one minute. A formula with a single shared step size would describe a different table.

Where the trapezoidal rule comes from

Draw time along the horizontal axis and flow rate along the vertical axis. Between minutes 0 and 2, join the heights 4 and 8 with a straight line. The region under that segment consists of a rectangle of height 4 and a triangle whose height increases by 4 across the interval. The rectangle contributes 2 × 4 = 8 liters. The triangle contributes 2 × 4 / 2 = 4 liters. Their sum is 12 liters.

You can get the same result with one multiplication. Average the heights to get (4 + 8)/2 = 6 liters per minute, then multiply by the two-minute width. Replacing the sloped top by a horizontal top at the average height preserves the area. The same reasoning works if the rate falls, because the shorter endpoint still gives the rectangle and the difference in heights still gives a triangle.

For an interval from a to b and a function f, the contribution is (b − a)(f(a) + f(b))/2. The trapezoidal estimate is exact for a line because the segment connecting its endpoints is the line itself. The estimate for a general curve uses that segment as an approximation. This distinction is central to interpreting a number from a table. The calculation is exact for the piecewise linear model you build from the data. Its accuracy for the real pump depends on what the rate did between readings.

In a graph of a rate, each vertical value is a rate and each horizontal interval supplies a duration. Practicing how to read calculus graphs helps you distinguish the area you are estimating from the slope of the connecting segment.

Partly filled translucent jug next to two wooden strips on a wet dock

Add a contribution for each actual time gap

Write the time gaps before multiplying. From minute 0 to minute 2 the width is 2 and the endpoint average is 6, contributing 12 liters. From minute 2 to minute 5 the width is 3 and the average is (8 + 6)/2 = 7, contributing 21 liters. From minute 5 to minute 6 the width is 1 and the average is (6 + 2)/2 = 4, contributing 4 liters. The total estimate is 12 + 21 + 4 = 37 liters.

The middle interval contributes most. It combines a high average rate with the longest duration. The last interval contributes the least because its rate is lower on average and the interval lasts only a minute. Read the units in each multiplication. Minutes multiplied by liters per minute gives liters. If your final line still has liters per minute, you have probably computed an average rate rather than a volume.

The same arithmetic applies to measurements other than flow. Integrating speed over time estimates distance traveled. Integrating a rate of energy use over time estimates energy. When the readings are signed, the formula estimates signed accumulation. For example, a negative rate might describe flow in the opposite direction. If the task asks how much water passed in either direction, you need the magnitude of the rate, and a sign change between readings may require splitting the straight segment where it crosses zero.

For example, suppose the rate goes in a straight line from −2 to 2 liters per minute over two minutes. It crosses zero after one minute. The negative triangle contributes −1 liter and the positive triangle contributes 1 liter. The net volume is zero, while the total volume moved in either direction is 2 liters.

Water pouring from a silver hose into a steel basin

Recognize when equal spacing changes the arithmetic

For equally spaced readings, call the common gap h. When you add adjacent trapezoids, every interior reading appears in two endpoint averages. The first and last appear once. Grouping the terms gives h times the sum of the interior heights plus half of each endpoint height. This compact expression depends on the widths all being equal. The University of Nebraska–Lincoln numerical integration notes give this form for a partition into equal subintervals.

A table with four sample points has three intervals. Even if you divide six minutes by three and get 2, the actual gaps here are 2, 3 and 1. Using 2 as a shared width gives 2 × (4/2 + 8 + 6 + 2/2) = 34 liters. That is a consistent answer for a different table whose readings occur at 0, 2, 4 and 6. It is three liters below the estimate for the actual timestamps.

You can still see the weights explicitly without assuming equal spacing. The first height gets half the first width and the last gets half the last width. An interior height gets half the width on its left plus half the width on its right. For the pump table, the weights are 1, 2.5, 2 and 0.5 minutes. They add to 6 minutes. Multiplying the heights by those weights gives 4 + 20 + 12 + 1 = 37 liters. This makes a useful check, though the interval-by-interval calculation is usually easier to write and review.

Three brass washers at uneven intervals beside a wooden strip on orange boards

Use curvature to interpret the error

When a curve bends upward throughout an interval, its chord lies above it. The trapezoidal estimate is then at least as large as the integral over that interval. For a curve that bends downward, the inequality goes the other way. When the curve changes curvature, errors can have different signs on different intervals. A table alone does not tell you what happens between readings.

Take f(x) = x² on [0, 2]. The exact integral is 8/3. Using two equal intervals gives endpoint heights 0, 1 and 4, and width 1. The contributions are 1/2 and 5/2, giving 3. The estimate is high by 1/3, as expected for this upward-bending curve. That difference is an example of absolute error. To express it as a percentage of the exact integral, divide 1/3 by 8/3 to get 1/8, or 12.5%.

Now use four intervals of width 1/2. The heights are 0, 1/4, 1, 9/4 and 4. The weighted estimate is (1/2)(0/2 + 1/4 + 1 + 9/4 + 4/2) = 11/4. The error is 11/4 − 8/3 = 1/12, one quarter of the previous error. This exact factor follows for this quadratic on the same interval. For a twice continuously differentiable function whose second derivative has magnitude at most M, the standard bound for n equal intervals is M(b − a)³/(12n²). On this example M = 2, and the bound equals the actual absolute error. A bound requires information about the curve that four measured rates do not supply by themselves.

Decide what extra readings would improve the estimate

Connecting neighboring samples with straight segments is the same local assumption used in linear interpolation. Integrating those segments gives an area under a model, including intervals that were never measured directly. If the pump might briefly speed up or stop between readings, two very different rate curves can share the same endpoints and yield different totals. Reporting 37 liters to several decimal places would hide that uncertainty behind extra digits.

If you can take one additional reading, first ask where the curve is likely to depart most from a line. The three-minute gap is a reasonable candidate if nothing else is known, since it is the longest period with no interior reading. But a known valve change during the one-minute gap might matter more. In a measurement problem, choosing sampling times is part of the reasoning, separate from computing an estimate once the table exists.

If you obtain a new reading at minute 3, split the old interval from 2 to 5 into widths 1 and 2. Leave the contributions from 0 to 2 and from 5 to 6 intact. A new reading of 22/3 lies on the old segment and leaves the sum unchanged. A new reading of 9 gives 1 × (8 + 9)/2 + 2 × (9 + 6)/2 = 23.5 liters for that middle span, raising the total to 39.5 liters. The change comes from new information inside the gap.

Practice with three readings

Suppose another pump runs for four minutes. Its rates at 0, 1 and 4 minutes are 3, 5 and 1 liters per minute. Before checking the result, write down the two widths and the average rate for each interval. The equal-step shortcut should stay out of this calculation because the second gap is three times the first.

The first interval contributes 1 × (3 + 5)/2 = 4 liters. The second contributes 3 × (5 + 1)/2 = 9 liters. The total is 13 liters. Check it by averaging the left- and right-endpoint rectangle sums computed on the same intervals. The left sum is 1 × 3 + 3 × 5 = 18 liters. The right sum is 1 × 5 + 3 × 1 = 8 liters. Their average is 13 liters, matching the trapezoids.

If the question instead asks for average flow over the four minutes, divide the accumulated volume by the duration. The estimate is 13/4 = 3.25 liters per minute. This last division changes the units and the question you have answered. Before you finish a problem, read the requested units and look back at the actual time gaps.

Person with a notebook and metal jug at a table next to a river

Your next problem, with a clearer path

Ready to understand the math?

Scan a problem, ask follow-up questions, and turn one difficult step into a method you can use again.

Good to know

Questions about this guide