A5 · Lesson 46 · Numerical integration
Integrating what you can't integrate, and what you only measured
Most integrals have no formula. , which describes noise and errors, can't be written with the functions you know. And a lot of what engineers integrate isn't a function at all: it's a list of measurements, power sampled every half second or current read by an ADC. The answer in both cases is to add up slices cleverly. How the slices are shaped decides how many you need.
- The curve is on . The shaded shapes are trapezoids, each joining two neighboring points with a straight line.
- Increase . The error readout falls; watch by how much each time doubles.
- The trapezoids sit below the curve where it bends down and above where it bends up. Which happens here?
Predict
The trapezoid rule's error on a smooth curve is about 0.0038 with 4 slices. About what is it with 8?
About 0.00096, a quarter as much. The trapezoid rule's error goes as , the square of the slice width, so halving cuts the error by 4. Simpson's rule, which fits parabolas instead of lines, does far better: its error goes as , falling 16 times when halves.
Name it
Three rules
Split into slices of width , with points .
- Trapezoid: join neighboring points with lines.
- Midpoint: use each slice's center height, .
- Simpson ( even): fit a parabola through each pair of slices.
How their errors shrink
For a smooth function, the errors are about
with an average second derivative. So the trapezoid and midpoint errors have opposite signs, with the midpoint's half as big, and both fall by 4 when halves. Simpson's falls by 16. If bends down (), trapezoids sit below the curve and underestimate.
Estimating the error from the answers
Compute and . Since the error falls by 4, the error in is about , and adding it on gives , which is exactly Simpson's rule. This is Richardson extrapolation: use how the answer changes to correct it.
Sampled data
Measured data comes on a fixed grid, so you can't choose . The trapezoid rule works on any spacing. Simpson needs an even number of equal slices. Either way, the samples have to be close enough to catch every bump in the signal: no rule can integrate what fell between the samples.
Worked example
Estimate (exactly 0.746 824) with by the trapezoid, midpoint and Simpson rules.
Show the solution
- Apply the three rules with .
| Rule | Estimate | Error |
|---|---|---|
| Trapezoid | 0.742 984 | |
| Midpoint | 0.748 747 | |
| Simpson | 0.746 855 |
- Compare the trapezoid and midpoint rules. The midpoint error is half the trapezoid error, with the opposite sign: the curve bends down here, so trapezoids sit low and midpoint rectangles sit high.
- Compare Simpson's rule. At the same cost, it's a hundred times better.
Answer the trapezoid rule gives 0.742 984, the midpoint rule 0.748 747 and Simpson's rule 0.746 855, within 0.000 031 of the exact value.
Worked example
With , the trapezoid rule gives 0.745 866. Use it and the value, 0.742 984, to estimate the error and correct it.
Show the solution
- Estimate the error in . and the true error is 0.000 959.
- Correct it. within 0.000 002 of the exact answer.
- Compare with Simpson's rule. The corrected value is identical to Simpson's rule with .
Answer the error in is about 0.000 961, and the corrected value is 0.746 826.
Worked example
A logger records a heater's power every 0.5 s: 0, 2.0, 3.5, 4.2, 4.0, 3.1, 1.8, 0.6, 0 W. How much energy did it use?
Show the solution
- Trapezoid rule.
- Simpson's rule, with 8 equal slices.
- Compare. The two agree to 1%. With measured data, that agreement is the best available check: if they differed a lot, the sampling would be too coarse.
Answer the heater used about 9.6 J by the trapezoid rule, or 9.7 J by Simpson's rule.
Check
The trapezoid rule gives an error of 0.01 on a smooth integral with slices. About what will its error be with ?
Check
Simpson's rule has an error of 0.002 with slices. About what will it be with ?
Check
Use the trapezoid rule with one slice for .
Check
The trapezoid rule gives 1.896 with slices and with . What does Richardson extrapolation give?
Check
Power samples taken every 0.25 s read 0, 3 and 7 W. What energy does Simpson's rule give for those two slices?
Write units the way you normally would: 1.5 J, 1500 mJ and 0.0015 kJ are the same answer.
Check
Integrate (exactly 4) with 4 slices.
(a)
What does the trapezoid rule give?
(b)
What does Simpson's rule give?
Check
Show that Simpson's rule is exact for any parabola. Use on .
Step 1
What is the exact integral ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
Write Simpson's formula, , with the values put in.
Step 3
Simplify it.
Explain why
Why do the trapezoid and midpoint rules err in opposite directions, and how does Simpson's rule use that?
On a curve that bends one way, say concave down, a straight chord between two points lies under the curve, so trapezoids underestimate. A midpoint rectangle has the curve's height at the center, and on a curve bending down that rectangle sticks out above the curve near its ends more than it falls short in the middle, so it overestimates. For a smooth curve the two errors are and times the same average curvature: opposite signs, with the midpoint's error half as big. A weighted average, , cancels that leading error, and that combination is exactly Simpson's rule. What's left is a much smaller error that goes as .
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.