Numerical Integration

No antiderivative? Trapezia still get close.

An area with no formula

The curve y = e^(−x²) is the bell shape behind the normal distribution. No combination of powers, exponentials, logarithms and trigonometric functions differentiates to e^(−x²), so its integral cannot be worked by finding an antiderivative.

The area under it from x = −1.5 to x = 1.5 is still a definite number, about 1.7124. It can be estimated as closely as needed by cutting the region into strips and adding their areas.

xy

The gold curve y = e^(−x²), shaded from x = −1.5 to x = 1.5. The curve is 1 high at x = 0 and about 0.105 high at each end of the shading. The shaded area is about 1.7124.

Strips with slanted tops

Split the interval from a to b into n strips of equal width h = (b − a)/n. Over each strip, join the two points of the curve at its edges with a straight line. The strip becomes a trapezium, whose area is its width times the average of its two parallel sides: h × (left height + right height) ÷ 2.

For the bell from −1.5 to 1.5 with n = 3, h = 1 and the heights are taken at x = −1.5, −0.5, 0.5 and 1.5. They are e^(−2.25) ≈ 0.1054, e^(−0.25) ≈ 0.7788, 0.7788 and 0.1054. The three trapezia have areas 0.4421, 0.7788 and 0.4421, which add to 1.6630.

xy

Three strips, each 1 wide, under the gold curve y = e^(−x²). Each top is the straight line between the curve’s heights at the strip’s two edges. Together they cover 1.6630, short of the true 1.7124.

The formula

Number the heights y₀, y₁, …, yₙ from left to right. Adding the strips gives (h/2)(y₀ + y₁) + (h/2)(y₁ + y₂) + … + (h/2)(yₙ₋₁ + yₙ). Every inner height is the right side of one strip and the left side of the next, so it appears twice, while y₀ and yₙ appear once each.

That is the trapezium rule: T = (h/2)(y₀ + 2y₁ + 2y₂ + … + 2yₙ₋₁ + yₙ). For the bell with n = 3 it gives (1/2)(0.1054 + 2 × 0.7788 + 2 × 0.7788 + 0.1054) = (1/2)(3.3260) = 1.6630, as before.

n strips need n + 1 heights. With heights 0, 1 and 4 at h = 1, the rule gives (1/2)(0 + 2 × 1 + 4) = 3.

Thinner strips

More strips follow the curve more closely. For the bell from −1.5 to 1.5: with 3 strips the estimate is 1.6630, 0.0494 short; with 6 strips it is 1.6994, 0.0130 short; with 8 it is 1.7050; with 12 it is 1.7091, 0.0033 short; with 24 it is 1.7116, 0.0008 short.

Each time the strips are halved in width the error falls to about a quarter: 0.0494 to 0.0130, then 0.0130 to 0.0033, then 0.0033 to 0.0008. The gap between a chord and a curve shrinks with the square of the strip width.

xy

Eight strips, each 0.375 wide, under the gold curve y = e^(−x²). Their tops lie almost on the curve, and together they cover 1.7050, short of 1.7124 by 0.0074.

Too much or too little

Which way the rule errs depends on the bend. Where a curve bends upward, each chord lies above the curve, so each trapezium holds a sliver too much and the rule overestimates. For x² from 0 to 2 with h = 1, the heights are 0, 1 and 4, the rule gives 3, and the exact area is 8/3, so the error is 1/3 too much. With h = 0.5 the heights are 0, 0.25, 1, 2.25 and 4, the rule gives 2.75, and the error is 1/12, a quarter of 1/3.

Where a curve bends downward, each chord lies below it and the rule underestimates. For √x from 0 to 4 with h = 1 the heights are 0, 1, 1.4142, 1.7321 and 2, and the rule gives 5.1463, short of the exact 16/3 ≈ 5.3333.

The bell bends downward in its middle, between x = −0.707 and x = 0.707, and upward outside that. The middle strips carry most of the area, so their shortfall outweighs the excess in the outer strips, and every estimate above came out low.

xy

Two strips, each 1 wide, under the gold curve y = x² from 0 to 2. The curve bends upward, so each straight top runs above it. The strips cover 3, which is 1/3 more than the exact 8/3.

0.511.5xy = e^(−x²)estimate 0.8525 · exact area 0.8562|E| = 0.0037n = 4trapezium ruleSimpson's rule

each chord cuts across the bend, so the error falls only as 1/n²: |E| = 0.0037 with n = 4

Get the error under 0.001 with 4 strips

The trapezium rule with 4 strips on y = e^(−x²) from 0 to 1.5. The estimate is 0.8525 against the exact 0.8562, an error of 0.0037, tinted between the chords and the curve. Drag n to 8: the estimate becomes 0.8553 and the error 0.0009, about a quarter.

The usual mistakes

Adding the heights as they are. With heights 0, 1 and 4 at h = 1 that gives 5; the inner height counts twice and the bracket is then multiplied by h/2, which gives 3.

Halving without doubling. (1/2)(0 + 1 + 4) = 2.5 forgets that the inner height belongs to two strips.

Doubling the end heights as well. y₀ and yₙ each belong to one strip only.

Taking h as the width divided by the number of heights. Four strips from 0 to 2 have h = 0.5 and five heights.

Five readings across a roof

In the application below, the trapezium rule runs on five readings of a curved roof taken 4 meters apart. It halves the two readings at the walls, which a plain average does not, and so comes much nearer the true mean height.

Worked example: A Grain Store's Hooped Roof: The Mean Height Across the Floor Against the Average of Five Measurements

Question A grain store has a hooped roof. Its height above the floor, x meters from the center line, is h = 8 − x28 meters, and the store is 16 meters wide, so the roof meets the floor at each side. (a) Find the mean height of the roof across the width of the store. (b) A worker measures the height every 4 meters across and averages the five readings. What does that average come to, and what do the same five readings give by the trapezium rule?

  1. 1.The mean value of a function over an interval is its integral divided by the width: h = 116∫−88(8 − x28)dx.

    02468−8−4048x, meters from the center lineheight, mmean value = the area divided by the width
    02468−8−4048x, meters from the center lineheight, mmean value = the area divided by the width
    The mean value of a function is its integral divided by the width: h = 116∫−88(8 − x28)dx.
  2. 2.Integrating, ∫−88(8 − x28)dx = [8x − x324]−88 = (64 − 643) − (−64 + 643) = 128 − 1283 = 2563, which is the area of the cross-section in square meters.

    02468−8−4048x, meters from the center lineheight, mmean value = the area divided by the widtharea = 256/3 = 85.33 m2
    02468−8−4048x, meters from the center lineheight, mmean value = the area divided by the widtharea = 256/3 = 85.33 m2
    The integral is [8x − x324]−88 = 2563 square meters, the area of the cross-section.
  3. 3.(a) Dividing by the width, h = 2563 × 116 = 163 = 5.33 meters to two decimal places. That is two thirds of the 8 meter crown, which is what the mean of a parabola over the whole of its arch must be.

    02468−8−4048x, meters from the center lineheight, mmean 5.33mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m
    02468−8−4048x, meters from the center lineheight, mmean 5.33mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m
    (a) Dividing by the width, h = 2563 × 116 = 163 = 5.33 meters, two thirds of the crown.
  4. 4.(b) The five readings, at x = −8, −4, 0, 4 and 8, are 0, 6, 8, 6 and 0 meters, and their average is 205 = 4 meters. That is well short, because the two readings at the walls stand for only half a strip of floor each and yet carry a full share of the average.

    02468−8−4048x, meters from the center lineheight, mmean 5.33readings average 4mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m(b) readings 0, 6, 8, 6, 0 average 4 m
    02468−8−4048x, meters from the center lineheight, mmean 5.33readings average 4mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m(b) readings 0, 6, 8, 6, 0 average 4 m
    (b) The five readings are 0, 6, 8, 6 and 0, whose plain average is 4 meters: the two at the walls carry a full share each.
  5. 5.The trapezium rule gives each end reading half weight, which is the share it really stands for: the area is 4(02 + 6 + 8 + 6 + 02) = 4 × 20 = 80 square meters, so the mean height is 8016 = 5 meters. Check: 80 is short of the true 2563 = 85.33 only because each chord cuts inside a roof that curves.

    02468−8−4048x, meters from the center lineheight, mmean 5.33readings average 4trapezium 80, mean 5mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m(b) readings 0, 6, 8, 6, 0 average 4 mtrapezium: 4(0 + 6 + 8 + 6 + 0) = 80, so 5 m
    02468−8−4048x, meters from the center lineheight, mmean 5.33readings average 4trapezium 80, mean 5mean value = the area divided by the widtharea = 256/3 = 85.33 m2(a) mean height = 85.33/16 = 5.33 m(b) readings 0, 6, 8, 6, 0 average 4 mtrapezium: 4(0 + 6 + 8 + 6 + 0) = 80, so 5 m
    Halving those two end readings is the trapezium rule: 4(02 + 6 + 8 + 6 + 02) = 80 square meters, a mean of 5 meters.

Answer: (a) the mean height is 5.33 meters, that is 16/3 meters; (b) the average of the five readings is 4 meters, while the trapezium rule on the same readings gives an area of 80 square meters and a mean height of 5 meters

Common mistakes

  • Averaging the five readings and calling it the mean height. That gives 4 meters, over a meter short, because it weights the two zero readings at the walls as heavily as the 8 meter crown. The mean value of a function shares the width out evenly along the floor, not evenly among the readings.
  • Taking the mean height as halfway between the lowest and the highest, 0 + 82 = 4 meters. Halving the two extremes is right for a straight line and wrong for anything that bends: the roof spends more of its width near the crown than a straight slope would.

More using integration problems, worked step by step →

Practice Numerical Integration in the app