Lesson 4: Numerical Integration
Estimated time: 35 to 45 minutes
Learning Objectives
By the end of this lesson, you will be able to:
- Apply the Trapezoidal Rule to approximate definite integrals
- Apply Simpson's Rule for higher accuracy approximation
- Understand error bounds for each method
- Compare the methods and know when to use each
Why Numerical Integration?
Many important integrals cannot be expressed in terms of elementary functions. Examples include ∫ e−x² dx (the Gaussian integral), ∫ sin(x²) dx, and ∫ √(1 + x4) dx. For these, we need numerical methods to approximate the value.
Even when an antiderivative exists, numerical methods can be faster for one time computations or when the integrand is given as a table of data points.
The Trapezoidal Rule
Instead of approximating the area with rectangles (Riemann sums), the Trapezoidal Rule uses trapezoids, which fit the curve more closely.
Trapezoidal Rule
With n subintervals and Δx = (b − a)/n:
Tn = (Δx/2)[f(x0) + 2f(x1) + 2f(x2) + ... + 2f(xn−1) + f(xn)]
Note the pattern: first and last values get weight 1; all interior values get weight 2.
Example 1: Trapezoidal Rule
Approximate ∫02 e−x² dx with n = 4.
Step 1: Δx = 2/4 = 0.5. Points: x0=0, x1=0.5, x2=1, x3=1.5, x4=2.
Step 2: Evaluate: f(0) = 1, f(0.5) = 0.7788, f(1) = 0.3679, f(1.5) = 0.1054, f(2) = 0.0183.
Step 3: T4 = (0.5/2)[1 + 2(0.7788) + 2(0.3679) + 2(0.1054) + 0.0183]
= 0.25[1 + 1.5576 + 0.7358 + 0.2108 + 0.0183] = 0.25(3.5225) ≈ 0.8806.
Simpson's Rule
Simpson's Rule approximates the integrand with parabolas instead of straight lines, yielding much better accuracy. It requires n to be even.
Simpson's Rule
With n subintervals (n even) and Δx = (b − a)/n:
Sn = (Δx/3)[f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + 2f(x4) + ... + 4f(xn−1) + f(xn)]
Pattern: 1, 4, 2, 4, 2, ..., 4, 1.
Example 2: Simpson's Rule
Approximate ∫02 e−x² dx with n = 4 (same as Example 1).
S4 = (0.5/3)[1 + 4(0.7788) + 2(0.3679) + 4(0.1054) + 0.0183]
= (1/6)[1 + 3.1152 + 0.7358 + 0.4216 + 0.0183] = (1/6)(5.2909) ≈ 0.8818.
(The true value is approximately 0.8821. Simpson's is already very close with just n = 4!)
Error Bounds
Error Bound for Trapezoidal Rule
|ET| ≤ M(b − a)³ / (12n²), where M = max |f''(x)| on [a, b].
Error decreases as O(1/n²): doubling n cuts the error by 4.
Error Bound for Simpson's Rule
|ES| ≤ K(b − a)5 / (180n4), where K = max |f(4)(x)| on [a, b].
Error decreases as O(1/n4): doubling n cuts the error by 16!
Example 3: Comparing Accuracy
For ∫01 x³ dx (exact answer = 1/4), compare T4 and S4.
Δx = 0.25. Points: 0, 0.25, 0.5, 0.75, 1. Values: 0, 0.0156, 0.125, 0.4219, 1.
T4 = (0.25/2)[0 + 2(0.0156) + 2(0.125) + 2(0.4219) + 1] = 0.125(2.1250) = 0.2656. Error: 0.0156.
S4 = (0.25/3)[0 + 4(0.0156) + 2(0.125) + 4(0.4219) + 1] = (1/12)(3.0000) = 0.2500. Error: 0!
Simpson's Rule gives the exact answer for cubics (because f(4) = 0 for polynomials of degree 3 or less).
Working with Data Tables
Numerical methods are essential when you only have data points (no formula).
Example 4: From a Data Table
Estimate ∫06 f(x) dx using Simpson's Rule given:
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| f(x) | 3 | 5 | 4 | 6 | 7 | 5 | 2 |
n = 6 (even), Δx = 1.
S6 = (1/3)[3 + 4(5) + 2(4) + 4(6) + 2(7) + 4(5) + 2] = (1/3)[3 + 20 + 8 + 24 + 14 + 20 + 2] = 91/3 ≈ 30.33.
Comparison and Guidelines
| Method | Accuracy | Requirement | Best For |
|---|---|---|---|
| Trapezoidal | O(1/n²) | Any n | Quick estimates, odd n |
| Simpson's | O(1/n4) | n must be even | Best accuracy per function evaluation |
Rule of thumb: Simpson's Rule with n = 10 often matches the Trapezoidal Rule with n = 100 in terms of accuracy.
Key Takeaways
- Trapezoidal Rule: weighted average with pattern 1, 2, 2, ..., 2, 1. Error is O(1/n²).
- Simpson's Rule: pattern 1, 4, 2, 4, 2, ..., 4, 1. Requires even n. Error is O(1/n4).
- Simpson's is exact for polynomials of degree 3 or less.
- Both methods work with data tables when no formula is available.
Check Your Understanding
1. Use the Trapezoidal Rule with n = 4 to approximate ∫13 (1/x) dx.
2. Use Simpson's Rule with n = 4 for the same integral.
3. If you need the Trapezoidal Rule error to be less than 0.001 for ∫01 ex dx, how many subintervals do you need?