Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / doc / diff.texi
1 @cindex differentiation of functions, numeric
2 @cindex functions, numerical differentiation
3 @cindex derivatives, calculating numerically
4 @cindex numerical derivatives
5 @cindex slope, see numerical derivative
6
7 The functions described in this chapter compute numerical derivatives by
8 finite differencing.  An adaptive algorithm is used to find the best
9 choice of finite difference and to estimate the error in the derivative.
10 These functions are declared in the header file @file{gsl_deriv.h}.
11
12 @menu
13 * Numerical Differentiation functions::  
14 * Numerical Differentiation Examples::  
15 * Numerical Differentiation References::  
16 @end menu
17
18 @node Numerical Differentiation functions
19 @section Functions
20
21 @deftypefun int gsl_deriv_central (const gsl_function * @var{f}, double @var{x}, double @var{h}, double * @var{result}, double * @var{abserr})
22 This function computes the numerical derivative of the function @var{f}
23 at the point @var{x} using an adaptive central difference algorithm with
24 a step-size of @var{h}.   The derivative is returned in @var{result} and an
25 estimate of its absolute error is returned in @var{abserr}.
26
27 The initial value of @var{h} is used to estimate an optimal step-size,
28 based on the scaling of the truncation error and round-off error in the
29 derivative calculation.  The derivative is computed using a 5-point rule
30 for equally spaced abscissae at @math{x-h}, @math{x-h/2}, @math{x},
31 @math{x+h/2}, @math{x+h}, with an error estimate taken from the difference
32 between the 5-point rule and the corresponding 3-point rule @math{x-h},
33 @math{x}, @math{x+h}.  Note that the value of the function at @math{x}
34 does not contribute to the derivative calculation, so only 4-points are
35 actually used.
36 @end deftypefun
37
38 @deftypefun int gsl_deriv_forward (const gsl_function * @var{f}, double @var{x}, double @var{h}, double * @var{result}, double * @var{abserr})
39 This function computes the numerical derivative of the function @var{f}
40 at the point @var{x} using an adaptive forward difference algorithm with
41 a step-size of @var{h}. The function is evaluated only at points greater
42 than @var{x}, and never at @var{x} itself.  The derivative is returned in
43 @var{result} and an estimate of its absolute error is returned in
44 @var{abserr}.  This function should be used if @math{f(x)} has a
45 discontinuity at @var{x}, or is undefined for values less than @var{x}.
46
47 The initial value of @var{h} is used to estimate an optimal step-size,
48 based on the scaling of the truncation error and round-off error in the
49 derivative calculation.  The derivative at @math{x} is computed using an
50 ``open'' 4-point rule for equally spaced abscissae at @math{x+h/4},
51 @math{x+h/2}, @math{x+3h/4}, @math{x+h}, with an error estimate taken
52 from the difference between the 4-point rule and the corresponding
53 2-point rule @math{x+h/2}, @math{x+h}. 
54 @end deftypefun
55
56 @deftypefun int gsl_deriv_backward (const gsl_function * @var{f}, double @var{x},  double @var{h}, double * @var{result}, double * @var{abserr})
57 This function computes the numerical derivative of the function @var{f}
58 at the point @var{x} using an adaptive backward difference algorithm
59 with a step-size of @var{h}. The function is evaluated only at points
60 less than @var{x}, and never at @var{x} itself.  The derivative is
61 returned in @var{result} and an estimate of its absolute error is
62 returned in @var{abserr}.  This function should be used if @math{f(x)}
63 has a discontinuity at @var{x}, or is undefined for values greater than
64 @var{x}.
65
66 This function is equivalent to calling @code{gsl_deriv_forward} with a
67 negative step-size.
68 @end deftypefun
69
70 @node Numerical Differentiation Examples
71 @section Examples
72
73 The following code estimates the derivative of the function 
74 @c{$f(x) = x^{3/2}$}
75 @math{f(x) = x^@{3/2@}} 
76 at @math{x=2} and at @math{x=0}.  The function @math{f(x)} is
77 undefined for @math{x<0} so the derivative at @math{x=0} is computed
78 using @code{gsl_deriv_forward}.
79
80 @example
81 @verbatiminclude examples/diff.c
82 @end example
83
84 @noindent
85 Here is the output of the program,
86
87 @example
88 $ ./a.out
89 @verbatiminclude examples/diff.out
90 @end example
91
92 @node Numerical Differentiation References
93 @section References and Further Reading
94
95 The algorithms used by these functions are described in the following sources:
96
97 @itemize @asis
98 @item
99 Abramowitz and Stegun, @cite{Handbook of Mathematical Functions},
100 Section 25.3.4, and Table 25.5 (Coefficients for Differentiation).
101
102 @item
103 S.D. Conte and Carl de Boor, @cite{Elementary Numerical Analysis: An
104 Algorithmic Approach}, McGraw-Hill, 1972.
105 @end itemize