The functions described in this chapter compute numerical derivatives by finite differencing.  An adaptive algorithm is used to find the best choice of finite difference and to estimate the error in the derivative. These functions are declared in the header file gsl_deriv.h.

Functions
=========

 -- Function: int gsl_deriv_central (const gsl_function * F, double X, double H, double * RESULT, double * ABSERR)
     This function computes the numerical derivative of the function F at the point X using an adaptive central difference algorithm with a step-size of H.   The derivative is returned in RESULT and an estimate of its absolute error is returned in ABSERR.

     The initial value of H is used to estimate an optimal step-size, based on the scaling of the truncation error and round-off error in the derivative calculation.  The derivative is computed using a 5-point rule for equally spaced abscissae at x-h, x-h/2, x, x+h/2, x+h, with an error estimate taken from the difference between the 5-point rule and the corresponding 3-point rule x-h, x, x+h.  Note that the value of the function at x does not contribute to the derivative calculation, so only 4-points are actually used.

 -- Function: int gsl_deriv_forward (const gsl_function * F, double X, double H, double * RESULT, double * ABSERR)
     This function computes the numerical derivative of the function F at the point X using an adaptive forward difference algorithm with a step-size of H. The function is evaluated only at points greater than X, and never at X itself.  The derivative is returned in RESULT and an estimate of its absolute error is returned in ABSERR.  This function should be used if f(x) has a discontinuity at X, or is undefined for values less than X.

     The initial value of H is used to estimate an optimal step-size, based on the scaling of the truncation error and round-off error in the derivative calculation.  The derivative at x is computed using an ``open'' 4-point rule for equally spaced abscissae at x+h/4, x+h/2, x+3h/4, x+h, with an error estimate taken from the difference between the 4-point rule and the corresponding 2-point rule x+h/2, x+h.

 -- Function: int gsl_deriv_backward (const gsl_function * F, double X, double H, double * RESULT, double * ABSERR)
     This function computes the numerical derivative of the function F at the point X using an adaptive backward difference algorithm with a step-size of H. The function is evaluated only at points less than X, and never at X itself.  The derivative is returned in RESULT and an estimate of its absolute error is returned in ABSERR.  This function should be used if f(x) has a discontinuity at X, or is undefined for values greater than X.

     This function is equivalent to calling gsl_deriv_forward with a negative step-size.

Examples
========

The following code estimates the derivative of the function $f(x) = x^3/2$ f(x) = x^{3/2} at x=2 and at x=0.  The function f(x) is undefined for x<0 so the derivative at x=0 is computed using gsl_deriv_forward.

          [file diff.c not included]

Here is the output of the program,

     $ ./a.out
          [file diff.out not included]

References and Further Reading
==============================

The algorithms used by these functions are described in the following sources:

  Abramowitz and Stegun, Handbook of Mathematical Functions, Section 25.3.4, and Table 25.5 (Coefficients for Differentiation).

  S.D. Conte and Carl de Boor, Elementary Numerical Analysis: An Algorithmic Approach, McGraw-Hill, 1972.