Tutorials › Calculus II › A Quadrature Accuracy and Cost Workshop

Quadrature and Error Bounds · Tutorial 373 of 998

A Quadrature Accuracy and Cost Workshop

Use derivative-based error bounds to select a quadrature rule and panel count, then compare the accuracy guarantee with the computational cost.

Intermediate 10 min read

What You'll Learn

  • Identify the smoothness and derivative bounds required for trapezoidal and Simpson error guarantees
  • Calculate a panel count that meets a prescribed absolute-error target
  • Enforce Simpson’s even-panel requirement when rounding a panel count
  • Compare rules by the number of function evaluations required
  • Distinguish a guaranteed error bound from the error observed in a particular calculation

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.

Trapezoidal error bound: If \(f\) has a continuous second derivative on \([a,b]\), and \(|f''(x)|\le M_2\) throughout the interval, then $$ \left|\int_a^b f(x)\,dx-T_n\right| \le \frac{M_2(b-a)^3}{12n^2}. $$
Simpson error bound: If \(f\) has a continuous fourth derivative on \([a,b]\), and \(|f^{(4)}(x)|\le M_4\) throughout the interval, then, for an even positive integer \(n\), $$ \left|\int_a^b f(x)\,dx-S_n\right| \le \frac{M_4(b-a)^5}{180n^4}. $$

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.

$$ n\ge \sqrt{\frac{M_2(b-a)^3}{12\varepsilon}} \qquad\text{(trapezoidal)} $$
$$ n\ge \left(\frac{M_4(b-a)^5}{180\varepsilon}\right)^{1/4} \qquad\text{(Simpson)} $$

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

$$ \left|\int_0^1x^2\,dx-T_n\right| \le \frac{2}{12n^2} =\frac{1}{6n^2}. $$

Require this to be no greater than \(0.01\):

$$ \frac{1}{6n^2}\le 0.01 \quad\Longrightarrow\quad n^2\ge \frac{1}{0.06} =\frac{50}{3} \approx 16.667. $$

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

$$ T_5 =0.2\left(\frac{0+1}{2}+0.04+0.16+0.36+0.64\right) =0.2(0.5+1.2) =0.34. $$

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

$$ \left|\int_0^1x^4\,dx-S_n\right| \le \frac{24}{180n^4} =\frac{2}{15n^4}. $$

Imposing the tolerance gives

$$ \frac{2}{15n^4}\le 0.0005 \quad\Longrightarrow\quad n^4\ge \frac{2}{0.0075} =\frac{800}{3} \approx266.667. $$

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

$$ 0+1296 +4(1+81+625) +2(16+256) =1296+2828+544 =4668. $$

Consequently,

$$ S_6 =\frac{h}{3}\cdot\frac{4668}{1296} =\frac{1}{18}\cdot\frac{4668}{1296} =\frac{389}{1944} \approx0.20010288. $$

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

$$ T_n =\frac{1}{n}\left(\frac12+\sum_{k=1}^{n-1}\frac{k^4}{n^4}\right) =\frac15+\frac{1}{3n^2}-\frac{1}{30n^4}, $$

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

$$ T_{32} =\frac15+\frac{1}{3072}-\frac{1}{31457280} \approx0.200325489. $$

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

$$ S_4 =\frac{1}{12}\left(1+4\left(\frac{1+81}{256}\right)+2\left(\frac{1}{16}\right)\right) =\frac{1}{12}\left(\frac{77}{32}\right) =\frac{77}{384} \approx0.200520833. $$

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.

1
Record the interval and tolerance.
Identify \(a\), \(b\), and the desired absolute error \(\varepsilon\).
2
Check available smoothness information.
Use a trapezoidal bound only with the required second-derivative bound; use a Simpson bound only with the required fourth-derivative bound.
3
Solve the appropriate inequality.
Calculate the real-valued lower threshold for \(n\) from the error bound.
4
Apply the rule’s panel constraint.
Round up to an integer for trapezoidal quadrature; for Simpson, round up to an even integer.
5
Compare the required work.
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\).

Takeaway: First round upward to meet the real-valued threshold. Then, for Simpson’s rule, move to the next even count if the rounded count is odd. A panel count that merely looks close is not enough to certify the target.

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.

  1. What derivative bound is needed to use the composite trapezoidal error bound, and what derivative bound is needed for Simpson’s rule?
  2. 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\)?
  3. For a uniform grid with \(n\) panels, how many distinct function values are needed when each node is evaluated once?
  4. Why does rounding a panel threshold down fail to preserve the error guarantee?
  5. Does an observed error smaller than the target prove that the same panel count will work for another integrand? Explain.

Test yourself: Calculus II final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon