Tutorials › Calculus II › The Composite Simpson Rule

Quadrature and Error Bounds · Tutorial 358 of 998

The Composite Simpson Rule

You will learn to organize function values on an equally spaced grid and use the composite Simpson formula to approximate a definite integral.

Intermediate 10 min read

What You'll Learn

  • Define the step size and grid nodes for an even number of subintervals
  • Apply the composite Simpson formula with alternating interior weights
  • Understand how adding local Simpson estimates produces the composite weights
  • Work out numerical approximations and check the arithmetic
  • Identify when the rule’s grid requirements are not satisfied
  • Correct the common error of assigning weight four to every interior node

Introduction

A definite integral can describe accumulated quantity, area, or total change. When an exact antiderivative is unavailable or inconvenient, a quadrature rule uses function values at selected points to estimate the integral.

The composite Simpson rule uses equally spaced points and approximates the function over successive pairs of subintervals. Its weights follow a repeating pattern: the endpoints have weight one, alternate interior points have weight four, and the remaining interior points have weight two. Applying the rule requires an even number of subintervals.

The Grid and the Composite Rule

Let \(f\) be defined on the finite interval \([a,b]\), where \(a<b\), and suppose its values can be evaluated at the grid points. Choose an even positive integer \(n\), so \(n=2m\) for some positive integer \(m\). Divide \([a,b]\) into \(n\) equal subintervals. The step size is \(h=(b-a)/n\), and the grid nodes are \(x_i=a+ih\) for \(i=0,1,\ldots,n\).

Definition: The composite Simpson rule estimates the integral over \([a,b]\) by
$$ \int_a^b f(x)\,dx \approx \frac{h}{3}\left[ f(x_0)+f(x_n) +4\sum_{\substack{1\le i\le n-1\\ i\ \mathrm{odd}}}f(x_i) +2\sum_{\substack{2\le i\le n-2\\ i\ \mathrm{even}}}f(x_i) \right], \qquad h=\frac{b-a}{n}, $$
where \(n\) is even and the nodes are equally spaced.

The odd-indexed interior nodes receive weight four; the even-indexed interior nodes receive weight two. The two endpoints are included separately, each with weight one. For \(n=2\), there is just one interior node, \(x_1\), and the rule reduces to \(h[f(x_0)+4f(x_1)+f(x_2)]/3\). The even-indexed interior sum is empty in that case.

The rule is designed for a finite interval with equally spaced nodes and an even panel count. It is not the stated composite Simpson rule if the grid has unequal spacing or if \(n\) is odd. In either situation, a different setup or rule is needed.

Why the Weights Alternate

The composite formula comes from applying the one-third Simpson rule over each pair of adjacent subintervals. On the pair from \(x_{2j}\) to \(x_{2j+2}\), that local estimate is \(h[f(x_{2j})+4f(x_{2j+1})+f(x_{2j+2})]/3\). Each pair has width \(2h\), so its midpoint is \(x_{2j+1}\), and the local rule uses the same step \(h\) as the full grid.

Adding these local estimates explains the composite weights. The endpoint nodes \(x_0\) and \(x_n\) occur in only one pair. Each odd-indexed node is the midpoint of one pair and receives coefficient four. Every even-indexed interior node is an endpoint of two neighboring pairs, so its two coefficients of one combine to give two. This is why the weights alternate rather than assigning the same coefficient to every interior node.

1
Make the grid.
Choose an even \(n\), calculate \(h=(b-a)/n\), and list the nodes \(x_i=a+ih\).
2
Evaluate the function.
Find \(f(x_i)\) at every node, keeping exact values as long as practical.
3
Apply the weights.
Add the endpoints, four times the odd-indexed interior values, and twice the even-indexed interior values.
4
Scale and report.
Multiply the weighted sum by \(h/3\), then round only the final result and state the precision.

Worked Examples

Worked Example: A Two-Subinterval Estimate

Approximate \(\int_0^1 x^4\,dx\) with the composite Simpson rule using \(n=2\) subintervals.

First calculate the step size and nodes:

$$ h=\frac{1-0}{2}=\frac12, \qquad x_0=0,\quad x_1=\frac12,\quad x_2=1. $$

The function values are

$$ f(x_0)=0^4=0,\qquad f(x_1)=\left(\frac12\right)^4=\frac1{16},\qquad f(x_2)=1^4=1. $$

For \(n=2\), the only interior point is odd-indexed, so it receives weight four:

$$ S_2 =\frac{h}{3}\left[f(x_0)+4f(x_1)+f(x_2)\right] =\frac{1/2}{3}\left[0+4\left(\frac1{16}\right)+1\right] =\frac16\left(\frac14+1\right) =\frac16\cdot\frac54 =\frac5{24} \approx 0.208333. $$

The exact integral is \(1/5=0.2\), since an antiderivative is \(x^5/5\). Thus this estimate is not the exact integral: its difference from the exact value is \(5/24-1/5=(25-24)/120=1/120\). The computation is also checked directly by substituting the three function values into the \(n=2\) rule.

Worked Example: Four Subintervals on a Rational Function

Approximate \(\int_0^1 \frac{1}{1+x}\,dx\) using \(n=4\).

The grid spacing is \(h=(1-0)/4=1/4\), with nodes \(0,1/4,1/2,3/4,1\). Evaluating \(f(x)=1/(1+x)\) gives

$$ f(x_0)=1,\quad f(x_1)=\frac45,\quad f(x_2)=\frac23,\quad f(x_3)=\frac47,\quad f(x_4)=\frac12. $$

The odd-indexed interior values are \(4/5\) and \(4/7\); the even-indexed interior value is \(2/3\). Therefore

$$ \begin{aligned} S_4 &=\frac{1/4}{3}\left[1+\frac12 +4\left(\frac45+\frac47\right) +2\left(\frac23\right)\right]\\ &=\frac1{12}\left[\frac32+4\left(\frac{28+20}{35}\right)+\frac43\right]\\ &=\frac1{12}\left[\frac32+\frac{192}{35}+\frac43\right]\\ &=\frac1{12}\left[\frac{315+1152+280}{210}\right]\\ &=\frac{1747}{2520} \approx 0.693253968. \end{aligned} $$

The integral itself is \(\ln 2\), approximately \(0.693147181\), so the estimate is about \(0.000106787\) larger. The weighted sum and the final factor \(1/12\) reproduce \(1747/2520\), checking the calculation.

Worked Example: A Wider Interval with Four Subintervals

Approximate \(\int_0^2 \frac{1}{1+x^2}\,dx\) using \(n=4\).

Here \(h=(2-0)/4=1/2\), and the nodes are \(0,1/2,1,3/2,2\). The corresponding function values are

$$ f(x_0)=1,\quad f(x_1)=\frac45,\quad f(x_2)=\frac12,\quad f(x_3)=\frac4{13},\quad f(x_4)=\frac15. $$

Use weight four on \(x_1,x_3\), weight two on \(x_2\), and weight one on the endpoints:

$$ \begin{aligned} S_4 &=\frac{1/2}{3}\left[1+\frac15 +4\left(\frac45+\frac4{13}\right) +2\left(\frac12\right)\right]\\ &=\frac16\left[\frac65+4\left(\frac{52+20}{65}\right)+1\right]\\ &=\frac16\left[\frac65+\frac{288}{65}+1\right]\\ &=\frac16\left[\frac{78+288+65}{65}\right] =\frac{431}{390} \approx 1.105128205. \end{aligned} $$

As a check, the exact integral is \(\arctan(2)-\arctan(0)=\arctan(2)\), approximately \(1.107148718\). The Simpson estimate is about \(0.002020513\) smaller. Substituting the listed node values into the formula gives the same exact fraction \(431/390\).

A Common Weighting Error

A frequent mistake is to give every interior node weight four. The four-subinterval example with \(f(x)=1/(1+x)\) makes the error visible. If all three interior values were given weight four, the calculation would be

$$ \frac1{12}\left[1+\frac12 +4\left(\frac45+\frac23+\frac47\right)\right] = \frac1{12}\left[\frac32+\frac{856}{105}\right] = \frac{2027}{2520} \approx 0.804365079. $$

That is not the composite Simpson estimate. The middle interior node \(x_2\) has even index, so it must have weight two, not four. Correcting that coefficient subtracts \((4-2)(2/3)\) from the bracket; after multiplication by \(1/12\), the estimate decreases by \(1/9=280/2520\). Thus the corrected result is \(2027/2520-280/2520=1747/2520\), matching the full calculation above.

Practical check: For \(n=4\), the coefficient pattern must be \(1,4,2,4,1\). More generally, it begins with one, alternates four and two through the interior nodes, and ends with one.

Using the Rule Reliably

Before calculating, verify that the interval is finite, the nodes are equally spaced, and the number of subintervals is even. Then check the indexing: with \(n+1\) nodes, the endpoints are \(x_0\) and \(x_n\), while the interior indices run from \(1\) to \(n-1\). The parity of the index, not the value of the function, determines whether an interior value receives weight four or two.

Keep fractions or exact function values through the weighted sum when possible. This reduces avoidable rounding error and makes it easier to find arithmetic mistakes. If decimal values are needed, calculate with adequate precision and round only the final estimate. The rule supplies a numerical approximation; it does not by itself state how large the error is. An error bound requires additional information about the function and is a separate question.

The method is useful because it replaces an integral by a finite, organized combination of function evaluations. The paired-subinterval structure is especially important: it explains both the alternating weights and the even-panel requirement. Once the grid and weights are set correctly, the calculation is a repeatable process rather than a guess about which values to emphasize.

Check Your Understanding

Use the definitions and weighting pattern to answer the following questions.

  1. For \([a,b]=[2,5]\) and \(n=6\), what are \(h\) and the general formula for the nodes \(x_i\)?
  2. For \(n=6\), which interior indices receive weight four, and which receive weight two?
  3. Why does an even-indexed interior node receive weight two when the local estimates over adjacent pairs are added?
  4. What is the specific weighting error in the pattern \(1,4,4,4,1\) for four subintervals?
  5. Can the stated composite Simpson rule be applied unchanged to five equally spaced subintervals? Explain which condition fails.