Approximation is a number plus a guarantee
Let , with , and assume on the whole interval. Divide into equal cells of width , with endpoints and midpoints .
Definition 5.10.1
(Midpoint rule and trapezoid rule)
With the grid above, the midpoint rule and the trapezoid rule are
The midpoint rule replaces on each cell by its value at the center. The trapezoid rule replaces on each cell by the chord through the two end values, so each interior endpoint is counted twice at half weight.
The exact integral need not be known in order to bound the errors:
Both bounds require one valid on the full interval. They bound the mathematical rules evaluated exactly; rounding the sampled values introduces additional error.
Derive the midpoint bound from Taylor's theorem
Theorem 5.10.2
(Midpoint error bound)
If and on , then .
Proof
(Symmetric cancellation on each cell)
On one cell of width centered at , write with . Taylor's theorem through degree one gives with . Integrating, the linear term cancels symmetrically. Thus the cell's error is at most
There are cells; summing their absolute-error bounds gives . The cancellation is on each complete symmetric cell, not at an arbitrary sample point.
The midpoint rule gains an order of accuracy because the first-order term vanishes by symmetry. The trapezoid rule has no such symmetry in the sample, so its bound comes from a different identity.
Derive the trapezoid bound from a kernel
Theorem 5.10.3
(Trapezoid error bound)
If and on , then . If moreover , then .
Proof
(An integration-by-parts identity with a nonnegative kernel)
On a cell of width , let . Since , integration by parts twice gives
Consequently the cell error, integral minus trapezoid, is . Here and , so the absolute error is at most . Sum over cells to obtain the composite bound. If , the kernel identity also shows the trapezoid value is at least the integral; a bound on alone does not determine the error's sign.
Proof X-ray
What the kernel does in the trapezoid proof
The proof has one idea: write the error as an integral of against a fixed weight. The identity is exact, so no approximation enters until the last step. Twice integrating by parts uses to kill the boundary terms that involve , and the surviving boundary terms are exactly the two end values that the trapezoid rule uses; supplies the integral of . The hypothesis is used once, to pull out of the integral, and then the positivity lets us replace by with no cancellation to worry about. The same positivity gives the sign when . If were only continuous, the identity would have no meaning, and if changed sign the estimate would replace by a larger number.
Worked example: Compare both rules on a quadratic
Worked example 5.10.4
(Both rules on a quadratic)
Problem. Apply both rules to on with . Compare their values with the exact integral and the error bounds.
Solution. The width is and . The midpoint values occur at , giving
The exact integral is . Thus and . The bounds are respectively and ; both are attained here. A universal bound can be sharp for one function without being exact for every function.
Worked example: Choose a grid before computing samples
Worked example 5.10.5
(A grid that guarantees three decimals)
Problem. Give a midpoint-rule approximation to with guaranteed error less than , without using its exact integral to choose the grid.
Solution. For , on . Choose and . The exact midpoint sum is
This is a complete exact expression and error guarantee. If the logarithms are rounded for display, their numerical rounding error must be added separately. As an independent check only, integration by parts gives the exact integral .
Worked example: Signs of the errors for a concave function
Worked example 5.10.6
(Sine on an interval with two cells)
Take on with , so and . The exact integral is . The trapezoid value is , with error and bound . The midpoint value is , with error and bound . Both bounds hold. Because , the trapezoid rule underestimates and the midpoint rule overestimates: here . This edge behavior is not a consequence of the absolute bound, which gives no sign.
Common mistakes
Common mistake
(Counting points instead of cells)
For cells on there are five points, but , not . The trapezoid sum uses the two endpoints at half weight and three interior points at full weight, which is interior points. The midpoint sum uses exactly midpoints, none of them a grid point.
Common mistake
(Ignoring rounding in the sampled values)
In the example the guarantee leaves only about of the budget . If each of the seven logarithms is rounded to three decimals, each is wrong by up to , and the weighted sum can be wrong by . Then the total guarantee is only . The mathematical bound has not failed; the computation has added error that the bound does not cover.
Another tempting shortcut changes the hypothesis on itself.
Counterexample mode
M must bound the second derivative on the whole interval
Claim: one may take at the midpoint of the interval. Test on with , , where and . The exact integral is . The trapezoid value is , with error , but the claimed bound is . The midpoint value is , with error , but the claimed bound is . Both claimed bounds fail. The correct constant is , which gives the valid bounds and .
Exercises
Quick check
(Apply the midpoint rule to on with . Compare the actual error with the bound .)
Here , , and the single midpoint is .
Solution · Answer
and , so the error is . The bound is . The bound is attained, as for in the main example.
Quick check
(For a function that is convex () on , is at least or at most ?)
Use the sign of the kernel identity.
Solution · Answer
At least. The cell error equals because and . So .
Exercise 5.10.7
(Find a number of equal cells for which the trapezoid rule is guaranteed to approximate with error less than , and show that is not guaranteed by the bound.)
Core
Solution(3)
- 1
Bound the second derivative on the whole interval
For , , which is decreasing and positive on , so .
- 2
Insert into the trapezoid bound
Key step
The error is at most .
Because: The bound is with and .
- 3
Solve for the grid
We need , that is , so since and . For the bound is . For it is , so the guarantee is not available.