Class interp2_seq (o2scl)¶
-
template<class
vec_t
= boost::numeric::ublas::vector<double>, classmat_t
= boost::numeric::ublas::matrix<double>, classmat_row_t
= boost::numeric::ublas::matrix_row<mat_t>>
classo2scl
::
interp2_seq
: public o2scl::interp2_base<boost::numeric::ublas::vector<double>, boost::numeric::ublas::matrix<double>>¶ Two-dimensional interpolation class by successive one-dimensional interpolation.
This class implements two-dimensional interpolation by iterating the one-dimensional interpolation routines. Derivatives and integrals along both x- and y-directions can be computed. This class is likely a bit slower than interp2_direct but more flexible.
The convention used by this class is that the first (row) index of the matrix enumerates the x coordinate and that the second (column) index enumerates the y coordinate. See 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
andy_grid
are all managed by the user.By default, cubic spline interpolation with natural boundary conditions is used. This can be changed by calling set_interp() again with the same data and the new interpolation type.
There is an example for the usage of this class given in
examples/ex_interp2_seq.cpp
.Because of the way this class creates pointers to the data, copy construction is not currently allowed.
- Idea for Future:
Implement an improved caching system in case, for example
xfirst
is true and the last interpolation used the same value ofx
.
Public Types
-
typedef boost::numeric::ublas::vector<double>
ubvector
¶
Public Functions
-
interp2_seq
()¶
-
~interp2_seq
()¶
-
void
set_data
(size_t n_x, size_t n_y, vec_t &x_grid, vec_t &y_grid, mat_t &data, size_t interp_type = itp_cspline)¶ Initialize the data for the 2-dimensional interpolation.
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 ofx
. An interpolation object is created at this column to find the value of the function at the specified valuey
. Ifx_first
is false, the opposite strategy is employed. These two options may give slightly different results.
-
void
reset_interp
()¶ Reset the stored interpolation since the data has changed.
This will throw an exception if the set_data() has not been called.
-
double
eval
(double x, double y) const¶ Perform the 2-d interpolation.
-
double
operator()
(double x, double y) const¶ Perform the 2-d interpolation.
-
double
deriv_x
(double x, double y) const¶ Compute the partial derivative in the x-direction.
-
double
deriv_xx
(double x, double y) const¶ Compute the partial second derivative in the x-direction.
-
double
integ_x
(double x0, double x1, double y) const¶ Compute the integral in the x-direction between x=x0 and x=x1.
-
double
deriv_y
(double x, double y) const¶ Compute the partial derivative in the y-direction.
-
double
deriv_yy
(double x, double y) const¶ Compute the partial second derivative in the y-direction.
-
double
integ_y
(double x, double y0, double y1) const¶ Compute the integral in the y-direction between y=y0 and y=y1.
-
double
deriv_xy
(double x, double y) const¶ Compute the mixed partial derivative \( \frac{\partial^2 f}{\partial x \partial y} \).
-
double
eval_gen
(int ix, int iy, double x0, double x1, double y0, double y1) const¶ Compute a general interpolation result.
This computes
\[ \frac{\partial^m}{\partial x^m} \frac{\partial^n}{\partial y^n} f(x,y) \]for \( m \in (-1,0,1,2) \) and \( n \in (-1,0,1,2) \) with the notation\[\begin{split}\begin{eqnarray*} \frac{\partial^{-1}}{\partial x^{-1}} &\equiv & \int_{x_0}^{x_1} f~dx \nonumber \\ \frac{\partial^0}{\partial x^0} &\equiv & \left.f\right|_{x=x_0} \nonumber \\ \frac{\partial^1}{\partial x^1} &\equiv & \left(\frac{\partial f}{\partial x}\right)_{x=x_0} \nonumber \\ \frac{\partial^2}{\partial x^2} &\equiv & \left(\frac{\partial^2 f}{\partial x^2}\right)_{x=x_0} \end{eqnarray*}\end{split}\]and the value of \( x_1 \) is ignored when \( m \geq 0 \) and the value of \( y_1 \) is ignored when \( n \geq 0 \).
Protected Attributes
-
std::vector<interp_vec<vec_t, mat_row_t>*>
itps
¶ The array of interpolation objects.
-
size_t
nx
¶ The number of x grid points.
-
size_t
ny
¶ The number of y grid points.
-
bool
data_set
¶ True if the data has been specified by the user.
-
size_t
itype
¶ Interpolation type.
Private Functions
-
interp2_seq
(const interp2_seq<vec_t, mat_t, mat_row_t>&)¶
-
interp2_seq<vec_t, mat_t, mat_row_t> &
operator=
(const interp2_seq<vec_t, mat_t, mat_row_t>&)¶