Interpolation and Extrapolation
From Wikiversity
This course is still very much in the rough!
Contents |
[edit] Summary
This course belongs to the track Numerical Algorithms in the Department of Scientific Computing in the School of Computer Science.
In this course, students will learn how to approximate discrete data. Different representations and techniques for the approximation are discussed.
[edit] Discrete Data
Discrete data arises from measurements of f(x) or when f(x) is difficult or expensive to evaluate.
In general, discrete data is given by a set of nodes xi,
and the function f(x) evaluated at these points: fi = f(xi),
.
In the following, we will refer to the individual nodes and function values as xi and fi respectively. The vectors of the n nodes or function values are written as
and
respectively.
We will also always assume that the xi are distinct.
[edit] Polynomial Interpolation
Although there are many ways of representing a function f(x), polynomials are the tool of choice for interpolation. As the Taylor series expansion of a function f(x) around 0 shows, every continuous, differentiable function has a polynomial representation
-
f(x) = 
= 
= 
in which the
are the exact weights.
If a function f(x) is assumed to be continuous and differentiable and we assume that it's derivatives f(n)(0) are zero or of negligible magnitude for increasing n, it is a good idea to approximate the function with a polynomial.
Given n distinct nodes xi,
at which the function values fi = f(xi) are known, we can construct an interpolating polynomial g(x) such that g(xi) = fi for all
. Such an interpolating polynomial with degree
is unique. However infinitely many such polynomials can be found with degree
.
- Any nice way of deriving the interpolation error?
[edit] The Vandermonde Matrix
By definition as given above, our polynomial
must interpolate the function f(x) at the n nodes xi. This leads to the following system of n linear equations in the coefficients ai:
-
f(x1) = 
f(x2) = 

f(xn) = 
We can re-write this system of linear equation in matrix notation as
where
is the vector of the ai,
coefficients and
is the so-called moment matrix or Vandermonde matrix with
or
This linear system of equations can be solved for
using Gauss elimination or other methods.
The following shows how this can be done in Matlab or GNU Octave.
% declare our function f
f = inline('sin(pi*2*x)','x')
% order of the interpolation?
n = 5
% declare the nodes x_i as random in [0,1]
x = rand(n,1)
% create the moment matrix
M = zeros(n)
for i=1:n
M(:,i) = x.^(i-1);
end
% solve for the coefficients a
a = M \ f(x)
% compute g(x)
g = ones(n,1) * a(1)
for i=2:n
g = g + x.^(i-1)*a(i);
end;
% how good was the approximation?
g - f(x)
However practical it may seem, the Vandermonde matrix is not especially suited for more than just a few nodes. Due to it's special structure, the Condition Number of the Vandermode matrix increases with n.
If in the above example we set n = 10 and compute
with
% solve for the coefficients a a = inv(M) * f(x)
the approximation is only good up to 10 digits. For n = 20 it is accurate only to one digit.
We must therefore consider other means of computing and/or representing g(x).
[edit] Lagrange Interpolation
Given a set of n nodes xi,
, we define the kth Lagrange Polynomial as the polynomial of degree n − 1 that satisifies
Maybe add a nice plot of a Lagrange polynomial over a few nodes?
The first condition, namely that
for
can be satisfied by construction. Since every polynomial of degree n − 1 can be represented as the product
where the ξi are the roots of g(x) and c is some constant, we can construct
as
.
The polynomial
is of order n − 1 and satisifies the first condition, namely that
for
.
Since, by construction, the n − 1 roots of
are at the nodes xi,
, we know that the value of
cannot be zero. This value, however, should be 1 by definition. We can enforce this by scaling
by
:
-

= 
= 
If we insert any xi,
into the above equation, the nominator becomes 0 and the first condition is satisified. If we insert xk, the nominator and the denominator are the same and we get 1, which means that the second condition is also satisfied.
We can now use the Lagrange polynomials
to construct a polynomial g(x) of degree n − 1 which interpolates the n function values fi at the points xi.
Consider that, given the definition of
,
.
Therefore, if we define g(x) as
then g(xi) = fi for all
. Since the
are all of degree n − 1, the weighted sum of these polynomials is also of degree n − 1.
Therefore, g(x) is the polynomial of degree n − 1 which interpolates the n values fi at the nodes xi.
The representation with Lagrange polynomials has some advantages over the monomial representation
described in the previous section.
First of all, once the Lagrange polynomials have been computed over a set of nodes xi, computing the interpolating polynomial for a new set of function values fi is trivial, since these only need to be multiplied with the Lagrange polynomials, which are independent of the fi.
Another advantage is that the representation can easily be extended if additional points are added. The Lagrange polynomial
, obtained by adding a point xn + 1 to the interpolation, is
.
Only the new polynomial
would need to be re-computed from scratch.
In the monomial representation, adding a point would involve adding an extra line and column to the Vandermonde matrix and re-computing the solution.
- Add a word on Barycentric interpolation to facilitate adding points.
[edit] Newton Interpolation
Given a set of n function values fi evaluated at the nodes xi, the Newton polynomial is defined as the sum
where the ni(x) are the n Newton basis polynomials defined by
-
n1(x) = 1 ni(x) =
.
An interpolation polynomial of degree n+1 can be easily obtained from that of degree n by just adding one more node point xn + 1 and adding a polynomial of degree n+1 to g(x).






