#include <twod_intp.h>
This class implements two-dimensional interpolation. Derivatives and integrals along both x- and y-directions can be computed. The function set_data(), does not copy the data but rather stores pointers to the data. If the data is modified, then the function reset_interp() can be called to reset the interpolation information with the original pointer information.
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.
By default, cubic spline interpolation with natural boundary conditions is used. This can be changed with the set_interp() function.
examples/ex_twod_intp.cpp
.
xfirst
is true and the last interpolation used the same value of x
.Definition at line 68 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_interp (size_t ni, base_interp< ovector_view > *it, base_interp< ovector_const_subvector > *it_sub, base_interp< ovector_view > &it2, base_interp< ovector_const_subvector > &it2_sub) |
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. |
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 may give slightly different results. 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
.
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
int set_interp | ( | size_t | ni, | |
base_interp< ovector_view > * | it, | |||
base_interp< ovector_const_subvector > * | it_sub, | |||
base_interp< ovector_view > & | it2, | |||
base_interp< ovector_const_subvector > & | it2_sub | |||
) | [inline] |
Specify the base interpolation objects to use.
This allows the user to provide new interpolation objects for use in the two-dimensional interpolation. This class requires an array of interpolation objects for the first two arguments because one interpolation object is required for each row (or each column). The argument ni
specifies the size of these arrays. In the case where the user intends the x interpolation first (i.e. x_first
=
true
in set_data() ), the parameter ni
should be equal to ny
. For x_first=false
, ni
should be equal to nx
. If the class does not find enough interpolation objects, i.e. if ni
is smaller than the values suggested above, the class will switch back to the default internal interpolation objects when it runs out of user-specified interpolation objects. 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 linear_interp<ovector_view> li[41]; linear_interp<ovector_const_subvector> li2[41]; ti.set_interp(40,li,li2,li[40],li2[40]); ti.set_data(20,40,x,y,d,true);
This function automatically calls reset_interp() if the data has already been set to reset the internal interpolation objects.
Definition at line 183 of file twod_intp.h.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page