eqi_deriv Class Template Reference

#include <eqi_deriv.h>

Inheritance diagram for eqi_deriv:

deriv

Detailed Description

template<class param_t, class func_t, class vec_t = ovector_view>
class eqi_deriv< param_t, func_t, vec_t >

Derivatives for equally-spaced abscissas.

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:
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.
Todo:
The uncertainties in the derivatives are not yet computed and the second and third derivative formulas are not yet finished.
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 135 of file eqi_deriv.h.


Public Member Functions

 eqi_deriv ()
int set_npoints (int npoints)
 Set the number of points to use for first derivatives (default 5).
int set_npoints2 (int npoints)
 Set the number of points to use for second derivatives (default 5).
virtual double calc (double x, void *pa, func_t &func)
 Calculate the first derivative of func w.r.t. x.
virtual double calc2 (double x, void *pa, func_t &func)
 Calculate the second derivative of func w.r.t. x.
virtual double calc3 (double x, void *pa, func_t &func)
 Calculate the third derivative of func w.r.t. x.
double calc_array (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the derivative at x given an array.
double calc2_array (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the second derivative at x given an array.
double calc3_array (double x, double x0, double dx, size_t nx, const vec_t &y)
 Calculate the third derivative at x given an array.
int deriv_array (size_t nv, double dx, const vec_t &y, vec_t &dydx)
 Calculate the derivative of an entire array.
virtual const char * type ()
 Return string denoting type ("eqi_deriv").

Data Fields

double h
 Stepsize (Default $ 10^{-4} $ ).
double xoff
 Offset (default 0.0).

Member Function Documentation

int set_npoints ( int  npoints  )  [inline]

Set the number of points to use for first derivatives (default 5).

Acceptable values are 2-5 (see above).

Definition at line 157 of file eqi_deriv.h.

int set_npoints2 ( int  npoints  )  [inline]

Set the number of points to use for second derivatives (default 5).

Acceptable values are 3-5 (see above).

Definition at line 183 of file eqi_deriv.h.

double calc_array ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
) [inline]

Calculate the derivative at x given an array.

This calculates the derivative at x given a func_tion 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 234 of file eqi_deriv.h.

double calc2_array ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
) [inline]

Calculate the second derivative at x given an array.

This calculates the second derivative at x given a func_tion 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 251 of file eqi_deriv.h.

double calc3_array ( double  x,
double  x0,
double  dx,
size_t  nx,
const vec_t &  y 
) [inline]

Calculate the third derivative at x given an array.

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 269 of file eqi_deriv.h.

int deriv_array ( size_t  nv,
double  dx,
const vec_t &  y,
vec_t &  dydx 
) [inline]

Calculate the derivative of an entire array.

Right now this uses np=5.

Todo:
generalize to other values of npoints.

Definition at line 283 of file eqi_deriv.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.