Title: Fish 507; Lecture 23
1Interpolation Methods
2What is Interpolation?
- There is a function f(x) that is very expensive
(or difficult) to evaluate. We wish to compute
f(x) for many values of x as cheaply as
possible. - We have data points (x,yg(x)) but do not know
the function g. We wish to compute g(x) for
values of x other than those for which the data
points are available.
3Consider the Runge Function
Given these seven data points, how do we
determine the values of y for other values for
x?
4Linear Interpolation-I
- Approximate f(x) between xi and xi1 by a
straight line connecting xi and xi1, i.e. - or
5Linear Interpolation-II
Linear interpolation is very accurate in this
case, but it requires knowing between which
values of xi the x we are interested in lies
6Linear Interpolation-III
- R includes the function approx which can be used
to perform linear interpolation - approx(x, y, xout)
- x,y the vector of (x,y) pairs on which to base
the calculations. - xout a vector of values of x for which values
of f(x) are required.
7Polynomial Interpolation-I
- There are many ways to approximate a function
using a polynomial. The simplest is to
approximate the function by - Note that
- this approximation is exact for xx1, x2, x3,
etc. and - a single equation is used to approximate the
entire function.
8Polynomial Interpolation-II
The polynomial passes though all seven
points but.
9Polynomial Interpolation-III
A better approximation can be obtained in this
case by applying polynomial interpolation with
N3 (i.e. quadratic functions)
10Rational Interpolation-I
- Rather than approximating a function by a simple
polynomial, we can approximate it by the ratio of
polynomials, i.e. - This approach can deal with poles in the function
to be approximated (unfortunately even when they
are not there).
11Rational Interpolation-II
Rational approximation performs better than
simple polynomial interpolation for the Runge
function (as expected?)
12More Examples
13Splines-I
- Cubic splines are piecewise cubic polynomials
that approximate a function such that - The zeroth, first and second derivatives are
continuous - the approximating function matches the points on
which it is based and - the second derivatives of the approximating
function match the second derivatives of the
function.
14Splines II
- Define a set of points (called knots) these
are the points for which data are available - The cubic spline is defined by the equation
- This equation has four parameters for each pair
of knots. The values for these parameters are
defined from the function values at the knots and
the (numerical) second derivatives at the knots.
15Splines III
The cubic spline is able to satisfactorily mimic
the underlying shape almost perfectly
y3 lt- spline(x,y) lines(y3,col19,lwd3)
16Splines -IV
- Using a Spline for interpolation requires that
the values for the parameters be computed. - In order to predict the value of y for some x, it
is necessary to apply a search algorithm (e.g.
bisection) to find the knots between which x lies.
17Splines V
- R includes the function spline
- spline(x, y, n, periodic, xmin, xmax )
- Arguments
- x, y the data (required)
- n number of output points
- periodic is the function periodic?
- xmin / xmax range to predict over.
- Output
- List with components x and y that provide the
results of the cubic spline fitting.
18Splines VI
Spline vs linear interpolation based on 8, 12 and
16 points
19Interpolation and Extrapolation-I
- Polynomial and rational approximation are methods
for interpolation. In principle, they can be used
to extrapolate beyond the range of the xs for
which data are available. This should, however,
be done with considerable caution. - Consider the following selectivity ogive.
20Interpolation and Extrapolation-II
3-point polynomial interpolation. Extrapolation
beyond age0 and age25 is based on the results
for the first and last intervals