Tutorials › Calculus II › Deriving Trapezoidal Weights

Quadrature and Error Bounds · Tutorial 352 of 998

Deriving Trapezoidal Weights

Learn how panelwise linear interpolation produces the composite trapezoidal formula and why its interior nodes receive twice the weight of the endpoints.

Intermediate 9 min read

What You'll Learn

  • Write the linear interpolant between two consecutive grid values.
  • Integrate a panel interpolant to obtain its trapezoidal contribution.
  • Sum panel contributions on a uniform grid.
  • Explain why endpoint weights are half the interior weights.
  • Check the formula on sampled and linear functions.
  • Avoid miscounting shared panel endpoints.

From Panel Areas to Weights

The composite trapezoidal rule approximates an integral by dividing an interval into panels and replacing the function on each panel by the straight line through its endpoint values. The familiar endpoint and interior weights are not arbitrary: they result from integrating those lines and adding the contributions.

The key detail is that adjacent panels share a node. A value at an interior node contributes to both neighboring panels, while each endpoint contributes to only one. This difference accounts for the weights in the composite formula.

Grid and Piecewise Linear Interpolant

Let \(a<b\), and divide \([a,b]\) into \(n\) equal panels, where \(n\) is a positive integer. The grid points are \(x_i=a+ih\), for \(i=0,1,\ldots,n\), with panel width \(h=(b-a)/n\). Write \(y_i=f(x_i)\) for the sampled function values.

Definition: On the panel \([x_i,x_{i+1}]\), the linear interpolant is the unique linear function that takes the values \(y_i\) at \(x_i\) and \(y_{i+1}\) at \(x_{i+1}\). For equal panel width \(h\), it is \[ L_i(x)=y_i\frac{x_{i+1}-x}{h}+y_{i+1}\frac{x-x_i}{h}. \]

At \(x=x_i\), the first coefficient is \(1\) and the second is \(0\), so \(L_i(x_i)=y_i\). At \(x=x_{i+1}\), those coefficients are \(0\) and \(1\), so \(L_i(x_{i+1})=y_{i+1}\). Between the endpoints, this formula describes the straight line connecting the sampled values.

The piecewise linear interpolant is made by using \(L_i\) on every panel. Its integral is the sum of the integrals of the separate panel interpolants. If \(f\) is integrable on \([a,b]\), this gives an approximation to \(\int_a^b f(x)\,dx\); the construction itself only requires the chosen grid values.

Integrating One Panel

To find the contribution from a single panel, use the scaled coordinate \(t=(x-x_i)/h\). As \(x\) moves from \(x_i\) to \(x_{i+1}\), \(t\) moves from \(0\) to \(1\), and \(dx=h\,dt\). In this coordinate, the interpolant is \(L_i(x)=(1-t)y_i+ty_{i+1}\).

$$ \begin{aligned} \int_{x_i}^{x_{i+1}}L_i(x)\,dx &=h\int_0^1\bigl((1-t)y_i+ty_{i+1}\bigr)\,dt\\ &=h\left(y_i\int_0^1(1-t)\,dt+y_{i+1}\int_0^1t\,dt\right)\\ &=h\left(\frac{y_i}{2}+\frac{y_{i+1}}{2}\right)\\ &=\frac{h}{2}(y_i+y_{i+1}). \end{aligned} $$

This is the trapezoidal contribution from one panel: its width multiplied by the average of the two endpoint heights. The calculation also explains why each endpoint of a single panel receives half of that panel's width as its coefficient.

Panel formula: The integral of the linear interpolant on \([x_i,x_{i+1}]\) is \(h(y_i+y_{i+1})/2\). This follows from integrating the interpolant, not from assuming that the original function itself is linear.

Summing the Panels Gives the Weights

Add the panel contributions for \(i=0,1,\ldots,n-1\). Each panel contributes \(h/2\) times the sum of its two endpoint values. In the resulting sum, \(y_0\) appears only in the first panel and \(y_n\) only in the last panel. Every other value \(y_i\), where \(1\le i\le n-1\), is shared by the panels on its left and right, so it appears twice.

$$ \begin{aligned} \int_a^b L(x)\,dx &=\sum_{i=0}^{n-1}\frac{h}{2}(y_i+y_{i+1})\\ &=\frac{h}{2}\left(y_0+2\sum_{i=1}^{n-1}y_i+y_n\right). \end{aligned} $$

Replacing \(y_i\) by \(f(x_i)\) gives the composite trapezoidal approximation to the integral of \(f\). The expression is called composite because it combines the trapezoidal contributions from all the panels. The derivation establishes the weights directly: the endpoints have coefficient \(h/2\), and each interior node has coefficient \(h\).

Derived composite formula: For a uniform grid with \(n\) panels and width \(h=(b-a)/n\), integrating the piecewise linear interpolant gives \[ T_n=\frac{h}{2}\left(f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right). \] Here \(T_n\) is the integral of the piecewise linear interpolant, used as an approximation to \(\int_a^b f(x)\,dx\).

Complete Derivation in Steps

1
Interpolate on each panel.
Join the two sampled values at the ends of each panel with a straight line.
2
Integrate that line.
The panel integral is \(h/2\) times the sum of its endpoint values.
3
Add all panel integrals.
Linearity of integration makes the integral of the piecewise interpolant the sum of its panel integrals.
4
Collect coefficients.
Each endpoint occurs once in the panel sum; each interior value occurs in two adjacent panels.

This argument justifies the formula: the weights record how many panel contributions include each grid value. It also shows the scope of the result. The rule is exactly the integral of the piecewise linear interpolant on the specified uniform grid. It is not, in general, an exact formula for the integral of a curved function.

Worked Examples

Worked Example: Deriving the Approximation for \(f(x)=x^2\)

Approximate the integral of \(f(x)=x^2\) on \([0,2]\) using four equal panels. First, \(n=4\) and \(h=(2-0)/4=1/2\). The nodes and values are:

$$ \begin{array}{c|ccccc} x_i&0&\frac12&1&\frac32&2\\ \hline f(x_i)&0&\frac14&1&\frac94&4 \end{array} $$

The global weights are \(h/2=1/4\) at the two endpoints and \(h=1/2\) at the three interior nodes. Therefore,

$$ \begin{aligned} T_4 &=\frac14(0)+\frac12\left(\frac14\right) +\frac12(1)+\frac12\left(\frac94\right)+\frac14(4)\\ &=0+\frac18+\frac12+\frac98+1\\ &=\frac{1+4+9}{8}+1\\ &=\frac{14}{8}+1=\frac74+1=\frac{11}{4}. \end{aligned} $$

Check by adding the four panel contributions separately:

$$ \begin{aligned} \frac14\left(0+\frac14\right)&=\frac1{16},& \frac14\left(\frac14+1\right)&=\frac5{16},\\ \frac14\left(1+\frac94\right)&=\frac{13}{16},& \frac14\left(\frac94+4\right)&=\frac{25}{16}. \end{aligned} $$

Their sum is \((1+5+13+25)/16=44/16=11/4\), matching the global-weight calculation. For comparison, the exact integral is \([x^3/3]_0^2=8/3\), so this example also illustrates that the rule need not give the exact integral of a nonlinear function.

Worked Example: A Linear Function on Two Panels

Use two equal panels to approximate \(\int_1^2(3x-2)\,dx\). Here \(n=2\), \(h=(2-1)/2=1/2\), and the nodes are \(x_0=1\), \(x_1=3/2\), and \(x_2=2\). The sampled values are

$$ f(1)=3(1)-2=1,\qquad f\left(\frac32\right)=3\left(\frac32\right)-2=\frac92-2=\frac52,\qquad f(2)=3(2)-2=4. $$

Applying the derived weights gives

$$ \begin{aligned} T_2 &=\frac{h}{2}\left(f(x_0)+2f(x_1)+f(x_2)\right)\\ &=\frac14\left(1+2\left(\frac52\right)+4\right)\\ &=\frac14(1+5+4)=\frac{10}{4}=\frac52. \end{aligned} $$

Check directly from the two panel contributions. Each is \(h/2=1/4\) times the sum of its endpoint values, so they are \((1/4)(1+5/2)=7/8\) and \((1/4)(5/2+4)=13/8\). Their sum is \(20/8=5/2\). Since the function is linear, each panel interpolant is the function itself. The exact integral confirms the result:

$$ \int_1^2(3x-2)\,dx =\left[\frac32x^2-2x\right]_1^2 =2-\left(-\frac12\right) =\frac52. $$

Worked Example: Recovering Weights from Three Panel Contributions

Suppose a piecewise linear interpolant on \([0,3]\) has unit-width panels and node values \(y_0=2\), \(y_1=0\), \(y_2=4\), and \(y_3=1\). Integrating each panel gives

$$ \begin{aligned} \text{panel }[0,1]&:\quad \frac12(2+0)=1,\\ \text{panel }[1,2]&:\quad \frac12(0+4)=2,\\ \text{panel }[2,3]&:\quad \frac12(4+1)=\frac52. \end{aligned} $$

Adding these values gives \(1+2+5/2=11/2\). The global formula gives the same result:

$$ \begin{aligned} \frac12\left(y_0+2y_1+2y_2+y_3\right) &=\frac12\left(2+2(0)+2(4)+1\right)\\ &=\frac12(11)=\frac{11}{2}. \end{aligned} $$

The check is the direct sum of the panel integrals, which agrees with the weighted expression. In particular, \(y_1\) and \(y_2\) each receive coefficient \(1\): each appears twice with panel coefficient \(1/2\). The endpoint values each retain coefficient \(1/2\).

A Common Weighting Mistake

A frequent mistake is to assign the same half-panel coefficient to every node after summing the panels. That overlooks the fact that each interior node belongs to two panels. For the values in the preceding example, this incorrect calculation would be

$$ \frac12(2+0+4+1)=\frac72, $$

which does not equal the panel sum \(11/2\). The correction is to add the panel contributions before collecting coefficients:

$$ \frac12(2+0)+\frac12(0+4)+\frac12(4+1) =\frac12(2+2(0)+2(4)+1)=\frac{11}{2}. $$

The zero value at the first interior node does not contribute numerically in this example, but it still has weight \(1\). The coefficient comes from its occurrence in both adjacent panels, not from the particular value recorded there.

Why the Derivation Is Useful

The derivation lets you rebuild the composite formula rather than memorize a pattern. Begin with a panel: its straight-line interpolant integrates to half the panel width times the sum of its endpoint values. Then sum the panels and count how often each node occurs. The endpoint weights follow from one occurrence, and the interior weights follow from two.

This way of reasoning is also a reliable check when applying the rule: expand the weighted expression or add the panel contributions, and confirm that every node has been counted with the appropriate multiplicity. The conclusion here concerns the weights and the integral of the piecewise linear interpolant; questions about the size or direction of the approximation error require additional results.

Check Your Understanding

Use the panel-integral derivation to answer these questions. For calculation questions, show the panel contributions as well as the collected weights.

  1. Why does an endpoint value appear once in the panel sum, while an interior value appears twice?
  2. For a uniform grid of width \(h\), what is the integral of the linear interpolant on one panel with endpoint values \(u\) and \(v\)?
  3. Write the composite weights for a grid with four panels, identifying the coefficients of the two endpoints and the three interior nodes.
  4. For unit-width panels and node values \(1,3,2\), calculate the sum of the two panel contributions and then collect the global weights.
  5. Does integrating the piecewise linear interpolant necessarily give the exact integral of the original function? Explain what the derivation guarantees.