AMTH247 Lecture 11
Interpolation I
Reading: Heath §7.1, §7.2, §7.3.1
All the Scilab functions used in this lecture are in the
file l11.sci in the directory for the lecture.
The same thing will apply to future lectures.
The general problem of interpolation is the following:
Given data
 |
(1) |
Find a function
such that
 |
(2) |
The equation (2) is called the interpolation
equation or interpolation condition.
It says that the function
passes through the data points.
A function
satisfying the interpolation condition
is called an interpolating function for the data.
There are numerous applications calling for the
construction of an interpolating function for a set of data.
Some of these are:
- Plotting a smooth curve through discrete data points.
- Reading between lines of a table.
- Numerical manipulation, e.g. integration, of tabular data.
Interpolation, as we will see later, is the basis
of variety of other numerical algorithms.
Heath, §7.1, gives extended account of the uses of interpolation.
Of course, for any set of data there is an unlimited
number of interpolating functions.
We will restrict attention to linear interpolation
where the interpolating function can be expressed as
a linear combination
 |
(3) |
of
basis functions
.
We will see shortly, that for the linear interpolation problem to be well posed,
the number of basis functions must be equal to the number of data points.
The problem of determining the interpolating function then becomes
one of determining the coefficients
of the basis functions
. These coefficients are determined by the interpolation
conditions (2).
We will interpolate the data
 |
-1 |
0 |
1 |
 |
1.4 |
0.8 |
1.7 |
by a function of the form
In this case the basis functions are
Our problem is to determine the coefficients
,
,
.
Applying the interpolation conditions, equation (2),
to the function
at each of the three data points gives
the system of equations
This is a set of three linear equations
for the three unknown coefficients,
,
,
.
It is easily solved in Scilab
-->a = [exp(1) 1 exp(-1)
-->1 1 1
-->exp(-1) 1 exp(1)]
a =
! 2.7182818 1. 0.3678794 !
! 1. 1. 1. !
! 0.3678794 1. 2.7182818 !
-->b = [1.4 0.8 1.7]'
b =
! 1.4 !
! 0.8 !
! 1.7 !
-->x = a\b
x =
! 0.6266863 !
! - 0.5810104 !
! 0.7543241 !
So our interpolating function is
It is easy to graph the interpolating function:
-->t = (-1:0.01:1)';
-->y = x(1)*exp(-t) + x(2) + x(3)*exp(t);
-->plot2d(t,y)
Just as in the example above, the determination of the
coefficients in a general linear interpolation problem
reduces to solving a system of linear equations.
Given data
and basis functions
, our
problem is to determine coefficients
such that
the function
satisfies the interpolation conditions
In terms of the basis functions, the interpolation conditions are
or, writing the equation for each data point,
This is a system of
linear coefficients for the
coefficients
.
In matrix form, these equations are
 |
(4) |
The
matrix in this equation is formed by evaluating
the
basis functions
at the
data points
.
It is called the basis matrix.
Again we will interpolate the data
 |
-1 |
0 |
1 |
 |
1.4 |
0.8 |
1.7 |
this time by a quadratic polynomial
In this case the basis functions are
The basis matrix is
and we need to solve
Solving the problem in Scilab:
-->a = [1 -1 1
-->1 0 0
-->1 1 1]
a =
! 1. - 1. 1. !
! 1. 0. 0. !
! 1. 1. 1. !
-->y = [1.4 0.8 1.7]'
y =
! 1.4 !
! 0.8 !
! 1.7 !
-->x = a\b
x =
! 0.8 !
! 0.15 !
! 0.75 !
giving the interpolating polynomial
We can evaluate and plot this polynomial
-->t = (-1:0.01:1)';
-->y = x(1) + x(2)*t + x(3)*t.^2;
-->plot2d(t,y)
The two different interpolating functions we have constructed
for our data give very similar, but not identical, graphs.
Choosing different sets of basis functions will, for a given
set of data, produce interpolating functions from
different classes of functions.
Some common classes of functions are
- Polynomials
- Trigonometric functions
- Splines
The choice of class of interpolating functions to use
for any particular set of data, depends on the data;
we choose a class of functions which seems
to give a good representation of the data.
Any such choice must be somewhat subjective, but sometimes we
have theoretical reasons for choosing a particular class
of interpolating functions.
Even for a single class of functions there can be different
choices of basis functions.
We will give several sets of basis functions for polynomials later.
Different bases, in this case, do not give different interpolating
functions, just different representations of that function.
The choice of basis has relevance to the computational problem
- Determining the coefficients
from the linear
equations (4):
the choice of basis functions determines the structure
of the basis matrix.
- For some choice of basis functions the basis matrix
may take a simple form, e.g. a triangular matrix,
for which determining the coefficients is easy.
- More generally, we would like the basis matrix to
be well-conditioned. This is particularly important
if the coefficients
are of interest in themselves
and need to be determined accurately.
- Even when the basis matrix is ill-conditioned,
the solution for the coefficients
may still
give a small residual, although it is quite
inaccurate. A small residual means that the
interpolating function still does a good job
of interpolating the data.
- Evaluating the interpolating function:
for most purposes
the interpolating function will be evaluated many times.
Therefore it is desirable to choose basis functions which
can be evaluated easily.
Given any set of data
there is a unique polynomial of degree at most
which interpolates the data.
Note that a polynomial of degree
has
coefficients,
the same as the number of data points.
The most obvious basis for the polynomials of degree at most
is the monomial basis of powers of
which gives the familiar representation of the interpolating
polynomial
For data
the basis matrix is
Note that the number of data points determines the number
of basis functions.
Below is a Scilab function to compute the basis matrix for
the monomial basis at a given set of data values.
The key point is to note that the columns of the basis matrix
are just powers
of the vector of data points considered as a column vector.
In the function monbasis (t) the vector t
of data points is assumed to be column vector.
function a = monbasis (t)
n = length(t)
a = zeros(n,n)
for j = 1:n
a(:,j) = t.^{j-1}
end
endfunction
Now, to compute the coefficients of the interpolating polynomial
we need to solve the linear system
where
is the basis matrix given above,
is the column vector of coefficients
, and
is the column vector of data values
.
We can write a Scilab function to compute the coefficients
of the interpolating polynomial in the monomial bases which
interpolates a given set of
data.
It is very simple:
function x = moninterp (t, y)
a = monbasis(t)
x = a\y
endfunction
We will do the same polynomial interpolation as we did
earlier, this time using moninterp:
-->t = [-1 0 1]'
t =
! - 1. !
! 0. !
! 1. !
-->y = [1.4 0.8 1.7]'
y =
! 1.4 !
! 0.8 !
! 1.7 !
-->x = moninterp(t,y)
x =
! 0.8 !
! 0.15 !
! 0.75 !
Once we have the coefficients of the interpolating polynomial
we need a procedure to evaluate it.
There is a clever method for evaluating polynomials.
The standard method writes a polynomial
evaluates the powers, multiplies by the coefficients and adds.
If we evaluate
by writing it
we get Horner's rule for evaluating a polynomial.
Horner's rule requires less arithmetic and is less
sensitive to rounding errors than the standard method.
It is easy modify Horner's method to evaluate
the derivatives of
at the same time the polynomial
is evaluated.
Here it is in Scilab function moneval
which takes a vector x of coefficients of a polynomial
and a vector t of points at which to evaluate the polynomial.
It returns the vector y of the values of the polynomial
at the points t evaluated by Horner's rule.
function y = moneval(x, t)
n = length(x);
y = zeros(t);
for i = n:-1:1
y = y.*t + x(i);
end
endfunction
We will use the data from Heath, p 309.
 |
1.0 |
2.0 |
3.0 |
4.0 |
5.0 |
6.0 |
 |
1.9 |
2.7 |
4.8 |
5.3 |
7.1 |
9.4 |
First we enter and plot the data
-->t =(1:6)'
t =
! 1. !
! 2. !
! 3. !
! 4. !
! 5. !
! 6. !
-->y = [1.9 2.7 4.8 5.3 7.1 9.4]'
y =
! 1.9 !
! 2.7 !
! 4.8 !
! 5.3 !
! 7.1 !
! 9.4 !
-->plot2d(t,y, style = -1)
Now we will compute the interpolating polynomial of degree 5 for
the data
-->x = moninterp(t, y)
x =
! 20.6 !
! - 40.241667 !
! 29.820833 !
! - 9.6291667 !
! 0.0791667 !
and evaluate and plot the interpolating polynomial
-->tt = (0:.01:7)';
-->yy = moneval(x, tt);
-->plot2d(tt, yy)
Finally we can compute the residual, the difference between
the data values and the polynomial values at the data points.
-->y1 = moneval(x, t)
y1 =
! 1.9 !
! 2.7 !
! 4.8 !
! 5.3 !
! 7.1 !
! 9.4 !
-->res = y1-y
res =
1.0E-13 *
! - 0.0133227 !
! 0.0976996 !
! - 0.0976996 !
! - 0.0976996 !
! 0.5861978 !
! 0.2664535 !
These residuals are rather large, suggesting that the solution
may be inaccurate. We can test this by looking at the condition
number of the basis matrix:
-->a = monbasis(t)
a =
! 1. 1. 1. 1. 1. 1. !
! 1. 2. 4. 8. 16. 32. !
! 1. 3. 9. 27. 81. 243. !
! 1. 4. 16. 64. 256. 1024. !
! 1. 5. 25. 125. 625. 3125. !
! 1. 6. 36. 216. 1296. 7776. !
-->cond(a)
ans =
731200.94
-->cond(a)*%eps
ans =
1.624E-10
and we see that while the residual is large, the expected
error in the coefficients is larger still.
This problem of the basis matrix having a large condition number is
typical of monomial bases.
AMTH247 Lecture 11
Interpolation I
This document was generated using the
LaTeX2HTML translator Version 2K.1beta (1.61)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split +0 lecture.tex
The translation was initiated by amth247 on 2003-05-05
amth247
2003-05-05