[ Home ] Numerical Methods. Note « 6 »

Lectures
Polynomial interpolation
Lagrange interpolating polynomial
P(x) = ∑i yi Πk≠i (x-xk)/Πk≠i (xi-xk)
Might show erratic behaviour for higher degree polynomials. Not useful for n larger than, say, 5.
Rational function interpolation (fraction of two
R(x) = Pm(x)/Qk(x)
Potentially larger range of conversion than polynomial. Still dangerous for higher orders.
Spline interpolation
In between the tabulated points the function is approximated by a polynomial:
y[i](x) = yi + bi (x-xi) + ci (x-xi)2 + di (x-xi)3 + ...
The coefficients b, c, d,... are calculated from the continuity equations
y[i-1](xi)=y[i](xi),
y[i-1]'(xi)=y[i]'(xi),
y[i-1]''(xi)=y[i]''(xi),
...
The most popular spline is cubic spline. Here are the fortran routines from netlib.org spline.f - for constructing the spline (calculating coefficients b,c,d) and seval.f - for the very interpolation.
Integration and differentiation of tabulated functions
Problems
  1. Make a function locate(x,xtab[]) which, given an array xtab[] and a number x, finds index j such that x lies in between xtab[j] and xtab[j+1].
  2. Make a function linterp(x,xtab[],ytab[]) which does a linear interpolation of a function represented by a table xtab[], ytab[] at a point x.
    or
    Make a subroutine qspline(xtab[],ytab[],n,b[],c[]) which calculates the coefficients b and c for quadratic spline. Make a separate subroutine qseval(xtab[],ytab[],n,b[],c[],x) which does quadratic interpolation with given b[] and c[].
  3. Make a polynomial and a spline interpolation of the tabulated function
    xi = i + sin(i)/2, yi = i + cos(i2), i=0,10
    Make a plot of the result.
    Hint: this is an example from GSL.

"Copyleft" © 2001 D.V.Fedorov (fedorov@ifa.au.dk)