twod_intp Class Reference

Two-dimensional interpolation class. More...

#include <twod_intp.h>


Detailed Description

This class implements two-dimensional interpolation. Derivatives and integrals along both x- and y-directions can be computed.

The storage of the matrix to be specified in the function set_data() and this function is designed to follow the format:

\[ \begin{array}{cccc} & x_0 & x_1 & x_2 \\ y_0 & M_{00} & M_{01} & M_{02} \\ y_1 & M_{10} & M_{11} & M_{12} \\ y_2 & M_{20} & M_{21} & M_{22} \end{array} \]

thus the matrix should be M[i][j] where i is the y index and j is the x index. (See also the discussion in the User's guide in the section called Rows and columns vs. x and y.)

The function set_data(), does not copy the data, it stores pointers to the data. If the data is modified, then the function reset_interp() must be called to reset the interpolation information with the original pointer information. The storage for the data, including the arrays x_grid and y_grid are all managed by the user.

By default, cubic spline interpolation with natural boundary conditions is used. This can be changed with the set_interp() function.

There is an example for the usage of this class given in examples/ex_twod_intp.cpp.

Idea for future:
Could also include mixed second/first derivatives: deriv_xxy and deriv_xyy.
Idea for future:
Implement an improved caching system in case, for example xfirst is true and the last interpolation used the same value of x.

Definition at line 100 of file twod_intp.h.


Public Member Functions

int set_data (size_t n_x, size_t n_y, ovector &x_grid, ovector &y_grid, omatrix &data, bool x_first=true)
 Initialize the data for the 2-dimensional interpolation.
int reset_interp ()
 Reset the stored interpolation since the data has changed.
double interp (double x, double y)
 Perform the 2-d interpolation.
double deriv_x (double x, double y)
 Compute the partial derivative in the x-direction.
double deriv2_x (double x, double y)
 Compute the partial second derivative in the x-direction.
double integ_x (double x0, double x1, double y)
 Compute the integral in the x-direction between x=x0 and x=x1.
double deriv_y (double x, double y)
 Compute the partial derivative in the y-direction.
double deriv2_y (double x, double y)
 Compute the partial second derivative in the y-direction.
double integ_y (double x, double y0, double y1)
 Compute the integral in the y-direction between y=y0 and y=y1.
double deriv_xy (double x, double y)
 Compute the mixed partial derivative $ \frac{\partial^2 f}{\partial x \partial y} $.
int set_interp (base_interp_mgr< ovector_const_view > &b1, base_interp_mgr< ovector_const_subvector > &b2)
 Specify the base interpolation objects to use.
int unset_data ()
 Inform the class the data has been modified or changed in a way that set_data() will need to be called again.

Member Function Documentation

int reset_interp (  ) 

This will return an error if the set_data() has not been called

int set_data ( size_t  n_x,
size_t  n_y,
ovector x_grid,
ovector y_grid,
omatrix data,
bool  x_first = true 
)

The interpolation type (passed directly to int_type) is specified in int_type and the data is specified in data. The data should be arranged so that the first array index is the y-value (the "row") and the second array index is the x-value (the "column"). The arrays xfun and yfun specify the two independent variables. xfun should be an array of length nx , and should be an array of length ny. The array data should be a two-dimensional array of size [ny][nx].

If x_first is true, then set_data() creates interpolation objects for each of the rows. Calls to interp() then uses these to create a column at the specified value of x. An interpolation object is created at this column to find the value of the function at the specified value y. If x_first is false, the opposite strategy is employed. These two options may give slightly different results.

int set_interp ( base_interp_mgr< ovector_const_view > &  b1,
base_interp_mgr< ovector_const_subvector > &  b2 
) [inline]

This allows the user to provide new interpolation objects for use in the two-dimensional interpolation. For example,

        twod_intp ti;
        ovector x(20), y(40);
        omatrix d(40,20);

        // Fill x, y, and d with the data, choose linear interpolation
        // instead of the default cubic spline
        def_interp_mgr<ovector_const_view,linear_interp> dim1;
        def_interp_mgr<ovector_const_subvector,linear_interp> dim2;
        
        ti.set_interp(dim1,dim2);
        ti.set_data(20,40,x,y,d,true);

This function automatically calls reset_interp() and reset_data() if the data has already been set to reset the internal interpolation objects.

Definition at line 201 of file twod_intp.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page