Training Numerical Methods Numerical Integration
3 / 5

Numerical Integration

25 min Numerical Methods
Numerical integration (quadrature) estimates definite integrals when an antiderivative is unavailable or the integrand is given only as discrete data. The trapezoidal rule approximates the area under f(x) by connecting adjacent points with straight lines, yielding an error of order O(h²) where h is the step size. Simpson's rule uses parabolic arcs through groups of three points and achieves O(h⁴) accuracy—a dramatic improvement for smooth functions. Gaussian quadrature goes further by choosing both the sample points and weights optimally, achieving O(h^(2n)) accuracy with n points. Richardson extrapolation and Romberg integration combine lower-order estimates to squeeze out higher accuracy systematically.

Numerical Integration

Trapezoidal Rule

$$\int_a^b f(x)\,dx \approx \frac{h}{2}\left[f(a) + 2\sum_{i=1}^{n-1} f(x_i) + f(b)\right]$$

$h = (b-a)/n$, $x_i = a + ih$. Error $= O(h^2)$.

Simpson's Rule

Requires $n$ even:

$$\int_a^b f(x)\,dx \approx \frac{h}{3}\left[f(a) + 4\sum_{\text{odd } i} f(x_i) + 2\sum_{\text{even } i} f(x_i) + f(b)\right]$$

Error $= O(h^4)$ — much more accurate.

Example 1

Trapezoidal rule for $\int_0^1 x^2\,dx$ with $n=4$.

  1. $h = 0.25$.
  2. Points: $f(0)=0, f(0.25)=0.0625, f(0.5)=0.25, f(0.75)=0.5625, f(1)=1$.
  3. $T = \frac{0.25}{2}[0+2(0.0625+0.25+0.5625)+1] = 0.125[0+1.75+1] = 0.34375$.
  4. Exact:
  5. $1/3 \approx 0.3333$.
Example 2

Simpson's rule for the same integral with $n=4$.

  1. $S = \frac{0.25}{3}[0 + 4(0.0625+0.5625) + 2(0.25) + 1] = \frac{0.25}{3}[0+2.5+0.5+1] = \frac{0.25 \cdot 4}{3} = 0.3333$.
  2. Exact! Simpson's is exact for polynomials of degree $\leq 3$.
Example 3

Estimate $\int_1^3 1/x\,dx$ using the trapezoidal rule with $n=2$.

  1. $h=1$. $T = \frac{1}{2}[f(1)+2f(2)+f(3)] = 0.5[1+1+0.333] = 1.167$.
  2. Exact $= \ln 3 \approx 1.099$.

Practice Problems

1. Trapezoidal: $\int_0^2 x^3\,dx$, $n=4$.
2. Simpson's: $\int_0^2 x^3\,dx$, $n=4$.
3. Compare both to exact value.
4. Trapezoidal: $\int_0^{\pi} \sin x\,dx$, $n=4$.
5. Why must $n$ be even for Simpson's?
6. Error order for trapezoidal?
7. Error order for Simpson's?
8. Midpoint rule formula?
9. $\int_0^1 e^{-x^2}\,dx$ with $n=2$, trapezoidal.
10. Why is numerical integration necessary for $e^{-x^2}$?
11. If $n$ is doubled, trapezoidal error is divided by?
12. Simpson's: $\int_0^1 \frac{1}{1+x^2}\,dx$, $n=4$. Compare to $\pi/4$.
Show Answer Key

1. $h=0.5$; $T = 0.25[0+2(0.125+1+3.375)+8] = 0.25[0+9+8] = 4.25$

2. $S = (0.5/3)[0+4(0.125+3.375)+2(1)+8] = (0.5/3)[14+2+8] = 4.0$

3. Exact $= 4$. Simpson's exact (degree 3); Trapezoidal off by 0.25

4. $h = \pi/4$; $T \approx 1.8961$. Exact $= 2$.

5. Uses parabolic arcs through 3 consecutive points → need pairs of subintervals

6. $O(h^2)$

7. $O(h^4)$

8. $M = h\sum_{i=0}^{n-1} f(\bar{x}_i)$ where $\bar{x}_i$ is midpoint of $[x_i,x_{i+1}]$

9. $h=0.5$; $T = 0.25[1+2e^{-0.25}+e^{-1}] \approx 0.25[1+1.5576+0.3679] \approx 0.7314$

10. $e^{-x^2}$ has no closed-form antiderivative

11. $4$ (error is $O(h^2)$; $h$ halved → $h^2$ quartered)

12. $S \approx 0.7854 \approx \pi/4$; very close

Numerical Integration Comparison
Exact ∫₀ᵇ xⁿ dx
Trapezoidal
Simpson's
Errors (Trap / Simp)