L-20 MCS 471 Friday 22 February 2002: Lagrange and Neville Interpolation

This worksheet illustrates some of the concepts we discussed in class.

1. The Interpolation Problem

We show that the problem of finding an interpolating polynomial through (x[i],f[i]), i=0,1,..,n is equivalent to solving a linear system.

> n := 3;

n := 3

The interpolating polynomial has unknown coefficients a[i]:

> p := sum(a['i']*z^'i','i'=0..n);

p := a[0]+a[1]*z+a[2]*z^2+a[3]*z^3

The interpolation conditions are

> for i from 0 to n do

> eqs[i] := subs(z=x[i],p) = f[i];

> od;

eqs[0] := a[0]+a[1]*x[0]+a[2]*x[0]^2+a[3]*x[0]^3 = ...

eqs[1] := a[0]+a[1]*x[1]+a[2]*x[1]^2+a[3]*x[1]^3 = ...

eqs[2] := a[0]+a[1]*x[2]+a[2]*x[2]^2+a[3]*x[2]^3 = ...

eqs[3] := a[0]+a[1]*x[3]+a[2]*x[3]^2+a[3]*x[3]^3 = ...

Now we extract the matrix of this linear system

> unknowns := [seq(a[i],i=0..n)];

unknowns := [a[0], a[1], a[2], a[3]]

> listeqs := convert(eqs,list):

> A:= linalg[genmatrix](listeqs,unknowns);

A := matrix([[1, x[0], x[0]^2, x[0]^3], [1, x[1], x...

and compute the determinant of the matrix (in factored form):

> factor(linalg[det](A));

(-x[3]+x[2])*(x[1]-x[3])*(x[1]-x[2])*(-x[3]+x[0])*(...

We see that the determinant is different from zero provided x[i] /= x[j], for i /= j.

2. Lagrange Interpolation

One solution to the interpolation problem is to take a special form of the interpolating polynomial:

> q := sum(l['i']*f['i'],'i'=0..n);

q := l[0]*f[0]+l[1]*f[1]+l[2]*f[2]+l[3]*f[3]

where l[i] is defined as follows:

> for i from 0 to n do

> l[i] := product((z-x['j'])/(x['i']-x['j']),'j'=0..i-1)*product((z-x['j'])/(x['i']-x['j']),'j'=i+1..n);

> od;

l[0] := (z-x[1])/(x[0]-x[1])*(z-x[2])/(x[0]-x[2])*(...

l[1] := (z-x[0])/(x[1]-x[0])*(z-x[2])/(x[1]-x[2])*(...

l[2] := (z-x[0])/(x[2]-x[0])*(z-x[1])/(x[2]-x[1])*(...

l[3] := (z-x[0])/(x[3]-x[0])*(z-x[1])/(x[3]-x[1])*(...

This is how our interpolating polynomial looks like:

> q;

(z-x[1])/(x[0]-x[1])*(z-x[2])/(x[0]-x[2])*(z-x[3])/...
(z-x[1])/(x[0]-x[1])*(z-x[2])/(x[0]-x[2])*(z-x[3])/...

We turn the expression for q into a function for evaluation:

> funq := unapply(q,z):

Checking the interpolation conditions:

> for i from 0 to n do

> funq(x[i]);

> od;

f[0]

f[1]

f[2]

f[3]

3. Neville Interpolation

One shortcoming of Lagrange interpolation is that everything has to be recalculated when an additional data point is used. Here we present the idea behind Neville interpolation.

Above we constructed q as the interpolating polynomial through (x[i],f[i]), i=0,1,..,n. Let us construct the interpolating polynomial through (x[i],f[i]), i = 1,2,..,n+1.

> q1 := sum(k['i']*f['i'],'i'=1..n+1);

q1 := k[1]*f[1]+k[2]*f[2]+k[3]*f[3]+k[4]*f[4]

where k is defined in similar fashion as the l[i] above:

> for i from 1 to n+1 do
k[i] := product((z-x['j'])/(x['i']-x['j']),'j'=1..i-1)*product((z-x['j'])/(x['i']-x['j']),'j'=i+1..n+1);
od;

k[1] := (z-x[2])/(x[1]-x[2])*(z-x[3])/(x[1]-x[3])*(...

k[2] := (z-x[1])/(x[2]-x[1])*(z-x[3])/(-x[3]+x[2])*...

k[3] := (z-x[1])/(x[3]-x[1])*(z-x[2])/(x[3]-x[2])*(...

k[4] := (z-x[1])/(x[4]-x[1])*(z-x[2])/(x[4]-x[2])*(...

Then the interpolating polynomial looks like

> q1;

(z-x[2])/(x[1]-x[2])*(z-x[3])/(x[1]-x[3])*(z-x[4])/...
(z-x[2])/(x[1]-x[2])*(z-x[3])/(x[1]-x[3])*(z-x[4])/...

As q interpolates through (x[i],f[i]), i = 0,1,..,n, and q1 through (x[i],f[i]), i=1,2,..,n+1, we now claim that the following polynomial interpolates through all n+2 points:

> qq1 := (z-x[n+1])/(x[0]-x[n+1])*'q' + (z-x[0])/(x[n+1]-x[0])*'q1';

qq1 := (z-x[4])/(x[0]-x[4])*q+(z-x[0])/(x[4]-x[0])*...

Or fully evaluated:

> eqq1 := map(t->eval(t),qq1);

eqq1 := (z-x[4])/(x[0]-x[4])*((z-x[1])/(x[0]-x[1])*...
eqq1 := (z-x[4])/(x[0]-x[4])*((z-x[1])/(x[0]-x[1])*...
eqq1 := (z-x[4])/(x[0]-x[4])*((z-x[1])/(x[0]-x[1])*...
eqq1 := (z-x[4])/(x[0]-x[4])*((z-x[1])/(x[0]-x[1])*...

To check the claim we create a function and evaluate at the interpolation points:

> funqq1 := unapply(eqq1,z):

> for i from 0 to n+1 do

> simplify(funqq1(x[i]));

> od;

f[0]

f[1]

f[2]

f[3]

f[4]

This leads to a general interpolation method. To be continued...