Interpolation and extrapolation

Header file interp.h

These methods operate on tables (arrays) of data.

table position (increasing or decreasing table values): `tabpos_increasing' and `tabpos_decreasing'

Like `tabpos' (below), except the table ordinates are assumed to be monotonically increasing or decreasing with the table index.

table position: `tabpos'

Searches list of ordered values for pair bracketing a value. (This method looks to see whether the first value is greater or less than the last, and calls `tabpos_increasing' or `tabpos_decreasing' accordingly.)

Given an array of monotonically changing values xtab and a value of x, calculates the position in the table corresponding to x. Also takes an optional initial guess (e.g. the previous value) to speed the search if possible. This value is ignored if negative or greater than the table size-1.

Interface:

int tabpos(
   const double x, // ordinate
   const Array& xtab, // table, increasing
   const int lastpos = -1 // last position, if known
)

Example:

#include
...
Array t;
double x;
...
int pos = tabpos(x,t);

linear interpolation/extrapolation: `lininterp'

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 lininterp(
   const double x, // ordinate
   const Array& xtab, // array of x values, increasing
   const Array& ftab, // array of f(x) values
   const int lastpos = -1 // last position, if known
)
N.B. The arrays must be the same size.

Example:

#include
...
Array xtab,ftab;
double x;
...
double f = lininterp(x,xtab,ftab);

polynomial interpolation/extrapolation: `polyinterp'

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 polyinterp(
   const double x, // ordinate
   const Array& xtab, // array of x values, increasing
   const Array& ftab, // array of f(x) values
   const int order, // order of interpolating polynomial
   const int lastpos = -1 // last position, if known
)
N.B. The arrays must be the same size.

Example:

#include
...
Array xtab,ftab;
double x;
int order = 2; // quadratic
...
double f = polyinterp(x,xtab,ftab,order);