Interpolation

Basic interpolation of generic vector types is performed by o2scl::interp and o2scl::interp_vec. The vector representing the independent variable must be monotonic, but need not be equally-spaced. The difference between the two classes is analogous to the difference between using gsl_interp_eval() and gsl_spline_eval() in GSL. You can create a o2scl::interp object and use it to interpolate among any pair of chosen vectors. For example, cubic spline interpolation with natural boundary conditions

// fill x and y with data
double y_half=oi.eval(0.5,20,x,y);

Alternatively, you can create a o2scl::interp_vec object which can be optimized for a pair of vectors that you specify in advance (now using linear interpolation instead)

// fill x and y with data
double y_half=oi.eval(0.5);

These interpolation classes require that the vector x is either monotonically increasing or monotonically decreasing, but these classes do not verify that this is the case. If the vectors or not monotonic, then the interpolation functions are not defined. These classes give identical results to the GSL interpolation routines when the vector is monotonically increasing.

These interpolation classes will extrapolate to regions outside those defined by the user-specified vectors and will not warn you when they do this (this is not the same behavior as in GSL).

The different interpolation types are defined in interp.h

Integrals are always computed assuming that if the limits are ordered so that if the upper limit appears earlier in the array x in comparison to the lower limit, that the value of the integral has the opposite sign than if the upper limit appears later in the array x .

The classes o2scl::interp and o2scl::interp_vec are based on the lower-level interpolation classes of type o2scl::interp_base. Also, the interpolation classes based on o2scl::interp_base and also the class o2scl::interp_vec also have defined a function operator() which also returns the result of the interpolation.

Two specializations for C-style arrays of double-precision numbers are provided in o2scl::interp_array and o2scl::interp_array_vec.

Lookup and binary search

The classes o2scl::search_vec and o2scl::search_vec_ext contain searching functions for generic vector types which contain monotonic (either increasing or decreasing) data. It is o2scl::search_vec which is used internally by the interpolation classes to perform cached binary searching. These classes also allow one to to exahaustively search for the index of an element in a vector without regard to any kind of ordering, e.g. o2scl::search_vec::ordered_lookup() .

Two and higher-dimensional interpolation

Support for multi-dimensional interpolation is documented in Higher-dimensional Interpolation.

Inverse interpolation and related functions

The equivalent to "inverse" linear interpolation, which computes all the abcissae which have a fixed value of the ordinate, is implemented in the template function o2scl::vector_find_level() which is documented in interp.h . This function together with o2scl::vector_invert_enclosed_sum() can be used to determine confidence limits surrounding the peak of a 1-dimensional data set using linear interpolation. To count level crossings in a function, use o2scl::vector_level_count(). The function o2scl::vector_integ_linear() uses linear interpolation to compute the integral defined by a set of vectors, and the function o2scl::vector_region_parint() finds the set of regions which gives a fraction of the integral reported by o2scl::vector_integ_linear().

Derivatives and integrals on a fixed grid

If the indepedent variable is represented by a uniform (equally-spaced) then the functions in vector_derint.h can provide faster (and occasionally more accurate) results.

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).