Numerical Integration

The Newton-Leibniz formula requires us to “be able to find an antiderivative”. But in reality many important integrals — such as ∫e−x2dx\int e^{-x^2} dx (the normal distribution) and ∫sin⁡xxdx\int \frac{\sin x}{x} dx — have no elementary antiderivative. At that point you have to return to the essence of integration: computing the area approximately. That is what numerical integration is.

Starting from the Riemann Sum

The definition of a definite integral is itself an approximation: divide the interval up and sum the areas of the rectangles.

Riemann sum

Divide the interval [a,b][a, b] into nn equal parts, each of width Δx=b−an\Delta x = \frac{b-a}{n}, and take the division points xi=a+iΔxx_i = a + i\Delta x. Then

Rn=∑i=1nf(ξi) ΔxR_n = \sum_{i=1}^{n} f(\xi_i)\, \Delta x

When n→∞n \to \infty, if the limit exists, it is the definite integral ∫abf(x) dx\int_a^b f(x)\, dx.

In actual computation, RnR_n with a finite nn is an approximation to the integral. According to how the sample point ξi\xi_i is chosen, there are:

  1. The left-endpoint Riemann sum: ξi=xi−1\xi_i = x_{i-1}, usually on the small side (for an increasing function)
  2. The right-endpoint Riemann sum: ξi=xi\xi_i = x_i, usually on the large side (for an increasing function)
  3. The midpoint Riemann sum: ξi=xi−1+xi2\xi_i = \frac{x_{i-1} + x_i}{2}, which is more accurate

The Trapezoidal Rule: Approximating with Straight Lines

A slightly cleverer approach: approximate each small interval by a trapezoid rather than a rectangle.

The trapezoidal rule

∫abf(x) dx≈Tn=Δx2[f(x0)+2f(x1)+2f(x2)+⋯+2f(xn−1)+f(xn)]\int_a^b f(x)\, dx \approx T_n = \frac{\Delta x}{2} \left[ f(x_0) + 2f(x_1) + 2f(x_2) + \cdots + 2f(x_{n-1}) + f(x_n) \right]

Here Δx=b−an\Delta x = \frac{b-a}{n}. The values at the two ends are multiplied by one only, while each value in the middle appears twice (because two neighbouring trapezoids share an endpoint).

Simpson’s Rule: Approximating with Parabolas

The trapezoidal rule joins adjacent points with straight lines; Simpson’s rule goes a step further: every three points (two small intervals) are approximated by a single parabola. This raises the accuracy considerably.

Simpson's rule

∫abf(x) dx≈Sn=Δx3[f(x0)+4f(x1)+2f(x2)+4f(x3)+⋯+2f(xn−2)+4f(xn−1)+f(xn)]\int_a^b f(x)\, dx \approx S_n = \frac{\Delta x}{3} \left[ f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + 2f(x_{n-2}) + 4f(x_{n-1}) + f(x_n) \right]

Note: Simpson’s rule requires nn to be even. The coefficients alternate 4,2,4,2,…,44, 2, 4, 2, \ldots, 4, with a 11 at each end.

Where Numerical Integration Is Used

  1. Statistics: the probability P(a≤X≤b)=12π∫abe−x2/2dxP(a \le X \le b) = \frac{1}{\sqrt{2\pi}}\int_a^b e^{-x^2/2} dx of the normal distribution has no elementary antiderivative, so numerical integration is the only way.
  2. Physics: many potential-energy, electric-field and radiation integrals have no analytic solution.
  3. Engineering computation: areas, volumes and centroids bounded by curves whose antiderivatives cannot be found analytically.

A Typical Application

Application: Approximating ∫01ex2dx\int_0^1 e^{x^2} dx by Three Methods (n=4n = 4)

numerical integrationthe trapezoidal ruleSimpson's rule

Approach:

With n=4n = 4, Δx=0.25\Delta x = 0.25, and the division points x0=0,x1=0.25,x2=0.5,x3=0.75,x4=1x_0 = 0, x_1 = 0.25, x_2 = 0.5, x_3 = 0.75, x_4 = 1. Compute the value of the function at each point and substitute into the formulas.

Steps:

  1. Function values: f(0)=1f(0) = 1, f(0.25)=e0.0625≈1.0645f(0.25) = e^{0.0625} \approx 1.0645, f(0.5)=e0.25≈1.2840f(0.5) = e^{0.25} \approx 1.2840, f(0.75)=e0.5625≈1.7551f(0.75) = e^{0.5625} \approx 1.7551, f(1)=e≈2.7183f(1) = e \approx 2.7183
  2. Trapezoidal rule: T4=0.252[1+2(1.0645+1.2840+1.7551)+2.7183]≈0.125×11.7265≈1.4658T_4 = \frac{0.25}{2}[1 + 2(1.0645 + 1.2840 + 1.7551) + 2.7183] \approx 0.125 \times 11.7265 \approx 1.4658
  3. Simpson’s rule: S4=0.253[1+4(1.0645+1.7551)+2(1.2840)+2.7183]≈0.08333×17.4291≈1.4524S_4 = \frac{0.25}{3}[1 + 4(1.0645 + 1.7551) + 2(1.2840) + 2.7183] \approx 0.08333 \times 17.4291 \approx 1.4524
  4. The exact value is about 1.46271.4627, so Simpson’s result is already very close

Answer: T4≈1.4658T_4 \approx 1.4658, S4≈1.4524S_4 \approx 1.4524 (the exact value is about 1.46271.4627)

Summary

Symbols Used in This Article

SymbolTypePronunciation/ExplanationMeaning in This Article
Δx\Delta xmathematical symboldelta xThe width of a small interval (the step size)
nnmathematical symbolnThe number of equal divisions of the interval
xix_imathematical symbolx-sub-iThe ii-th division point
ξi\xi_iGreek letterXi-sub-iThe sample point on the ii-th small interval
RnR_nmathematical symbolR-sub-nThe Riemann sum
TnT_nmathematical symbolT-sub-nThe approximation given by the trapezoidal rule
SnS_nmathematical symbolS-sub-nThe approximation given by Simpson’s rule
∑i=1n\sum_{i=1}^{n}mathematical symbolsum from i=1 to nThe summation sign
eemathematical symbolEuler’s numberThe base of the natural logarithm
π\piGreek letterPiThe ratio of a circle’s circumference to its diameter
P(a≤X≤b)P(a \le X \le b)mathematical symbolprobabilityThe probability that a random variable falls in the interval

Found an issue with this content?

Tell us what could be improved.