![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
Numerical differentiation (GSL) More...
#include <gsl_deriv.h>
This class computes the numerical derivative of a function. The stepsize h should be specified before use. If similar functions are being differentiated in succession, the user may be able to increase the speed of later derivatives by setting the new stepsize equal to the optimized stepsize from the previous differentiation, by setting h to h_opt.
The derivative computation will never fail, but the results will be incorrect for sufficiently difficult functions or if the step size is not properly chosen.
Some successive derivative computations can be made more efficient by using the optimized stepsize in gsl_deriv::h_opt , which is set by the most recent last derivative computation.
Setting deriv::verbose to a number greater than zero results in output for each call to central_deriv() which looks like:
gsl_deriv: step: 1.000000e-04 abscissas: 4.999500e-01 4.999000e-01 5.000500e-01 5.001000e-01 ordinates: 4.793377e-01 4.793816e-01 4.794694e-01 4.795132e-01 res: 8.775825e-01 trc: 1.462163e-09 rnd: 7.361543e-12
where the last line contains the result (res
), the truncation error (trc
) and the rounding error (rnd
). If deriv::verbose is greater than 1, a keypress is required after each iteration.
Computing first derivatives requires either 1 or 2 calls to central_deriv() and thus either 4 or 8 function calls. This class never calls the error handler.
An example demonstrating the usage of this class is given in examples/ex_deriv.cpp
and the Numerical differentiation .
Definition at line 105 of file gsl_deriv.h.
Public Member Functions | |
virtual int | calc_err (double x, func_t &func, double &dfdx, double &err) |
Calculate the first derivative of func w.r.t. x and uncertainty. | |
virtual const char * | type () |
Return string denoting type ("gsl_deriv") | |
Data Fields | |
double | h |
Initial stepsize. | |
double | h_opt |
The last value of the optimized stepsize. | |
Protected Member Functions | |
template<class func2_t > | |
int | calc_base (double x, func_t &func, double &dfdx, double &err) |
Internal template version of the derivative function. | |
virtual int | calc_err_int (double x, funct &func, double &dfdx, double &err) |
Internal version of calc_err() for second and third derivatives. | |
template<class func2_t > | |
int | central_deriv (double x, double hh, double &result, double &abserr_round, double &abserr_trunc, func2_t &func) |
Compute derivative using 5-point rule. |
int gsl_deriv< func_t >::central_deriv | ( | double | x, |
double | hh, | ||
double & | result, | ||
double & | abserr_round, | ||
double & | abserr_trunc, | ||
func2_t & | func | ||
) | [inline, protected] |
Compute the derivative using the 5-point rule (x-h, x-h/2, x, x+h/2, x+h) and the error using the difference between the 5-point and the 3-point rule (x-h,x,x+h). Note that the central point is not used for either.
This must be a class template because it is used by both calc_err() and calc_err_int().
Definition at line 207 of file gsl_deriv.h.
This should be specified before a call to calc() or calc_err(). If it is zero, then will used, or if
x
is zero, then will be used.
Definition at line 122 of file gsl_deriv.h.
This is initialized to zero in the constructor and set by calc_err() to the most recent value of the optimized stepsize.
Definition at line 129 of file gsl_deriv.h.
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).