Interpolation and Polynomial Approximation
The set of algebraic polynomials, which are functions of the form
where is a nonnegative integer and are real constants, are extremely useful for approximating functions.
Weierstrass Approximation Theorem: Suppose is defined and continuous on For each there exists a polynomial with the property that
In other words, for any continuous function, there is a polynomial that approximates the function as closely as desired.
Morever, it's trivial to differentiate and integrate polynomials, making them very amenable to calculus based analysis.
Taylor polynomials are one type of approximating polynomial, but because they concentrate all of their information near a point, they generally only approximate the function well near the point. Here, we'll investigate other types of polynomials that are more useful for approximating functions along an entire continuous interval by incorporating information from multiple points in the interval.
Lagrange Interpolating Polynomials
If we have two points, and we can make a linear polynomial that passes through both points, and use it to approximate a function for which and We call this an interpolating polynomial because it agrees with the values of at the given points. We can use this polynomial for approximating within the interval and we call this process polynomial interpolation.
If we define the functions
then linear Lagrange interpolating polynomial through and is
Note that
which implies that
and
Thus, is the unique polynomial of degree at most one that passes through both and
The functions and are called basis functions and serve to localize the influence of the values at the sample points. is 1 when at and 0 when at (and the opposite is true for ,) ensuring that only contributes to the function's value at and only contributes to the function's value at so that the polynomial agrees with at those points.
The numerator of will be when , and since we want its value to be there, we must make its denominator .
We can generalize this concept to work for more than two points. To approximate a function given sample points, we can construct a polynomial that passes through
To do so, for each we construct a function such that when and To make for we need the numerator to contain
To normalize the function so that , the denominator must contian the same term but evaluated at so we have
Now that we've described how to construct the basis functions, we can define the nth Lagrange interpolating polynomial with the following theorem.
Theorem: If are distinct numbers and is a function whose values are given at these numbers, then a unique polynomial of degree at most exists with
This polynomial is given by
where, for each
Sometimes we will write just instead of when the value of is clear.
Divided Differences
If is the interpolating polynomial that agrees with at points, it is unique, but it be written in multiple forms. An alternative form that uses divided differences of with respect to samples at are used to express in the form
for appropriate constants
To get a sense for how we find the constants, note that when we want and that since all terms in , other than , have in them and will thus be 0 at , must be
Similarly, at , all terms other than the first two will be 0, so we have
Substituting and then solving for gives
This process can be repeated to find more constants, but there is a simpler way.
Now for some new notation. We say that the zeroth divided difference of with respect to denoted as is just the value of at
Remaining divided differences are defined recursively; the first divided difference of with respect to and is denoted and defined as
The second divided difference is then
In general, the kth divided difference is
and finally we get the nth divided difference
This means that and in general
for each Now, we can rewrite as Newton's Divided Difference:
One important fact is that the value of is independent of the order of the numbers That means we can add a sample point in the middle of others and calculate the additional term in order to improve the accuracy of the interpolation.
Here's psuedocode:
float[] newtonsDividedDifference(float xs, float ys) {
assert(len(xs) = len(ys));
int n = len(xs) - 1;
float F[n+1][n+1];
float as[n+1];
for (int i = 0; i <= n; i++) {
F[i][0] = ys[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
//F[i][j] = f[x_{i - j}, ..., x_i]
F[i][j] = (F[i][j-1] - F[i - 1][j - 1])/(xs[i] - xs[i - j]);
if (i == j) {
as[i][i] = F[i][i];
}
}
}
return as;
}
Chebyshev Polynomials
We can use the orthogonal family of Chebyshev Polynomials to pick optimal nodes for minimizing error for approximation of a function with Lagrange Interpolating Polynomials.
Doing so requires either that the function we're approximating is on or doing some more advanced transformations I won't cover here, so just assume that's the domain.
Then, to make we pick the nodes as the roots of the monic Chebyshev Polynomial Those nodes are then given by
We then proceed as usual using one of the above methods.
Cubic Splines
Using a single high-degree polynomial to approximate a function on an interval has some issues. Particualarly, high-degree polynomials can oscillate erratically.
Another approach is to use a lower degree polynomial to approximate the subinterval between each pair of successive points in the general interval; this is called piecewise-polynomial approximation.
The simplest form of this is piecewise-linear approximation, where we join each pair of successive sample points with a series of straight line segments. This can produce reasonable approximations but has a major disadvantage in there is no differentiability at the endpoints of each subinterval (except in the special case that all points fall on the same line.) This means the approximating function is not continuously differentiable - it's not smooth - which typically doesn't match the behavior of the phsyical system being approximated.
A better - and more common - approach is cubic spline interpolation. A cubic polynomial has 4 constants, which provides sufficient flexibility so that the approximating function is twice differentiable on the entire interval.
Given a function defined on and a set of nodes a cubic spline interpolant for is a function that satisfies the following conditions:
- is a cubic polynomial, denoted as , on the subinterval for each ( is a piecewise function with each piece being composed of a cubic polynomial that covers the subinterval between two successive points, overlapping at the endpoints)
- and for each (the cubic polynomial for each subinterval agrees with the function being approximated at the endpoints of each subinterval.)
- for each (the cubic polynomials for two adjacent subintervals have the same value at the point they overlap.)
- Next,
for each (the first derivatives of the cubic polynomials for two adjacent subintervals have the same value at the point they overlap.)
- Next,
for each (the second derivatives of the cubic polynomials for two adjacent subintervals have the same value at the point they overlap.)
- One of the following sets of boundary conditions is satisfied:
- (natural or free boundary.)
- and (clamped boundary.)
A natural spline approximates the shape a long flexible rod would take when forced to go through the sample points. Clamped boundary conditions generally lead to more accurate approximations, but require information about the derivatives of the function at its endpoints.
The procedure for finding a cubic spline interpolation over subintervals is to setup a system of equations using the contraints given above and to solve for the unknown constants. There will be cubic polynomials, each with 4 constants, so equations will be needed to find the constants.
Each cubic polynomial is of the form