From an Error Target to a Computation
A quadrature calculation is not finished when an estimate has been produced. In many applications, the more important question is whether the estimate is accurate enough—and how much computation is needed to justify that claim.
This workshop focuses on a practical decision: given a definite integral and a requested absolute-error tolerance, should we use the composite trapezoidal rule or the composite Simpson rule, and how many panels should we take? The answer depends on the regularity of the integrand, available derivative bounds, and the cost of evaluating the function.
A bound is a guarantee under stated assumptions, not a prediction of the exact error. A method may perform much better than its bound, but a panel count chosen from that bound is what certifies the requested tolerance.
The Error Bounds Used for Planning
Let \(f\) be defined on \([a,b]\), and divide the interval into \(n\) equal panels of width \(h=(b-a)/n\). Write \(T_n\) for the composite trapezoidal approximation and \(S_n\) for the composite Simpson approximation. The following standard error bounds give a way to plan the computation.
The derivative bound must hold on the whole interval, not just at the endpoints or at the quadrature nodes. A larger valid derivative bound is safe but may lead to more panels than necessary. Simpson’s rule also has a structural restriction: its composite form requires an even number of panels.
For a requested absolute-error tolerance \(\varepsilon>0\), we plan by requiring the applicable upper bound to be no greater than \(\varepsilon\). Solving these inequalities gives the panel-count rules.
For the trapezoidal rule, round the result up to the next integer. For Simpson’s rule, choose the smallest even integer at least as large as the calculated threshold. Rounding down can invalidate the guarantee.
Worked Example: Choosing a Trapezoidal Panel Count
Worked Example: A tolerance for the integral of \(x^2\)
Find a trapezoidal panel count that guarantees absolute error at most \(0.01\) for \(\int_0^1 x^2\,dx\), and calculate the resulting approximation.
Here \(f(x)=x^2\), so \(f''(x)=2\) throughout \([0,1]\). Thus \(M_2=2\), \(b-a=1\), and the error bound is
Require this to be no greater than \(0.01\):
Therefore \(n\ge\sqrt{50/3}\approx4.082\), so the smallest allowable integer is \(n=5\). The panel width is \(h=1/5=0.2\), and the node values are \(0\), \(0.04\), \(0.16\), \(0.36\), \(0.64\), and \(1\). The composite trapezoidal formula gives
As a check, \(\int_0^1x^2\,dx=1/3\), so the actual absolute error is \(|0.34-1/3|=1/150\approx0.006667\). The stated bound is \(1/(6\cdot25)=1/150\), which agrees with the error here. In general, the bound need not equal the actual error.
Worked Example: Choosing an Even Simpson Panel Count
Worked Example: A Simpson tolerance for \(x^4\)
Find the smallest Simpson panel count that guarantees absolute error at most \(0.0005\) for \(\int_0^1x^4\,dx\), then compute the Simpson estimate for that count.
Since \(f^{(4)}(x)=24\), we may use \(M_4=24\). The Simpson bound becomes
Imposing the tolerance gives
The fourth root of \(800/3\) is approximately \(4.041\). The smallest integer above it is \(5\), but Simpson’s rule requires an even panel count. Therefore the smallest eligible count is \(n=6\).
For \(n=6\), the bound is \(2/(15\cdot1296)=1/9720\approx0.00010288\), which is below \(0.0005\). The width is \(h=1/6\). At the seven nodes \(k/6\), for \(k=0,\ldots,6\), the fourth-power values are \(k^4/1296\). The weighted numerator in Simpson’s formula, using denominator \(1296\), is
Consequently,
The exact integral is \(1/5=0.2\). The actual error is \(389/1944-1/5=1/9720\approx0.00010288\), equal to the bound in this case. Substitution into the exact integral confirms that this error is within the requested tolerance.
Comparing Accuracy and Evaluation Cost
Panel count is a useful first measure of cost. On a uniform grid, either composite rule requires the function values at the \(n+1\) nodes, so a direct calculation uses \(n+1\) evaluations if each node value is computed once. This count does not include the cost of evaluating the function itself, setup work, or the arithmetic used to combine the values.
The error formulas explain why the methods can have very different panel requirements. The trapezoidal bound decreases in proportion to \(n^{-2}\), whereas the Simpson bound decreases in proportion to \(n^{-4}\). That faster decrease can make Simpson attractive when its fourth-derivative condition is available and the even-panel requirement is satisfied.
Worked Example: Comparing guaranteed cost for the same integral
Compare the smallest panel counts that guarantee absolute error at most \(0.001\) for \(\int_0^1x^4\,dx\), using each rule. Then calculate both estimates.
For the trapezoidal rule, \(M_2=12\), so the bound is \(12/(12n^2)=1/n^2\). Requiring \(1/n^2\le0.001\) gives \(n^2\ge1000\), hence \(n\ge31.623\) and the smallest integer choice is \(n=32\). This calculation uses \(33\) node values.
For Simpson’s rule, \(M_4=24\), so the bound is \(2/(15n^4)\). Requiring \(2/(15n^4)\le0.001\) gives \(n^4\ge400/3\), or \(n\ge3.398\). The smallest even choice is \(n=4\), which uses \(5\) node values.
To compare the estimates, the exact integral is \(1/5\). For \(x^4\), the composite trapezoidal sum on \([0,1]\) can be written as
where the second equality follows by inserting \(\sum_{k=1}^{n-1}k^4=(n-1)n(2n-1)(3n^2-3n-1)/30\) and simplifying. At \(n=32\), this gives
The actual error is approximately \(0.000325489\), below both the \(0.001\) target and the guaranteed bound \(1/32^2=0.000976563\).
For Simpson with \(n=4\), the function values at \(0,1/4,1/2,3/4,1\) are \(0,1/256,1/16,81/256,1\). Therefore
The actual error is \(77/384-1/5=1/1920\approx0.000520833\). The Simpson bound at \(n=4\) is \(2/(15\cdot256)=1/1920\), also below \(0.001\). For this example, Simpson meets the same guaranteed tolerance with \(5\) function values instead of \(33\). This is a cost comparison for this integrand and these bounds, not a claim that Simpson is always preferable.
How to Make the Choice
A sound choice starts with the information actually available about the integrand. If a continuous second derivative and a valid bound for its magnitude are known, the trapezoidal guarantee can be used. A Simpson guarantee needs a continuous fourth derivative and a valid bound for that derivative. If these conditions or bounds cannot be established, the corresponding error guarantee cannot be claimed just because the rule can be evaluated.
Identify \(a\), \(b\), and the desired absolute error \(\varepsilon\).
Use a trapezoidal bound only with the required second-derivative bound; use a Simpson bound only with the required fourth-derivative bound.
Calculate the real-valued lower threshold for \(n\) from the error bound.
Round up to an integer for trapezoidal quadrature; for Simpson, round up to an even integer.
Count the \(n+1\) grid values, and remember that the bounds guarantee accuracy only when their assumptions hold.
A Common Panel-Count Mistake
Suppose the Simpson calculation in the second example produces a threshold of about \(4.041\). A tempting but incorrect choice is \(n=4\), because it is an even integer and is close to the threshold. But \(4<4.041\), so it fails the inequality. Indeed, its bound is \(2/(15\cdot4^4)=1/1920\approx0.000520833\), which exceeds the tolerance \(0.0005\). The correct choice is \(n=6\), whose bound is approximately \(0.00010288\).
Finally, keep the distinction between a guarantee and an observed error clear. The error bound is derived from assumptions and applies before the exact integral is known. An actual error can be checked only when the exact value is available. A small observed error in one example does not replace the bound when the aim is to guarantee accuracy in a new problem.
Check Your Understanding
Use the stated error bounds and panel-count rules to answer these questions.
- What derivative bound is needed to use the composite trapezoidal error bound, and what derivative bound is needed for Simpson’s rule?
- If a trapezoidal calculation gives a threshold \(n\ge 7.2\), what is the smallest permitted panel count? What if the Simpson threshold is \(n\ge7.2\)?
- For a uniform grid with \(n\) panels, how many distinct function values are needed when each node is evaluated once?
- Why does rounding a panel threshold down fail to preserve the error guarantee?
- Does an observed error smaller than the target prove that the same panel count will work for another integrand? Explain.