Tutorials › Calculus II › The Composite Trapezoidal Rule

Quadrature and Error Bounds · Tutorial 351 of 998

The Composite Trapezoidal Rule

Learn to apply the composite trapezoidal rule to equally spaced function values and check that the panel widths and weights are used correctly.

Intermediate 10 min read

What You'll Learn

  • Identify the number of panels, nodes, and common panel width.
  • Write the composite trapezoidal formula in equivalent forms.
  • Apply the half-weight to endpoints and full weights to interior nodes.
  • Compute an approximation from a function formula or a table of values.
  • Check a calculation by adding the individual panel estimates.
  • Recognize a common error caused by using the wrong node weights.

Approximating an Integral from Equally Spaced Values

A definite integral can represent a total accumulated quantity, such as distance from velocity or mass from a density. Sometimes the function is known only at selected input values, or evaluating an exact antiderivative is inconvenient. A numerical quadrature rule uses function values at chosen points to estimate the integral.

The composite trapezoidal rule is built from a sequence of adjacent trapezoid estimates. Its key bookkeeping feature is that the two endpoint values receive half-weights, while each interior value receives a full weight. The rule applies when the nodes divide the interval into equal-width panels.

Definition: Let \(f\) be continuous on \([a,b]\), where \(a<b\). Choose a positive integer \(n\), the number of panels, and set \(h=(b-a)/n\). The equally spaced nodes are \(x_i=a+ih\), for \(i=0,1,\ldots,n\). The composite trapezoidal approximation to \(\int_a^b f(x)\,dx\) is
$$ T_n=\frac{h}{2}\left[f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right]. $$
Equivalently, \(T_n=h\left[\frac12f(x_0)+\sum_{i=1}^{n-1}f(x_i)+\frac12f(x_n)\right]\). If \(n=1\), the interior sum is empty and is taken to be zero.

There are \(n\) panels but \(n+1\) nodes: the endpoints and the points between them. The common width \(h\) is positive because \(b>a\). The formula uses the values of \(f\) at those nodes; it does not require evaluating \(f\) between nodes in order to calculate \(T_n\).

Why the Endpoint and Interior Weights Differ

On one panel \([x_i,x_{i+1}]\), the trapezoid estimate is the panel width multiplied by the average of the two endpoint heights: \( \frac{h}{2}\left[f(x_i)+f(x_{i+1})\right] \). The composite rule adds these estimates for all \(n\) adjacent panels. This addition explains the weights: an endpoint belongs to just one panel, but an interior node is shared by two neighboring panels.

Justification: Adding the single-panel estimates gives
$$ \begin{aligned} T_n &=\frac{h}{2}\sum_{i=0}^{n-1}\left[f(x_i)+f(x_{i+1})\right]\\ &=\frac{h}{2}\left[f(x_0)+2f(x_1)+2f(x_2)+\cdots+2f(x_{n-1})+f(x_n)\right]. \end{aligned} $$
The first node appears only in the first panel, and the last node appears only in the final panel. Each interior node appears once in each of its two adjoining panels, so its value occurs twice in the sum. This is exactly the composite formula.

This argument also gives a practical check: a calculation using the weighted formula should agree with the sum of the individual panel estimates. The formula estimates the integral; it is not, in general, an exact identity for the integral.

A Reliable Calculation Procedure

Before substituting values, determine which values are endpoints and which are interior. A useful procedure is:

1
Count the panels.
Record \(n\), and confirm that the given data contain \(n+1\) node values.
2
Find the common width.
Calculate \(h=(b-a)/n\), or verify the spacing in a supplied table.
3
Assign the weights.
Use one-half for each endpoint and weight one for every interior value in the equivalent \(h[\cdots]\) form.
4
Calculate and check.
Evaluate the weighted sum, then compare it with the sum of the separate panel estimates when practical.

Worked Examples

Worked Example: Approximate the Integral of \(x^2\)

Use four equal panels to approximate \(\int_0^2 x^2\,dx\). First, \(n=4\), so the panel width is

$$ h=\frac{2-0}{4}=\frac12. $$

The nodes are \(x_i=0+i/2\), giving \(0,\frac12,1,\frac32,2\). Evaluating \(f(x)=x^2\) gives the values \(0,\frac14,1,\frac94,4\). There are five values, as required for four panels.

Apply the endpoint and interior weights:

$$ \begin{aligned} T_4 &=\frac{1}{2}\left[\frac12(0)+\frac14+1+\frac94+\frac12(4)\right]\\ &=\frac12\left[\frac14+1+\frac94+2\right]\\ &=\frac12\left[\frac{1+4+9+8}{4}\right]\\ &=\frac12\cdot\frac{22}{4} =\frac{11}{4}=2.75. \end{aligned} $$

Check by adding the four panel estimates. Each panel has width \(1/2\), so its trapezoid estimate is \(1/4\) times the sum of its endpoint values:

$$ \begin{aligned} T_4 &=\frac14\left(0+\frac14\right) +\frac14\left(\frac14+1\right) +\frac14\left(1+\frac94\right) +\frac14\left(\frac94+4\right)\\ &=\frac{1}{16}+\frac{5}{16}+\frac{13}{16}+\frac{25}{16} =\frac{44}{16} =\frac{11}{4}. \end{aligned} $$

The panel check agrees with the weighted formula. The result is an approximation to the integral, not a claim that the integral itself equals \(11/4\).

Worked Example: Use Function Values at the Nodes

Approximate \(\int_0^1 \frac{1}{1+x^2}\,dx\) using four equal panels. Here \(h=(1-0)/4=1/4\), and the nodes are \(0,\frac14,\frac12,\frac34,1\). The corresponding function values are

$$ f(0)=1,\quad f\left(\frac14\right)=\frac{16}{17},\quad f\left(\frac12\right)=\frac45,\quad f\left(\frac34\right)=\frac{16}{25},\quad f(1)=\frac12. $$

Use the half-weights at the endpoints and full weights at the three interior nodes:

$$ \begin{aligned} T_4 &=\frac18\left[1+2\left(\frac{16}{17}+\frac45+\frac{16}{25}\right)+\frac12\right]\\ &=\frac18\left[1+\frac{32}{17}+\frac85+\frac{32}{25}+\frac12\right]. \end{aligned} $$

For an independent check, calculate each panel separately. Every panel has width \(1/4\), so the multiplier is \(h/2=1/8\):

$$ \begin{aligned} T_4 &=\frac18\left(1+\frac{16}{17}\right) +\frac18\left(\frac{16}{17}+\frac45\right) +\frac18\left(\frac45+\frac{16}{25}\right) +\frac18\left(\frac{16}{25}+\frac12\right)\\ &=\frac{33}{136}+\frac{37}{170}+\frac{9}{50}+\frac{57}{400}. \end{aligned} $$

To add these fractions, use denominator \(6800\):

$$ \frac{33}{136}+\frac{37}{170}+\frac{9}{50}+\frac{57}{400} = \frac{1650+1480+1224+969}{6800} =\frac{5323}{6800} \approx 0.782794. $$

Thus the approximation is \(\frac{5323}{6800}\), or \(0.782794\) to six decimal places. The panel calculations agree with the composite formula.

Worked Example: An Exact Check with a Linear Function

Use three equal panels to approximate \(\int_1^3 (2x+1)\,dx\). The width is \(h=(3-1)/3=2/3\), and the nodes are \(1,\frac53,\frac73,3\). The function values are

$$ f(1)=3,\quad f\left(\frac53\right)=\frac{13}{3},\quad f\left(\frac73\right)=\frac{17}{3},\quad f(3)=7. $$

There are two interior values. Substitution gives

$$ \begin{aligned} T_3 &=\frac{2/3}{2}\left[3+2\left(\frac{13}{3}+\frac{17}{3}\right)+7\right]\\ &=\frac13\left[3+2(10)+7\right]\\ &=\frac13(30)=10. \end{aligned} $$

Check against the exact integral using the antiderivative \(x^2+x\):

$$ \int_1^3(2x+1)\,dx =[x^2+x]_1^3 =(9+3)-(1+1)=12-2=10. $$

The trapezoidal value agrees with the exact value in this example. This check verifies the arithmetic; it does not mean every function will give an exact result with the rule.

Common Weighting Mistake

A frequent error is to use the same coefficient for every node, as though the composite rule were simply the panel width times half the sum of all the listed values. For the first example, that incorrect calculation would be

$$ \frac{h}{2}\left(0+\frac14+1+\frac94+4\right) =\frac14\cdot\frac{15}{2} =\frac{15}{8}=1.875. $$

This is not the composite trapezoidal rule: it gives the interior values only one occurrence, although each belongs to two adjacent panel estimates. The correction is to double the interior values inside the \(h/2\) formula, or equivalently to use \(h\) times the interior sum and half of each endpoint value. For the same data, the correct result is \(11/4=2.75\).

Another practical safeguard is to count the entries before calculating. With \(n\) panels, there must be \(n+1\) node values: two endpoints and \(n-1\) interior values. If the spacing is not equal, the common-\(h\) formula above does not apply as written.

Using the Rule Carefully

The composite trapezoidal rule turns a list of equally spaced function values into one estimate for an integral. Its weights follow directly from adding the panel estimates: endpoints occur once, and interior nodes occur twice. Keeping that structure visible helps prevent both missing values and incorrect weights.

When applying the rule, report the interval, number of panels, width, and approximation clearly. Keep exact fractions during the calculation when they are manageable, and round only the final decimal if one is needed. The rule provides an estimate; establishing how accurate that estimate is requires additional error analysis.

Check Your Understanding

Answer these questions using the definitions and examples above.

  1. If an interval is divided into seven equal panels, how many nodes are there, and how many interior nodes?
  2. Write the composite trapezoidal formula for \(n\) panels, identifying the endpoint and interior weights.
  3. For nodes \(x_0,\ldots,x_n\), why does each interior function value receive twice the coefficient of an endpoint in the \(h/2\) form?
  4. What is the common panel width when \([a,b]\) is divided into \(n\) equal panels?
  5. Explain why using the same weight for every node gives an incorrect composite trapezoidal calculation.