Interpolation and Extrapolation

From testwiki
Jump to navigation Jump to search

Template:Cleanup


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.

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, i=1n and the function f(x) evaluated at these points: fi=f(xi), i=1n.

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.

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) = f(0)+f(0)x+12f(0)x2+16f(0)x3+
= n=01n!f(n)(0)=anxn
= n=0anxn

in which the an=1n!f(n)(0) 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, i=1n 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 i=1n. Such an interpolating polynomial with degree n is unique. However infinitely many such polynomials can be found with degree >n.

Any nice way of deriving the interpolation error?

The Vandermonde Matrix

By definition as given above, our polynomial

g(x)=i=0n1aixi

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) = a0+a1x1+a2x12++an1x1n1
f(x2) = a0+a1x2+a2x22++an1x2n1
f(xn) = a0+a1xn+a2xn2++an1xnn1

We can re-write this system of linear equation in matrix notation as

๐Œ๐š=๐Ÿ

where ๐š is the vector of the ai, i=0n1 coefficients and ๐Œ is the so-called moment matrix or Vandermonde matrix with

๐Œ=[1x1x12x1n11x2x22x2n11xnxn2xnn1]

or

๐Œi,j=xij1

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).

Lagrange Interpolation

Given a set of n nodes xi, i=1n, we define the kth Lagrange Polynomial as the polynomial of degree n1 that satisifies

k(xi)={0ik1i=k

Maybe add a nice plot of a Lagrange polynomial over a few nodes?

The first condition, namely that k(xi)=0 for ik can be satisfied by construction. Since every polynomial of degree n1 can be represented as the product

g(x)=ci=1n1(xξi)

where the ξi are the roots of g(x) and c is some constant, we can construct k(x) as

k(x)=i=1,ikn(xxi).

The polynomial k(x) is of order n1 and satisifies the first condition, namely that k(xi)=0 for ik.

Since, by construction, the n1 roots of k(x) are at the nodes xi, ik, we know that the value of k(xk) cannot be zero. This value, however, should be 1 by definition. We can enforce this by scaling k(x) by k(xk)1:

k(x) = k(x)k(xk)
= i=1,ikn(xxi)i=1,ikn(xkxi)

If we insert any xi, ik 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 k(x) to construct a polynomial g(x) of degree n1 which interpolates the n function values fi at the points xi.

Consider that, given the definition of k(x),

fkk(xi)={fki=k0ik.

Therefore, if we define g(x) as

g(x)=k=1nfkk(x)

then g(xi)=fi for all i=1n. Since the k(x) are all of degree n1, the weighted sum of these polynomials is also of degree n1.

Therefore, g(x) is the polynomial of degree n1 which interpolates the n values fi at the nodes xi.

The representation with Lagrange polynomials has some advantages over the monomial representation g(x)=i=0n1aixi 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 k+(x), obtained by adding a point xn+1 to the interpolation, is

k+(x)=k(x)xxn+1xkxn+1.

Only the new polynomial n+1+(x) 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.

Newton Interpolation

Given a set of n function values fi evaluated at the nodes xi, the Newton polynomial is defined as the sum

g(x)=i=1naini(x)

where the ni(x) are the n Newton basis polynomials defined by

n1(x) = 1
ni(x) = k=1i1(xxk)for i>1.

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).

The Newton form of the interpolating polynomial is particularly suited to computations by hand, and underlies Neville's algorithm for polynomial interpolation. It is also directly related to the exact formula for the error term fig(xi). Any good text in numerical analysis will prove this formula and fully specify Neville's algorithm, usually doing both via divided differences.

(Should link to error formula, divided differences and Neville's algorithm, adding articles where they don't exist)

Interpolation error

When interpolating a given function f by a polynomial of degree n at the nodes x0,...,xn we get the error

f(x)pn(x)=f[x0,,xn,x]i=0n(xxi)

where

f[x0,,xn,x]

is the notation for divided differences.

If f is n + 1 times continuously differentiable on a closed interval I and pn(x) be a polynomial of degree at most n that interpolates f at n + 1 distinct points {xi} (i=0,1,...,n) in that interval. Then for each x in the interval there exists ξ in that interval such that

f(x)pn(x)=f(n+1)(ξ)(n+1)!i=0n(xxi)

The above error bound suggests choosing the interpolation points xi such that the product | ฮ  (xxi) | is as small as possible.

Proof

Let's set the error term is

Rn(x)=f(x)pn(x)

and set up a auxiliary function Y(t) and the function is

Y(t)=Rn(t)Rn(x)W(x) W(t)

where

W(t)=i=0n(txi)

and

W(x)=i=0n(xxi)

Since xi are roots of function f and pn(x), so we will have

Y(x)=Rn(x)Rn(x)W(x) W(x)=0

and

Y(xi)=Rn(xi)Rn(x)W(x) W(xi)=0

Then Y(t) has n+2 roots. From Rolle's theorem, Y(t) has n+1 roots, then Y(n+1)(t) has one root ξ, where ξ is in the interval I.

So we can get

Y(n+1)(t)=Rn(n+1)(t)Rn(x)W(x) (n+1)!

Since pn(x) is a polynomial of degree at most n, then

Rn(n+1)(t)=f(n+1)(t)

Thus

Y(n+1)(t)=f(n+1)(t)Rn(x)W(x) (n+1)!

Since ξ is the root of Y(n+1)(t), so

Y(n+1)(ξ)=f(n+1)(ξ)Rn(x)W(x) (n+1)!=0

Therefore

Rn(x)=f(x)pn(x)=f(n+1)(ξ)(n+1)!i=0n(xxi).

Switching Between Representations

Arbitrary Basis Functions

Piecewise Interpolation / Splines

B Splines

Radial Basis Functions

Extrapolation

Interpolation is the technique of estimating the value of a function for any intermediate value of the independent variable while the process of computing the value of the function outside the given range is called extrapolation.

Caution must be used when extrapolating, as assumptions outside the data region (linearization, general shape and slope) may breakdown.

Exercises