Find a course

Module 4: Improper Integrals and Numerical IntegrationLesson 12 of 1214 min

Numerical Integration

Approximate integrals with the trapezoidal rule and Simpson's rule, predict over- and underestimates, and use error bounds to choose how many subintervals.

Step 1 of 14Learn

When there is no formula

Some integrals have no elementary antiderivative, like ∫ e^(−x²) dx or the arc length of a sine curve. Others come from data, such as a flow meter reading every 15 minutes, with no formula at all. In both cases you need a good numerical approximation.

Left and right sums are a start, but they're crude. A better idea: instead of a flat-topped rectangle on each subinterval, connect the endpoints with a straight line and use a trapezoid. A trapezoid's area is the width times the average of its two heights.

Adding n trapezoids of width Δx = (b − a)/n gives the trapezoidal rule:

T_n = (Δx/2)·[f(x₀) + 2f(x₁) + 2f(x₂) + … + 2f(xₙ₋₁) + f(xₙ)].

Interior points get weight 2 because each one is shared by two neighboring trapezoids. Algebraically, T_n is exactly the average of the left and right sums, T_n = (L_n + R_n)/2, so the overestimate of one partly cancels the underestimate of the other.

For x² on [0, 2] with n = 4, the left and right sums were 1.75 and 3.75, far from the exact 8/3. The trapezoidal rule gives their average, which is much closer.

Step 2 of 14Practice · Work it out

Use the trapezoidal rule with n = 4 to approximate ∫ from 0 to 2 of x² dx.

Step 3 of 14Learn

Simpson's rule: fitting parabolas

Straight-line tops are better than flat tops. Curved tops are better still. Simpson's rule fits a parabola through each consecutive set of three points and integrates the parabolas exactly. Because each parabola spans two subintervals, n must be even:

S_n = (Δx/3)·[f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 2f(xₙ₋₂) + 4f(xₙ₋₁) + f(xₙ)].

The weights follow the pattern 1, 4, 2, 4, 2, …, 4, 1.

Example. For ∫ from 0 to 2 of x² dx with n = 2: Δx = 1, so S₂ = (1/3)[0 + 4·1 + 4] = 8/3, exactly right. That's no accident: Simpson's rule is exact for any polynomial of degree 3 or less, even though it uses parabolas.

Data example. A surveyor measures the depth of a river every 2 meters across its 8-meter width: 0, 1.5, 2.4, 1.8 and 0 meters. The cross-sectional area by Simpson's rule is

(2/3)·[0 + 4(1.5) + 2(2.4) + 4(1.8) + 0] = (2/3)·18 = 12 square meters.

Simpson's rule is also a weighted average of two simpler rules: S₂ₙ = (2M_n + T_n)/3, where M is the midpoint sum. Since the midpoint and trapezoid errors tend to have opposite signs, with the midpoint error about half as large, this combination cancels most of the error.

Step 4 of 14Practice · Work it out

Using the same river depths (0, 1.5, 2.4, 1.8, 0 m at 2 m spacing), approximate the cross-sectional area with the trapezoidal rule instead.

Step 5 of 14Practice · Chart

Five estimates of ∫ from 0 to 2 of x² dx with n = 4

Tap the method that gets this integral exactly right.

Tap the bar that answers the question, then press Check.

Five estimates of ∫ from 0 to 2 of x² dx with n = 4Bar chart with 6 categories: Left: 1.75; Right: 3.75; Midpoint: 2.63; Trapezoid: 2.75; Simpson: 2.67; Exact: 2.67.01234LeftRightMidpointTrapezoidSimpsonExact1.753.752.632.752.672.67
Exact value 8/3 ≈ 2.667.
Five estimates of ∫ from 0 to 2 of x² dx with n = 4
ItemEstimate
Left1.75
Right3.75
Midpoint2.63
Trapezoid2.75
Simpson2.67
Exact2.67

Step 6 of 14Learn

How accurate is the answer?

Error bounds tell you how close an approximation is guaranteed to be, before you know the exact answer.

Trapezoidal rule: |error| ≤ K(b − a)³ / (12n²), where K is the maximum of |f″(x)| on [a, b].

Midpoint rule: |error| ≤ K(b − a)³ / (24n²), half the trapezoid bound.

Simpson's rule: |error| ≤ K(b − a)⁵ / (180n⁴), where K is the maximum of |f⁽⁴⁾(x)|.

The powers of n are the headline. Doubling n cuts the trapezoid error by about a factor of 4 and Simpson's error by about 16. To gain three more correct digits, the trapezoid rule needs about 32 times as many points; Simpson's needs about 6 times as many.

The second derivative also predicts the direction of the trapezoid error. On a concave-up curve, each straight top lies above the curve, so the trapezoidal rule overestimates and the midpoint rule underestimates. On a concave-down curve, it's the reverse. Simpson's error depends on the fourth derivative, which is zero for cubics, explaining why it's exact for them.

Using the bound in reverse answers practical questions: how many subintervals guarantee an error below 0.001? Solve the inequality for n, then round up. Since Simpson's rule needs an even n, round up to the next even number.

Step 7 of 14Practice · Chart

Error shrinks with n: ∫ from 0 to 1 of eˣ dx

Tap the first n where the trapezoid error drops below 0.01.

Tap the point that answers the question, then press Check.

Error shrinks with n: ∫ from 0 to 1 of eˣ dxLine chart with 4 categories: n = 2: Trapezoid error 0.0356, Simpson error 5.8 × 10⁻⁴; n = 4: Trapezoid error 0.009, Simpson error 3.7 × 10⁻⁵; n = 8: Trapezoid error 0.0022, Simpson error 2.3 × 10⁻⁶; n = 16: Trapezoid error 5.6 × 10⁻⁴, Simpson error 1.5 × 10⁻⁷.00.010.020.030.04Absolute errorn = 2n = 4n = 8n = 16
Computed values. Doubling n cuts the trapezoid error by about 4 and Simpson's by about 16.
Error shrinks with n: ∫ from 0 to 1 of eˣ dx
ItemTrapezoid errorSimpson error
n = 20.03565.8 × 10⁻⁴
n = 40.0093.7 × 10⁻⁵
n = 80.00222.3 × 10⁻⁶
n = 165.6 × 10⁻⁴1.5 × 10⁻⁷

Step 8 of 14Explore

Three methods for ∫ from 0 to 1 of eˣ dx

The exact value is e − 1 ≈ 1.71828. Slide n and compare the trapezoid, midpoint and Simpson approximations. Notice the trapezoid error is about twice the midpoint error with the opposite sign, and that Simpson (using 2n subintervals) is accurate to many digits with tiny n.

0123 00.20.40.60.81
Trapezoid T_n
1.753931
Midpoint M_n
1.700513
Simpson S2n = (2M + T)/3
1.71831884
Exact e − 1
1.71828183

Step 9 of 14Practice · Sort into groups

Classify each approximation as an overestimate, an underestimate or exact.

Tap an item, then tap its group (or drag it there).

Step 10 of 14Note

Step 11 of 14Learn

Putting the whole course together

You now have a complete map for any integral you meet.

Is it a definite integral of a nice function on a finite interval? Find an antiderivative and apply the Fundamental Theorem. Simplify first, then use the strategy checklist: basic rules, substitution, parts, trig identities or substitution, partial fractions.

Does the interval reach infinity, or does the integrand blow up somewhere? It's improper. Write it as a limit, split at every trouble spot, and check that every piece converges. If you only need to know convergence, compare with a p-integral or an exponential.

Is there no elementary antiderivative, or only data? Approximate numerically. Simpson's rule is the usual first choice for smooth functions; use error bounds or keep doubling n until the answer stops changing in the digits you care about.

Is it an applied problem? Slice the quantity into small pieces, approximate one piece (a strip, a disk, a shell, a layer of water), and let the integral add them up. Units and quick estimates protect you from setup errors.

That last idea, slice and add, is the reason integrals appear in every quantitative field. The techniques make the calculation possible; the slicing makes the setup possible.

Step 12 of 14Practice · Diagram

A map of the whole course

Where does ∫ from 0 to 1 of e^(−x²) dx belong?

Tap the shape that answers the question, then press Check.

A map of the whole courseHierarchy diagram: Any integral, Finite limits, nice f, Infinite limit or asymptote, No formula or data only, Antiderivative + FTC, Basic rules, Substitution, Parts, Trig methods, Partial fractions.Any integralFinite limits, nice fAntiderivative + FTCBasic rulesSubstitutionPartsTrig methodsPartial fractionsInfinite limit or asymptoteNo formula or data only
Any integral
Finite limits, nice f
Infinite limit or asymptote

Write it as a limit; use p-integrals or comparison to decide convergence.

No formula or data only

Trapezoid, midpoint, Simpson, or adaptive software.

Antiderivative + FTC
Basic rules
Substitution
Parts
Trig methods
Partial fractions

Step 13 of 14Practice · Choose one

If you double the number of subintervals in Simpson's rule, the error typically shrinks by about what factor?

Step 14 of 14Practice · Work it out

The trapezoidal error bound for ∫ from 0 to 2 of x⁴ dx is K(b − a)³/(12n²) with K = max|f″| = 48. What is the smallest n that guarantees an error of at most 0.01?