Numerical Integration
Elementary Numerical Integration
The basic method for approximating is called numerical quadrature and uses the sum
We'll cover quadrature methods based on interpolation polynomials. The idea is to select a set of distinct nodes from the interval use them to construct a Lagrange interpolating polynomial and its error term, and then integrate those over
When we use equally spaced nodes, the approximations produced from first and second Lagrange polynomials are known as the Trapezoidal rule and Simpson's rule. These are commonly introduced in calculus courses.
The Trapezoidal rule is
where and is some value in
Simpson's rule uses three points and is
where and is some value in
Perhaps simpler to read:
In general, integrating Lagrange interpolating polynomials and there error terms give us Newton-Cotes formulas; the Trapezoidal rule and Simpson's rule are the first two examples of these.
Composite Numerical Integration
Newton-Cotes formulas don't work well on large intervals, because it requires high-degree formulas, which are difficult to derive, and the required interpolating polynomials can oscillate wildly.
A piecewise approach using low-order Newton-Cotes formulas is more often applied. We can break an interval down into subintervals, and then apply a Newton-Cotes formula across subintervals. This leads to an approximation with a much lower error.
For example, the Composite Simpson's rule breaks an interval down into subintervals for some even applies Simpson's rule on each consecutive pair of subintervals, and then sums the results.
Theorem: Let be even, and for each There exists a for which the Composite Simpson's rule for subintervals can be written with its error term as
Here's psuedocode that uses the Composite Simpson's rule on subintervals. This is the most frequently used general-purpose quadrature algorithm.
float compositeSimpsons(float a, float b, int n, function f) {
assert(b > a);
assert(n > 0 && n % 2 == 0);
float h = (b - a) / n;
float XI0 = f(a) + f(b);
float XI1 = 0;
float XI2 = 0;
for (int i = 1; i <= n - 1; i++) {
float X = a + i * h;
if (i % 2 == 0) {
XI2 += f(X);
} else {
XI1 += f(x)
}
}
return h * (XI0 + 2 * XI2 + 4 * XI1) / 3;
}
We can use this approach for other Newton-Cotes formulas. The Trapezoidal rule requires only one interval for each application, so we can use either odd or even
Theorem: Let and for each There exists a for which the Composite Trapezoidal rule for subintervals can be written with its error term as
For the Composite Midpoint Rule we again require even .
Theorem: Let be even, and for each There exists a for which the Composite Midpoint rule for subintervals can be written with its error term as
Gaussian Quadrature
Recall that Newton-Cotes formulas use values of the function at equally spaced points. While convenient, this can significantly reduce accuracy of the approximation.
In contrast, Gaussian quadrature picks the optimal nodes in and coefficients to minimize expected error in the approximation
Picking these optimal nodes and coefficients allows Gaussian quadrature to be more accurate than Newton-Cotes formulas for the same number of nodes. While Newton-Cotes formulas can exactly approximate polynomials up of up to degree Gaussian quadrature can exactly approximatie polynomials of up to degree This is achievable because the coefficients are arbitrary and the nodes are restricted only in being within so we get parameters to choose, and the class of polynomials of degree at most also contains parameters, so properly picking parameters allows us to exactly approximate any of those polynomials.
For example, let's say we want to determine and so that
gives the exact result whenver is a polynomial of degree 3 or less, that is, when
for some constants
Now,
so we neeed a formula that gives exact results when is and That us, we need such that
(Note that the RHS values and in these equations are just the values of the preceding definite integrals.)
Now we have a system of unknowns an equations which we can solve to find
This gives the approximation formula
which as degree of precision three, meaining it produces the exact result for every polynomial of degree three or less. This is pretty amazing.
Legendre Polynomials
There is an easier way to determine the nodes and coefficients for the formulas that give exact results for higher-degree polynomials.
We will use a collection of orthogonal polynomials called the Legendre Polynomials, denoted here as and having the properties
- For each , is a monic polynomial of degree
- whenever is a polynomial of degree less than
Note that these polynomials form an orthogonal basis for the monic polynomials over the interval
The roots of these polynomials are distinct, lie in are symmetric with respect to the origin, and are the correct choice for determining the parameters that give us the nodes and coefficients for Gaussian quadrature.
The proof and reasoning are excluded here, but the procedure, using a the roots of the Legendre polynomials and associated coefficients (which are widely available in tables) is to approximate with precision as
Gaussian Quadrature on Arbitrary Intervals
This is all well and good if the interval in question is but what if it isn't?
We can take advantage of the fact that over an arbitrary interval can be transformed into an integral over by using a change of variable:
Thus,