Interpolation has fallen by the wayside since the computer has replaced the use of precise mathematical tables, but the technique is still important in the analysis of laboratory data, for making predictions about the outcome of experiments that measure the values of some quantity between bracketing known values as a function of some parameter.
Suppose that you have a table or array of the values of a function
One can perform a linear interpolation to obtain for
by assuming that the curve is well approximated by a straight line between adjacent points listed in the table
If the points are evenly spaced with , the Lagrange interpolation can provide better accuracy. Notice that
in which is the shift operator
Then
which we can expand as
Collect terms together and use the fact that
then
and so on, here correct to third order differences. Notice that if ,for , we simply obtain .
This can provide a significant improvement over linear interpolation, and can be used to develop predict-correct numerical integration algorithms. For example consider a function and its derivative , and apply this to the case to , we obtain
Now consider numerically integrating from to by Simpson’s rule
and into this insert the previous interpolation formula to eliminate on the right side to obtain the interpolation
Bashford-Adams-Milne Integration
This method is a predict-correct method based on the interpolation formula that we just derived. Consider a differential equation
and make a guess solution that satisfies the boundary conditions (say ) and build up a table from the guess solution. From the derivatives of the guess solution make the predictions
then compute from these new values of the derivatives from
and then correct the prediction using Simpson’s rule
We simply iterate the procedure until desired accuracy is achieved. This method does not suffer from the accumulated errors of Euler or Euler-Cromer methods.
Here is a simple implementation in C to solve , .
/* BAM algorithm, for y'=F(y,x), in this case F(y,x)=1-y^2 */
#include<stdio.h>
#define N 1000
double dx;
int n,m,p;
double x[N],y[N],yp[N], *yptr, *ypptr, *xptr;
double func(double Y, double X);
main(){
dx=0.001;
/* initialise with a guess */
for(n=0;n<1000;n++){
x[n]=(double)n*dx;
y[n]=x[n];
yp[n]=1.0;}
yptr=&y[0];
ypptr=&yp[0];
xptr=&x[0];
for(n=0;n<1;n++){ /* iterate, begin with one cycle */
/* predict */
for(m=4; m<N;m++){
*(yptr+m)=*(yptr+m-4)+(8.0*dx/3.0)*( *(ypptr+m-3) -0.5*(*(ypptr+m-2)) + \
*(ypptr+m-1));
/* correct */
*(ypptr+m)=func(*(yptr+m), x[m]);
*(yptr+m)=*(yptr+m-2)+(dx/3.0)*( *(ypptr+m-2) +4.0*(*(ypptr+m-1)) + \
*(ypptr+m));
}
} /* end of iterative loop */
for(n=0;n<N-4;n++){
printf("%f\t%f\n", *(xptr+n), *(yptr+n)); /* print x[n] \t y[n] to STDOUT */
}
return;
}
double func(double Y, double X) /* user definable */
{
double tmp;
tmp=1.0-Y*Y;
return(tmp);
}
I have used pointers to represent the arrays, I hope pointers don’t scare you too much.