3H

The trapezoidal rule

Approximating a definite integral with the trapezoidal rule using equally spaced function values, and using concavity to decide whether the estimate is too big or too small.

Some integrals can't be done with a primitive, such as $\displaystyle\int_0^1 \sqrt{1 + x^3}\,dx$. And often there is no formula at all, only measurements: a flow rate read every two hours, or a river's depth measured every metre. The trapezoidal rule estimates the area from a few function values.

One trapezium

Join the two end points of the curve with a straight line. The region under the line is a trapezium with parallel sides $f(a)$ and $f(b)$ and width $b - a$.

Trapezoidal rule, one interval
$$\int_a^b f(x)\,dx \approx \frac{b - a}{2}\big(f(a) + f(b)\big)$$

Several subintervals

One trapezium is usually crude. Split $a \le x \le b$ into $n$ equal subintervals of width $h = \dfrac{b - a}{n}$, and add the trapezia. Every inside value is the right side of one trapezium and the left side of the next, so it is counted twice.

Trapezoidal rule, n subintervals
$$\int_a^b f(x)\,dx \approx \frac{h}{2}\Big(y_0 + 2(y_1 + y_2 + \cdots + y_{n-1}) + y_n\Big)$$

Remember it as "ends once, middles twice". With $n$ subintervals there are $n + 1$ function values.

Example 1●●

Use the trapezoidal rule with $4$ subintervals to estimate $\displaystyle\int_1^3 \dfrac1x\,dx$, correct to four decimal places.

$h = 0.5$: $\;x = 1, 1.5, 2, 2.5, 3$ give $y = 1, \tfrac23, \tfrac12, \tfrac25, \tfrac13$.
h = (3 − 1) ÷ 4. List the x-values and the function values.
$\approx \dfrac{0.5}{2}\left(1 + 2\left(\tfrac23 + \tfrac12 + \tfrac25\right) + \tfrac13\right)$
Ends once, middles twice.
$= 0.25 \times (1.3333 + 3.1333) \approx 1.1167$

The exact answer turns out to be $\ln 3 \approx 1.0986$ (Chapter 5), so the estimate is a little too big. The next part explains why.

Example 2: data in a table●●

Water flows into a dam. The flow rate $R$ (in ML per hour) is measured every $2$ hours:

$t$ (h)$0$$2$$4$$6$$8$
$R$$0$$30$$45$$40$$20$

Estimate the total volume that flowed in over the $8$ hours.

$V \approx 1 \times \big(0 + 2(30 + 45 + 40) + 20\big)$
Total volume is the area under the rate graph. Here h = 2, so h/2 = 1.
$= 250$ ML

Too big or too small?

Each trapezium has a straight top. If the curve is concave up, it sags below every chord, so the trapezia include extra area: the rule overestimates. If the curve is concave down, it bulges above every chord, and the rule underestimates.

Trapezia under y = x²

The shaded region is the trapezoidal estimate of the integral from 0 to 2.

Try this

Is the estimate too big or too small, and where can you see the extra area? Increase $n$ until the error is below $0.01$. How many subintervals did you need?

Lorenz curves and the Gini coefficient

Economists measure inequality with a Lorenz curve. Its $x$-value is a fraction of the population, from the poorest up, and its $y$-value is the fraction of total income that group earns. It runs from $(0, 0)$ to $(1, 1)$. If everyone earned the same, it would be the line of equality $y = x$. Real Lorenz curves sag below that line.

Gini coefficient
$$G = \frac{\text{area between } y = x \text{ and the Lorenz curve}}{\text{area under } y = x} = 1 - 2\int_0^1 L(x)\,dx$$

The area under $y = x$ is $\tfrac12$, which is where the formula comes from. $G = 0$ means perfect equality; values near $1$ mean a few people earn almost everything.

Example 3●●●

Survey data give these points on a Lorenz curve. Estimate the Gini coefficient using the trapezoidal rule.

poorest fraction $x$$0$$0.2$$0.4$$0.6$$0.8$$1$
income share $L$$0$$0.05$$0.15$$0.3$$0.55$$1$
$\displaystyle\int_0^1 L\,dx \approx 0.1\big(0 + 2(0.05 + 0.15 + 0.3 + 0.55) + 1\big) = 0.31$
Five subintervals of width 0.2, so h/2 = 0.1.
$G \approx 1 - 2 \times 0.31 = 0.38$

A Lorenz curve is concave up, so the trapezoidal estimate of the area under it is a little too big, which makes this Gini estimate a little too small.

Your turn

Estimate $\displaystyle\int_0^1 \sqrt{1 + x^2}\,dx$ with $2$ subintervals, to two decimal places.

Show the working

$h = 0.5$, and the values are $1$, $\sqrt{1.25} \approx 1.1180$ and $\sqrt2 \approx 1.4142$. Estimate $= 0.25(1 + 2 \times 1.1180 + 1.4142) \approx 1.16$.

Flashcards
Trapezoidal rule
$\dfrac{h}{2}\big(y_0 + 2(y_1 + \cdots + y_{n-1}) + y_n\big)$
Concave up curve
The trapezoidal rule overestimates.
Gini coefficient
$1 - 2\displaystyle\int_0^1 L(x)\,dx$
Practice
  1. Use one trapezium to estimate $\displaystyle\int_0^2 x^2\,dx$.

  2. Use $4$ subintervals to estimate $\displaystyle\int_0^2 x^2\,dx$.

  3. The exact value of $\displaystyle\int_0^2 x^2\,dx$ is $\tfrac83$. The estimate $2.75$ is too big because:

  4. Find $h$ when the trapezoidal rule is used on $1 \le x \le 4$ with $6$ subintervals.

  5. The trapezoidal rule with $n$ subintervals uses how many function values?

  6. Estimate $\displaystyle\int_1^3 \dfrac1x\,dx$ with $4$ subintervals, to four decimal places.

  7. A flow rate (ML/h) is $0, 30, 45, 40, 20$ at $t = 0, 2, 4, 6, 8$ hours. Estimate the total flow in ML.

  8. A Lorenz curve is modelled by $L(x) = x^2$. Find the Gini coefficient, to two decimal places.

  9. Exam style: Lorenz curve data are $L = 0, 0.05, 0.15, 0.3, 0.55, 1$ at $x = 0, 0.2, 0.4, 0.6, 0.8, 1$. Use the trapezoidal rule to estimate the Gini coefficient.

  10. Exam style: the trapezoidal estimate of $\displaystyle\int_0^2 x^2\,dx$ with $n$ subintervals has error $\dfrac{4}{3n^2}$. Find the least $n$ that makes the error less than $0.01$.

Formula sheet