Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
o2scl::deriv_eqi< func_t, vec_t > Class Template Reference

Derivatives for equally-spaced abscissas. More...

#include <deriv_eqi.h>

Inheritance diagram for o2scl::deriv_eqi< func_t, vec_t >:
o2scl::deriv_base< func_t >

Public Member Functions

int set_npoints (int npoints)
 Set the number of points to use for first derivatives (default 5) More...
 
int set_npoints2 (int npoints)
 Set the number of points to use for second derivatives (default 5) More...
 
virtual int deriv_err (double x, func_t &func, double &dfdx, double &err)
 Calculate the first derivative of func w.r.t. x.
 
virtual int deriv2_err (double x, func_t &func, double &dfdx, double &err)
 Calculate the second derivative of func w.r.t. x.
 
virtual int deriv3_err (double x, func_t &func, double &dfdx, double &err)
 Calculate the third derivative of func w.r.t. x.
 
double deriv_vector (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the derivative at x given an array. More...
 
double deriv2_vector (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the second derivative at x given an array. More...
 
double deriv3_vector (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the third derivative at x given an array. More...
 
int deriv_vector (size_t nv, double dx, const vec_t &y, vec_t &dydx)
 Calculate the derivative of an entire array. More...
 
virtual const char * type ()
 Return string denoting type ("deriv_eqi")
 
- Public Member Functions inherited from o2scl::deriv_base< func_t >
virtual double deriv (double x, func_t &func)
 Calculate the first derivative of func w.r.t. x. More...
 
virtual double deriv2 (double x, func_t &func)
 Calculate the second derivative of func w.r.t. x.
 
virtual double deriv3 (double x, func_t &func)
 Calculate the third derivative of func w.r.t. x.
 
virtual double get_err ()
 Get uncertainty of last calculation.
 

Public Attributes

double h
 Stepsize (Default $ 10^{-4} $ ).
 
double xoff
 Offset (default 0.0)
 
- Public Attributes inherited from o2scl::deriv_base< func_t >
bool err_nonconv
 If true, call the error handler if the routine does not "converge".
 
int verbose
 Output control.
 

Protected Member Functions

virtual int deriv_err_int (double x, funct11 &func, double &dfdx, double &err)
 Calculate the first derivative of func w.r.t. x and the uncertainty. More...
 
double derivp2 (double x, double p, func_t &func)
 Two-point first derivative.
 
double derivp3 (double x, double p, func_t &func)
 Three-point first derivative.
 
double derivp4 (double x, double p, func_t &func)
 Four-point first derivative.
 
double derivp5 (double x, double p, func_t &func)
 Five-point first derivative.
 
double deriv_vector3 (double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Three-point first derivative for arrays.
 
double deriv_vector4 (double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Four-point first derivative for arrays.
 
double deriv_vector5 (double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Five-point first derivative for arrays.
 
double deriv2p3 (double x, double p, func_t &func)
 Three-point second derivative.
 
double deriv2p4 (double x, double p, func_t &func)
 Four-point second derivative.
 
double deriv2p5 (double x, double p, func_t &func)
 Five-point second derivative.
 
- Protected Member Functions inherited from o2scl::deriv_base< func_t >
virtual double deriv_int (double x, funct11 &func)
 Calculate the first derivative of func w.r.t. x. More...
 
double derivfun (double x, func_t *fp)
 The function for the second derivative.
 
double derivfun2 (double x, func_t *fp)
 The function for the third derivative.
 

Protected Attributes

double(deriv_eqi::* cp )(double x, double p, func_t &func)
 Pointer to the first derivative function.
 
double(deriv_eqi::* cap )(double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Pointer to the first derivative for arrays function.
 
double(deriv_eqi::* c2p )(double x, double p, func_t &func)
 Pointer to the second derivative function.
 
double(deriv_eqi::* c2ap )(double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Pointer to the second derivative for arrays function.
 
double(deriv_eqi::* c3p )(double x, double h, double p, func_t &func)
 Pointer to the third derivative function.
 
double(deriv_eqi::* c3ap )(double x, double x0, double dx, size_t nx, const vec_t &y, size_t ix)
 Pointer to the third derivative for arrays function.
 
- Protected Attributes inherited from o2scl::deriv_base< func_t >
bool from_deriv
 Avoids infinite loops in case the user calls the base class version.
 
double derr
 The uncertainity in the most recent derivative computation.
 

Detailed Description

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
class o2scl::deriv_eqi< func_t, vec_t >

This is an implementation of the formulas for equally-spaced abscissas as indicated below. The level of approximation is specified in set_npoints(). The value of $ p \times h $ can be specified in xoff (default is zero).

Note
Uncertainties are not computed and the code for second and third derivatives is unfinished.
The derivatives given, for example, from the five-point formula can sometimes be more accurate than computing the derivative from the interpolation class. This is especially true near the boundaries of the interpolated region.
Idea for Future:
Finish the second and third derivative formulas.

Two-point formula (note that this is independent of p).

\[ f^{\prime}(x_0+p h)=\frac{1}{h}\left[ f_{1}-f_{0} \right] \]

Three-point formula from Abramowitz and Stegun

\[ f^{\prime}(x_0+p h)=\frac{1}{h}\left[ \frac{2p-1}{2}f_{-1}-2 p f_{0}+\frac{2p+1}{2}f_{1}\right] \]

Four-point formula from Abramowitz and Stegun

\[ f^{\prime}(x_0+p h)=\frac{1}{h}\left[ -\frac{3 p^2-6 p+2}{6}f_{-1} +\frac{3 p^2-4 p -1}{2}f_{0} -\frac{3 p^2-2 p-2}{2}f_{1} +\frac{3 p^2-1}{6}f_{2} \right] \]

Five-point formula from Abramowitz and Stegun

\begin{eqnarray*} f^{\prime}(x_0+p h)&=&\frac{1}{h}\left[ \frac{2 p^3-3 p^2-p+1}{12}f_{-2} -\frac{4 p^3-3p^2-8p+4}{6}f_{-1} \right. \\ && \left. +\frac{2p^3-5p}{2}f_{0} -\frac{4p^3+3p^2-8p-4}{6}f_{1} \right. \\ && \left. +\frac{2p^3+3p^2-p-1}{12}f_{2} \right] \end{eqnarray*}

The relations above can be confined to give formulas for second derivative formulas: Three-point formula

\[ f^{\prime}(x_0+p h)=\frac{1}{h^2} \left[f_{-1}-2 f_0+f_1\right] \]

Four-point formula:

\[ f^{\prime}(x_0+p h)=\frac{1}{2 h^2} \left[\left(1-2p\right)f_{-1}-\left(1-6p\right)f_0 -\left(1+6p\right)f_1+\left(1+2p\right)f_2\right] \]

Five-point formula:

\[ f^{\prime}(x_0+p h)=\frac{1}{4 h^2} \left[\left(1-2p\right)^2f_{-2} +\left(8p-16 p^2\right)f_{-1} -\left(2-24 p^2\right)f_0 -\left(8p+16p^2\right)f_1 +\left(1+2p\right)^2 f_2\right] \]

Six-point formula:

\begin{eqnarray*} f^{\prime}(x_0+p h)&=&\frac{1}{12 h^2}\left[ \left(2-10p+15 p^2-6p^3\right)f_{-2} +\left(3+14p-57p^2+30p^3\right)f_{-1} \right. \\ && \left. +\left(-8+20p+78 p^2-60p^3\right)f_0 +\left(-2-44p-42p^2+60p^3\right)f_1 \right. \\ && \left. +\left(6+22p+3p^2-30p^3\right)f_2 +\left(-1-2p+3p^2+6p^3\right)f_3 \right] \end{eqnarray*}

Seven-point formula:

\begin{eqnarray*} f^{\prime}(x_0+p h)&=&\frac{1}{36 h^2}\left[ \left(4-24p+48p^2-36p^3+9p^4\right)f_{-3} +\left(12+12p-162p^2+180p^3-54p^4\right)f_{-2} \right. \\ && \left. +\left(-15+120p+162p^2-360p^3+135p^4\right)f_{-1} -4\left(8+48p-3p^2-90p^3+45p^4\right)f_0 \right. \\ && \left. +3\left(14+32p-36p^2-60p^3+45p^4\right)f_1 +\left(-12-12p+54p^2+36p^3-54p^4\right)f_2 \right. \\ && \left. +\left(1-6p^2+9p^4\right)f_3 \right] \end{eqnarray*}

Definition at line 144 of file deriv_eqi.h.

Member Function Documentation

◆ deriv2_vector()

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
double o2scl::deriv_eqi< func_t, vec_t >::deriv2_vector ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
)
inline

This calculates the second derivative at x given a function specified in an array y of size nx with equally spaced abscissas. The first abscissa should be given as x0 and the distance between adjacent abscissas should be given as dx. The value x need not be one of the abscissas (i.e. it can lie in between an interval). The appropriate offset is calculated automatically.

Definition at line 263 of file deriv_eqi.h.

◆ deriv3_vector()

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
double o2scl::deriv_eqi< func_t, vec_t >::deriv3_vector ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
)
inline

This calculates the third derivative at x given a function specified in an array y of size nx with equally spaced abscissas. The first abscissa should be given as x0 and the distance between adjacent abscissas should be given as dx. The value x need not be one of the abscissas (i.e. it can lie in between an interval). The appropriate offset is calculated automatically.

Definition at line 280 of file deriv_eqi.h.

◆ deriv_err_int()

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
virtual int o2scl::deriv_eqi< func_t, vec_t >::deriv_err_int ( double  x,
funct11 func,
double &  dfdx,
double &  err 
)
inlineprotectedvirtual

This function doesn't do anything, and isn't required for this class since it computes higher-order derivatives directly.

Implements o2scl::deriv_base< func_t >.

Definition at line 323 of file deriv_eqi.h.

◆ deriv_vector() [1/2]

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
double o2scl::deriv_eqi< func_t, vec_t >::deriv_vector ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
)
inline

This calculates the derivative at x given a function specified in an array y of size nx with equally spaced abscissas. The first abscissa should be given as x0 and the distance between adjacent abscissas should be given as dx. The value x need not be one of the abscissas (i.e. it can lie in between an interval). The appropriate offset is calculated automatically.

Definition at line 247 of file deriv_eqi.h.

◆ deriv_vector() [2/2]

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::deriv_eqi< func_t, vec_t >::deriv_vector ( size_t  nv,
double  dx,
const vec_t &  y,
vec_t &  dydx 
)
inline

Right now this uses np=5.

Todo:
generalize to other values of npoints.

Definition at line 293 of file deriv_eqi.h.

◆ set_npoints()

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::deriv_eqi< func_t, vec_t >::set_npoints ( int  npoints)
inline

Acceptable values are 2-5 (see above).

Definition at line 166 of file deriv_eqi.h.

◆ set_npoints2()

template<class func_t = funct11, class vec_t = boost::numeric::ublas::vector<double>>
int o2scl::deriv_eqi< func_t, vec_t >::set_npoints2 ( int  npoints)
inline

Acceptable values are 3-5 (see above).

Definition at line 192 of file deriv_eqi.h.


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

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