The Central Idea
A definite integral is
\[ I = \int_a^b f(x)\,dx. \]Numerical integration replaces \(f\) with a simpler approximation \(p\):
\[ f(x)\approx p(x). \]Then
\[ \boxed{ \int_a^b f(x)\,dx \approx \int_a^b p(x)\,dx }. \]The resulting approximation is called a quadrature rule.
Why Numerical Integration Is Needed
Numerical quadrature is useful when:
- an antiderivative has no elementary closed form;
- the function is known only from data;
- the integrand comes from a simulation;
- the antiderivative exists but is inconvenient to evaluate;
- an integral must be computed repeatedly inside a larger algorithm.
Quadrature as Weighted Sampling
Many numerical integration formulas have the form
\[ \boxed{ \int_a^b f(x)\,dx \approx \sum_{i=0}^{n}w_i f(x_i) }. \]The points \(x_i\) are quadrature nodes and the coefficients \(w_i\) are quadrature weights.
The Rectangle Rule
On one interval \([a,b]\), approximate the integrand by a constant.
Using the left endpoint gives
\[ \boxed{ \int_a^b f(x)\,dx \approx (b-a)f(a) }. \]This is the left rectangle rule.
The Right Rectangle Rule
Using the right endpoint gives
\[ \boxed{ \int_a^b f(x)\,dx \approx (b-a)f(b) }. \]The Midpoint Rule
Using the interval midpoint
\[ m=\frac{a+b}{2}, \]gives
\[ \boxed{ \int_a^b f(x)\,dx \approx (b-a) f\left(\frac{a+b}{2}\right) }. \]The midpoint rule is usually more accurate than a one-sided rectangle rule for smooth functions.
Example: Midpoint Rule
Approximate
\[ \int_0^2 x^2\,dx \]with one midpoint rectangle.
The midpoint is \(1\), so
\[ M = 2f(1) = 2. \]Therefore,
\[ \boxed{M=2}. \]The exact integral is \(8/3\).
The Trapezoidal Rule
Approximate \(f\) by the line through
\[ (a,f(a)) \]and
\[ (b,f(b)). \]Integrating that line gives
\[ \boxed{ T = \frac{b-a}{2} \left[ f(a)+f(b) \right] }. \]Why the Trapezoidal Rule Works
The interpolating line is a degree-one polynomial.
Integrating this linear interpolant exactly produces the trapezoidal formula.
Numerical integration is therefore closely connected to interpolation.
Example: Trapezoidal Rule
Approximate
\[ \int_0^2 x^2\,dx. \]The trapezoidal rule gives
\[ T = \frac{2}{2} \left[ 0^2+2^2 \right] = 4. \]Therefore,
\[ \boxed{T=4}. \]Trapezoidal Error
For sufficiently smooth \(f\), the one-panel trapezoidal error has the form
\[ \boxed{ E_T = -\frac{(b-a)^3}{12}f''(\xi) } \]for some \(\xi\in(a,b)\).
Curvature controls the leading error.
The Composite Trapezoidal Rule
Divide \([a,b]\) into \(n\) equal subintervals:
\[ h=\frac{b-a}{n}, \qquad x_i=a+ih. \]Applying the trapezoidal rule on each subinterval gives
\[ \boxed{ T_n = h \left[ \frac12f(x_0) + \sum_{i=1}^{n-1}f(x_i) + \frac12f(x_n) \right] }. \]Composite Trapezoidal Error
For sufficiently smooth \(f\),
\[ \boxed{ E_{T_n} = -\frac{(b-a)}{12}h^2 f''(\xi) }. \]The composite trapezoidal rule is second-order accurate:
\[ E_{T_n}=O(h^2). \]The Composite Midpoint Rule
Divide the interval into equal subintervals and evaluate at each midpoint
\[ m_i=\frac{x_{i-1}+x_i}{2}. \]Then
\[ \boxed{ M_n = h \sum_{i=1}^{n}f(m_i) }. \]This rule is also second-order accurate for smooth integrands.
Simpson's Rule
Simpson's rule approximates the integrand with a quadratic polynomial through three equally spaced points.
On \([a,b]\), let
\[ m=\frac{a+b}{2}. \]Then
\[ \boxed{ S = \frac{b-a}{6} \left[ f(a)+4f(m)+f(b) \right] }. \]Why Simpson's Rule Is Powerful
Simpson's rule integrates every polynomial of degree at most \(3\) exactly.
Although it is derived from quadratic interpolation, a symmetry cancellation increases its degree of exactness.
Example: Simpson's Rule
Approximate
\[ \int_0^2 x^2\,dx. \]Simpson's rule gives
\[ S = \frac{2}{6} \left[ 0+4(1)+4 \right] = \frac{8}{3}. \]Thus,
\[ \boxed{ S=\frac83 }. \]This is exact because \(x^2\) is a polynomial of degree less than \(4\).
Simpson Error
For sufficiently smooth \(f\),
\[ \boxed{ E_S = -\frac{(b-a)^5}{2880} f^{(4)}(\xi) }. \]The fourth derivative controls the leading error.
The Composite Simpson Rule
Divide \([a,b]\) into an even number \(n\) of equal subintervals:
\[ h=\frac{b-a}{n}. \]Then
\[ \boxed{ S_n = \frac{h}{3} \left[ f(x_0) + 4\sum_{\substack{i=1\\i\text{ odd}}}^{n-1}f(x_i) + 2\sum_{\substack{i=2\\i\text{ even}}}^{n-2}f(x_i) + f(x_n) \right] }. \]Composite Simpson Error
For sufficiently smooth \(f\),
\[ \boxed{ E_{S_n} = -\frac{(b-a)}{180}h^4f^{(4)}(\xi) }. \]Thus,
\[ E_{S_n}=O(h^4). \]Degree of Exactness
A quadrature rule has degree of exactness \(m\) if it integrates every polynomial of degree at most \(m\) exactly.
Examples:
- midpoint rule: degree \(1\);
- trapezoidal rule: degree \(1\);
- Simpson's rule: degree \(3\).
Newton-Cotes Rules
Rectangle, trapezoidal, and Simpson formulas belong to the Newton-Cotes family.
These rules use equally spaced nodes and integrate an interpolating polynomial.
Closed and Open Newton-Cotes Rules
A closed rule includes the interval endpoints.
An open rule uses only interior nodes.
The trapezoidal and Simpson rules are closed Newton-Cotes formulas.
Why Very High-Degree Newton-Cotes Rules Are Rare
High-degree equally spaced interpolation can oscillate and produce unfavorable quadrature weights.
Composite low-order rules are usually more stable and practical.
Romberg Integration
The composite trapezoidal rule has an even-power error expansion:
\[ T(h) = I + C_2h^2 + C_4h^4 +\cdots. \]Richardson extrapolation can therefore eliminate successive error terms.
First Romberg Extrapolation
Since the leading trapezoidal error is \(O(h^2)\),
\[ \boxed{ R = \frac{ 4T(h/2)-T(h) }{3} }. \]This removes the leading \(h^2\) term and produces a higher-order estimate.
Romberg Table
Romberg integration builds a triangular table of successively refined trapezoidal approximations and Richardson extrapolations.
Each column removes another leading even-power error term when the required smoothness and asymptotic behavior are present.
Gaussian Quadrature
Newton-Cotes formulas fix the nodes first and then determine weights.
Gaussian quadrature chooses both nodes and weights to maximize polynomial exactness.
A Gaussian rule has the form
\[ \boxed{ \int_{-1}^{1}f(x)\,dx \approx \sum_{i=1}^{n}w_i f(x_i) }. \]Gauss-Legendre Quadrature
For ordinary integration on \([-1,1]\), Gauss-Legendre quadrature uses nodes at the zeros of the Legendre polynomial \(P_n(x)\).
An \(n\)-point Gauss-Legendre rule integrates every polynomial of degree at most
\[ \boxed{2n-1} \]exactly.
Two-Point Gauss-Legendre Rule
For \(n=2\), the nodes are
\[ x_1=-\frac{1}{\sqrt3}, \qquad x_2=\frac{1}{\sqrt3}, \]with weights
\[ w_1=w_2=1. \]Thus,
\[ \boxed{ \int_{-1}^{1}f(x)\,dx \approx f\left(-\frac{1}{\sqrt3}\right) + f\left(\frac{1}{\sqrt3}\right) }. \]Mapping a General Interval to \([-1,1]\)
Let
\[ x = \frac{a+b}{2} + \frac{b-a}{2}t. \]Then
\[ dx = \frac{b-a}{2}dt. \]Therefore,
\[ \boxed{ \int_a^b f(x)\,dx = \frac{b-a}{2} \int_{-1}^{1} f\left( \frac{a+b}{2} + \frac{b-a}{2}t \right)dt }. \]Gaussian Quadrature and Orthogonal Polynomials
Gaussian nodes arise from orthogonal polynomials associated with the integration weight.
This connects numerical integration directly to the orthogonal-basis ideas from function approximation.
Weighted Gaussian Quadrature
More general integrals have the form
\[ \int_a^b w(x)f(x)\,dx. \]Specialized Gaussian rules choose orthogonal polynomials associated with the weight \(w(x)\).
Adaptive Quadrature
A uniform step size spends equal computational effort everywhere.
Adaptive quadrature uses finer subdivisions where the function is difficult and coarser subdivisions where it is smooth.
The Adaptive Strategy
- Approximate the integral on an interval.
- Subdivide the interval.
- Compute refined approximations.
- Estimate the local error from the difference.
- Accept the interval if the error is small enough.
- Otherwise subdivide again.
Adaptive Simpson's Method
Compute Simpson's rule on \([a,b]\):
\[ S(a,b). \]Then split at the midpoint \(m\) and compute
\[ S(a,m)+S(m,b). \]The discrepancy between the coarse and refined values provides an error estimate.
Adaptive Simpson Error Estimate
Because Simpson's error scales like \(h^4\), the refined estimate can be compared with the coarse one using
\[ \boxed{ \frac{ |S_{\text{refined}}-S_{\text{coarse}}| }{15} }. \]This factor follows from Richardson-extrapolation reasoning.
Why Adaptivity Helps
Many functions are easy over most of an interval but difficult in localized regions.
Examples include:
- sharp peaks;
- rapid oscillations;
- boundary layers;
- near-singular behavior;
- localized curvature.
Error Control
A practical integrator often seeks
\[ |I-Q|\le\tau, \]where \(Q\) is the numerical estimate.
When the exact integral is unknown, the method uses a computable error estimate instead.
Absolute and Relative Tolerances
A combined criterion may take the form
\[ \boxed{ E_{\text{est}} \le \tau_{\text{abs}} + \tau_{\text{rel}}|Q| }. \]This works across both small and large integral magnitudes.
Convergence Rate
If a quadrature rule has error
\[ E(h)\approx Ch^p, \]then halving \(h\) should reduce the leading error by approximately
\[ \boxed{2^p}. \]Observed Order
When an exact integral is available for testing,
\[ \boxed{ p_{\text{obs}} = \log_2 \left( \frac{E(h)}{E(h/2)} \right) }. \]This provides a practical convergence check.
Integration Is Usually Better Conditioned Than Differentiation
Differentiation amplifies high-frequency noise.
Integration tends to average or smooth local fluctuations.
Numerical integration is therefore often more forgiving of noisy data than numerical differentiation.
Rounding Error in Large Sums
Composite quadrature may require summing thousands or millions of weighted function values.
Floating-point addition can accumulate rounding error.
Summation order or compensated summation can matter when the terms vary greatly in magnitude.
Compensated Summation
Compensated summation tracks small low-order contributions that ordinary floating-point addition can lose.
This can improve the reliability of large quadrature sums without changing the quadrature rule itself.
Improper Integrals
Numerical integration becomes more delicate when:
\[ \int_a^\infty f(x)\,dx \]has an infinite interval or when the integrand is singular at an endpoint.
Transformations, interval splitting, or specialized quadrature may be required.
Endpoint Singularities
An integral such as
\[ \int_0^1 \frac{1}{\sqrt{x}}\,dx \]is finite even though the integrand is unbounded at \(x=0\).
A naive quadrature rule that evaluates the endpoint directly will fail.
Variable Transformations
A substitution can remove or weaken difficult behavior.
If
\[ x=\phi(t), \]then
\[ \boxed{ \int_a^b f(x)\,dx = \int_{\alpha}^{\beta} f(\phi(t))\phi'(t)\,dt }. \]A good transformation can make numerical integration much easier.
Oscillatory Integrals
Integrals containing rapidly oscillating terms such as
\[ \sin(\omega x) \]may require many uniform sample points when \(\omega\) is large.
Specialized oscillatory quadrature methods can exploit the known oscillatory structure.
Highly Peaked Integrands
A narrow peak may contribute substantially to the total integral while occupying only a small part of the interval.
Coarse uniform sampling can miss such a feature.
Adaptive refinement is especially valuable in this situation.
Integrating Tabulated Data
When only sampled values are available, composite Newton-Cotes rules are natural.
The trapezoidal rule works with arbitrary consecutive data intervals, while Simpson's rule requires appropriate spacing patterns.
Nonuniform Trapezoidal Rule
For nonuniform nodes
\[ x_0Multidimensional Integration
Numerical quadrature extends to
\[ \int\!\!\int_D f(x,y)\,dA \]and higher-dimensional integrals.
Tensor-product quadrature applies one-dimensional rules along each coordinate.
The Curse of Dimensionality
If a one-dimensional rule uses \(m\) nodes, a full tensor-product rule in \(d\) dimensions uses
\[ \boxed{m^d} \]nodes.
High-dimensional integration therefore requires different strategies.
Monte Carlo Integration
For high-dimensional problems, random sampling can become attractive.
If \(X\) is uniformly distributed over a region \(D\), then
\[ \int_D f(\mathbf{x})\,d\mathbf{x} = |D|\, \mathbb{E}[f(X)]. \]The expectation can be estimated from random samples.
Monte Carlo Estimate
With samples
\[ X_1,\ldots,X_N, \]estimate
\[ \boxed{ I \approx |D| \frac{1}{N} \sum_{i=1}^{N}f(X_i) }. \]The convergence rate is slower than high-order deterministic quadrature in one dimension but is largely independent of dimension in its basic statistical scaling.
A Reliable Composite-Quadrature Workflow
- Inspect the integrand and interval.
- Choose trapezoidal, midpoint, or Simpson based on smoothness and available data.
- Select a starting subdivision count.
- Compute the quadrature estimate.
- Refine the grid.
- Compare successive approximations.
- Estimate convergence order when possible.
- Stop when the required tolerance is satisfied.
A Reliable Adaptive-Quadrature Workflow
- Compute a coarse estimate on the interval.
- Split the interval and compute a refined estimate.
- Estimate local error from the discrepancy.
- Accept intervals whose estimated error is small enough.
- Refine only intervals that need more resolution.
- Distribute the global tolerance among subintervals.
- Set recursion or subdivision limits for safety.
A Reliable Gaussian-Quadrature Workflow
- Map the interval to the standard Gaussian domain.
- Select an appropriate Gaussian family and node count.
- Evaluate the integrand at the quadrature nodes.
- Apply the quadrature weights.
- Increase the node count or compare with another rule to assess convergence.
- Use transformations or interval splitting for singular or highly localized behavior.
Common Error: Using Simpson's Rule with an Odd Number of Subintervals
Composite Simpson's rule groups subintervals in pairs.
The number of equal subintervals must therefore be even.
Common Error: Assuming Higher Order Always Wins
A high-order rule may perform poorly if the function lacks the smooth derivatives required by its error analysis.
Sharp features, singularities, or discontinuities can favor adaptive or piecewise treatment.
Common Error: Ignoring Singular Endpoints
A formula that evaluates an undefined endpoint cannot be used directly on an improper integral.
Transform the problem or use a method designed for the singularity.
Common Error: Using Only One Grid
A single quadrature value provides little evidence of accuracy.
Refine the grid or compare independent methods to assess convergence.
Common Error: Overrefining Everywhere
Uniformly shrinking \(h\) can waste computation when only a small region is difficult.
Adaptive quadrature allocates work more efficiently.
Common Error: Ignoring Cancellation in the Integral
Positive and negative contributions can nearly cancel.
The final integral may be small even though intermediate accumulated magnitudes are large.
Relative error should then be interpreted carefully.
Common Error: Treating the Integrand as Exact
If \(f(x)\) is itself computed approximately, the quadrature result inherits that error.
Quadrature error and function-evaluation error should be analyzed separately.
Common Error: Using an Inappropriate Variable Scale
Very long or highly compressed intervals can make a problem harder to analyze numerically.
Mapping to a standard interval often improves both implementation and interpretation.
Example: Composite Trapezoidal Rule
Approximate
\[ \int_0^2 x^2\,dx \]using \(n=2\) subintervals.
Then
\[ h=1, \qquad x_0=0,\quad x_1=1,\quad x_2=2. \]Therefore,
\[ T_2 = 1 \left[ \frac12(0)+1+\frac12(4) \right] = \boxed{3}. \]Example: Composite Simpson Rule
Using the same integral and \(n=2\),
\[ S_2 = \frac13 \left[ 0+4(1)+4 \right] = \boxed{\frac83}. \]The result is exact.
Example: Two-Point Gauss Rule
Approximate
\[ \int_{-1}^{1}x^2\,dx. \]The two-point Gauss rule gives
\[ \left(-\frac{1}{\sqrt3}\right)^2 + \left(\frac{1}{\sqrt3}\right)^2 = \frac13+\frac13 = \boxed{\frac23}. \]This is exact because the rule integrates polynomials through degree \(3\).
Practice 1: Midpoint Rule
Approximate
\[ \int_0^4 x\,dx \]with one midpoint rectangle.
Practice 2: Trapezoidal Rule
Approximate
\[ \int_0^2 x\,dx \]with one trapezoid.
Practice 3: Simpson's Rule
Approximate
\[ \int_0^2 x^3\,dx \]with one Simpson panel.
Practice 4: Composite Trapezoidal Formula
State the composite trapezoidal rule for equally spaced nodes.
Practice 5: Simpson Subinterval Requirement
What restriction must the number of subintervals satisfy in composite Simpson's rule?
Practice 6: Orders of Accuracy
State the leading composite error order of:
- trapezoidal rule;
- Simpson's rule.
Practice 7: Gaussian Degree of Exactness
What polynomial degree is integrated exactly by an \(n\)-point Gauss-Legendre rule?
Practice 8: Adaptive Integration
What is the main advantage of adaptive quadrature over uniform refinement?
Practice 9: Improper Integral
Why can a standard closed Newton-Cotes rule fail on
\[ \int_0^1\frac{1}{\sqrt{x}}\,dx? \]Practice 10: Monte Carlo Scaling
Write the basic Monte Carlo estimate of an integral over a region \(D\) using \(N\) uniform random samples.
Practice Answers
Practice 1
The midpoint is \(2\), so
\[ M = 4f(2) = 4(2) = \boxed{8}. \]Practice 2
\[ T = \frac{2}{2} [0+2] = \boxed{2}. \]Practice 3
Simpson's rule gives
\[ S = \frac{2}{6} \left[ 0+4(1)+8 \right] = \frac{12}{3} = \boxed{4}. \]This is exact because \(x^3\) is degree \(3\).
Practice 4
\[ \boxed{ T_n = h \left[ \frac12f(x_0) + \sum_{i=1}^{n-1}f(x_i) + \frac12f(x_n) \right] }. \]Practice 5
The number of equal subintervals must be
\[ \boxed{\text{even}}. \]Practice 6
- composite trapezoidal rule: \(\boxed{O(h^2)}\);
- composite Simpson's rule: \(\boxed{O(h^4)}\).
Practice 7
\[ \boxed{2n-1}. \]Practice 8
Adaptive quadrature concentrates additional evaluations only where the integrand needs more resolution, reducing wasted work on smooth regions.
Practice 9
The integrand is undefined at \(x=0\). A closed rule that directly evaluates the endpoint therefore fails without a transformation or special treatment.
Practice 10
\[ \boxed{ I \approx |D| \frac1N \sum_{i=1}^{N} f(X_i) }. \]What to Remember
Numerical integration approximates
\[ \boxed{ I=\int_a^b f(x)\,dx } \]using weighted samples or integrated local approximations.
- rectangle rules use constant approximations;
- the trapezoidal rule integrates a linear interpolant;
- Simpson's rule integrates a quadratic interpolant and is exact through degree \(3\);
- composite trapezoidal error is \(O(h^2)\);
- composite Simpson error is \(O(h^4)\);
- Romberg integration uses Richardson extrapolation on trapezoidal estimates;
- Gaussian quadrature chooses nodes and weights to maximize polynomial exactness;
- an \(n\)-point Gauss-Legendre rule is exact through degree \(2n-1\);
- adaptive quadrature refines only where the integrand needs more resolution;
- singular, oscillatory, or sharply peaked integrands may require special treatment;
- high-dimensional integration introduces the curse of dimensionality;
- Monte Carlo integration becomes useful when deterministic tensor-product rules become too expensive;
- convergence studies and error estimates are essential for validating a quadrature result.
Where We Go Next
Numerical differentiation and integration approximate derivatives and accumulated quantities from discrete information. The next step is to combine these ideas to approximate entire differential-equation solutions over time or space.
The next lesson, Numerical Differential Equations, develops Euler methods, Runge-Kutta methods, local and global error, stability, stiffness, step-size control, and numerical treatment of initial-value problems.