Numerical Integration: A Comprehensive Guide

Numerical integration approximates definite integrals \( \int_a^b f(x) \, dx \) when analytical solutions are unavailable, such as for \( e^{-x^2} \) or data-driven functions. By discretizing the interval \([a, b]\) into subintervals, it estimates areas under curves using weighted function evaluations. This MathMultiverse guide explores techniques like the Trapezoidal Rule, Simpson’s Rule, and Gaussian Quadrature, with detailed examples, equations, and visualizations, highlighting applications in physics, engineering, and statistics.

Accuracy depends on the method and subinterval count, with errors from truncation (curve approximation) and rounding (finite precision). Advanced methods minimize these errors for robust computation.

Trapezoidal Rule

The Trapezoidal Rule approximates integrals by summing trapezoid areas under the curve. For \( n \) subintervals over \([a, b]\), step size \( h = \frac{b - a}{n} \), points \( x_i = a + i h \):

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

Single interval (\( n = 1 \)):

\[ \int_a^b f(x) \, dx \approx \frac{b - a}{2} \left[ f(a) + f(b) \right] \]

Error, derived from Taylor series:

\[ \text{Error} = -\frac{(b - a)^3}{12 n^2} f''(\xi), \quad \xi \in [a, b] \]

The \( O(h^2) \) error improves quadratically with more subintervals.

Examples

Let’s apply numerical integration techniques with detailed calculations.

Trapezoidal Rule: \( \int_0^1 x^2 \, dx \)

Exact: \( \int_0^1 x^2 \, dx = \left[ \frac{x^3}{3} \right]_0^1 = \frac{1}{3} \approx 0.3333 \).

\( n = 2 \), \( h = 0.5 \):

\[ x_0 = 0, \quad x_1 = 0.5, \quad x_2 = 1 \] \[ f(0) = 0, \quad f(0.5) = 0.25, \quad f(1) = 1 \] \[ \frac{0.5}{2} \left[ 0 + 2(0.25) + 1 \right] = 0.25 \cdot 1.5 = 0.375 \]

Error: \( 0.375 - 0.3333 = 0.0417 \).

\( n = 4 \), \( h = 0.25 \):

\[ x_i = 0, 0.25, 0.5, 0.75, 1 \] \[ f(x_i) = 0, 0.0625, 0.25, 0.5625, 1 \] \[ \frac{0.25}{2} \left[ 0 + 2(0.0625 + 0.25 + 0.5625) + 1 \right] = 0.34375 \]

Error: \( 0.34375 - 0.3333 = 0.01045 \), reduced by ~4.

Trapezoidal Rule: \( \int_0^1 e^x \, dx \)

Exact: \( \int_0^1 e^x \, dx = [e^x]_0^1 = e - 1 \approx 1.7183 \).

\( n = 2 \), \( h = 0.5 \):

\[ f(0) = 1, \quad f(0.5) \approx 1.6487, \quad f(1) \approx 2.7183 \] \[ \frac{0.5}{2} \left[ 1 + 2(1.6487) + 2.7183 \right] \approx 1.7589 \]

Error: \( 1.7589 - 1.7183 = 0.0406 \).

Improper Integral: \( \int_0^1 \frac{1}{\sqrt{x}} \, dx \)

Exact: \( \int_0^1 x^{-1/2} \, dx = [2x^{1/2}]_0^1 = 2 \). Start at \( x = 0.001 \):

\[ n = 4, \quad h = 0.25 \] \[ x_i = 0.001, 0.251, 0.501, 0.751, 1 \] \[ f(x_i) \approx 31.6228, 1.996, 1.413, 1.154, 1 \] \[ \frac{0.25}{2} \left[ 31.6228 + 2(1.996 + 1.413 + 1.154) + 1 \right] \approx 2.356 \]

Error reflects the singularity at \( x = 0 \).

Trapezoidal Rule Approximation

Approximation of \( \int_0^1 x^2 \, dx \) with varying subintervals.

Other Methods

Advanced methods improve accuracy for smooth functions.

Simpson’s Rule

Fits parabolas over pairs of intervals (\( n \) even):

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

Error: \( O(h^4) \)

\[ \text{Error} = -\frac{(b - a)^5}{180 n^4} f^{(4)}(\xi) \]

For \( \int_0^1 x^2 \, dx \), \( n = 2 \), \( h = 0.5 \):

\[ \frac{0.5}{3} \left[ 0 + 4(0.25) + 1 \right] = \frac{0.5}{3} \cdot 2 = 0.3333 \]

Exact for quadratics.

Gaussian Quadrature

Uses optimal points and weights:

\[ \int_a^b f(x) \, dx \approx \sum_{i=1}^n w_i f(x_i) \]

2-point Gauss-Legendre on \([-1, 1]\): \( x_1 = -\frac{1}{\sqrt{3}} \), \( x_2 = \frac{1}{\sqrt{3}} \), \( w_1 = w_2 = 1 \). Scales to \([a, b]\) for high accuracy.

Romberg Integration

Refines Trapezoidal Rule via extrapolation:

\[ R(k, m) = R(k-1, m) + \frac{R(k-1, m) - R(k-1, m-1)}{4^m - 1} \]

Achieves higher-order accuracy efficiently.

Simpson’s Rule vs. Trapezoidal

Comparison for \( \int_0^1 x^2 \, dx \).