Interpolation and extrapolation (2D)

Header file interp2d.h

These methods operate on tables (arrays) of data.

bilinear interpolation/extrapolation: `bilininterp2d'

Takes an initial guess (e.g. the previous value) of the position of the ordinate in the table to speed the search phase if possible (see `tabpos').

Interface:

double bilininterp2d(
   const double x, const double y, // co-ordinates for interpolation
   const Array& xtab, // array of x values
   const Array& ytab, // array of y values
   const Matrix& ftab, // array of f(x,y) values, x.n by y.n
   const int ilastpos = -1, const int jlastpos = -1 // last positions, if known
)

Interface to calculate gradient:

Vector2d grad_bilininterp2d(
   const Vector2d& v, // co-ordinates for interpolation
   const Array& xtab, // array of x values
   const Array& ytab, // array of y values
   const Matrix& ftab, // array of f(x,y) values, x.n by y.n
   const int ilastpos = -1, const int jlastpos = -1 // last positions, if known
)

Example:

#include
...
Array xtab,ytab;
matrix ftab;
double x,y;
...
double f = bilininterp2d(x,y,xtab,ytab,ftab);
Vector2d v(x,y);
Vector2d gradf = grad_bilininterp2d(v,xtab,ytab,ftab);

polynomial interpolation/extrapolation: `bipolyinterp2d'

Takes an initial guess (e.g. the previous value) of the position of the ordinate in the table to speed the search phase if possible (see `tabpos').

Interface:

double bipolyinterp2d(
   const double x, const double y, // co-ordinates for interpolation
   const Array& xtab, // array of x values
   const Array& ytab, // array of y values
   const Matrix& ftab, // array of f(x,y) values, x.n by y.n
   const int xorder, const int yorder, // order of interpolating polynomials
   const int xfirst, // 1/0 to fit x/y direction first
   const int ilastpos = -1, const int jlastpos = -1 // last positions, if known
)

Interface to calculate gradient:

Vector2d grad_bipolyinterp2d(
   const Vector2d& v, // co-ordinates for interpolation
   const Array& xtab, // array of x values
   const Array& ytab, // array of y values
   const Matrix& ftab, // array of f(x,y) values, x.n by y.n
   const int xorder, const int yorder, // order of interpolating polynomials
   const int ilastpos = -1, const int jlastpos = -1 // last positions, if known
)
Note: xfirstis not used!

Example:

#include
...
Array xtab,ftab;
double x;
int xorder = 2, yorder = 2; // bi-quadratic
int xfirst = 1;
...
double f = bipolyinterp2d(x,y,xtab,ytab,ftab,xorder,yorder,xfirst);
Vector2d v(x,y);
Vector2d gradf = grad_bipolyinterp2d(v,xtab,ytab,ftab,xorder,yorder);

natural interpolation/extrapolation: `natinterp2d'

Uses the basis set {1,x,y,xy} to represent the data in each rectangle of the table.

Takes an initial guess (e.g. the previous value) of the position of the ordinate in the table to speed the search phase if possible (see `tabpos').

Interface:

double natinterp2d(
   const double x, const double y, // co-ordinates for interpolation
   const Array& xtab, // array of x values
   const Array& ytab, // array of y values
   const Matrix& ftab, // array of f(x,y) values, x.n by y.n
   const int ilastpos = -1, const int jlastpos = -1 // last positions, if known
)

Example:

#include
...
Array xtab,ytab;
matrix ftab;
double x,y;
...
double f = natinterp2d(x,y,xtab,ytab,ftab);