#include <twod_intp.h>
This class implements two-dimensional interpolation. Derivatives and integrals along both x- and y-directions can be computed.
The storage for the data, including the arrays x_fun
and y_fun
are all managed by the user. If the data is changed without calling reset_interp(), then interp() will return incorrect results.
No caching is done (except for the caching already present in sm_interp), and successive calls to interp() with the same values of x and y will take nearly the same amount of time.
Definition at line 60 of file twod_intp.h.
Public Member Functions | |
int | set_data (int n_x, int n_y, ovector &x_fun, ovector &y_fun, omatrix &u_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 ![]() |
int set_data | ( | int | n_x, | |
int | n_y, | |||
ovector & | x_fun, | |||
ovector & | y_fun, | |||
omatrix & | u_data, | |||
bool | x_first = true | |||
) |
Initialize the data for the 2-dimensional interpolation.
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 will give different results (unless linear interpolation is explicity selected). Using x_first=false
will be slightly slower, since the data has to be rearranged in the opposite order first. In general, if the data is "more accurate" in the x direction than in the y direction, it is probably better to choose x_first=true
.
Valid values of int_type
are:
int reset_interp | ( | ) |
Reset the stored interpolation since the data has changed.
This will return an error if the set_data() has not been called