📄 diff.texi
字号:
@cindex differentiation of functions, numeric@cindex functions, numerical differentiation@cindex derivatives, calculating numerically@cindex numerical derivatives@cindex slope, see numerical derivativeThe functions described in this chapter compute numerical derivatives byfinite differencing. An adaptive algorithm is used to find the bestchoice of finite difference and to estimate the error in the derivative.These functions are declared in the header file @file{gsl_deriv.h}.@menu* Numerical Differentiation functions:: * Numerical Differentiation Examples:: * Numerical Differentiation References:: @end menu@node Numerical Differentiation functions@section Functions@deftypefun int gsl_deriv_central (const gsl_function * @var{f}, double @var{x}, double @var{h}, double * @var{result}, double * @var{abserr})This function computes the numerical derivative of the function @var{f}at the point @var{x} using an adaptive central difference algorithm witha step-size of @var{h}. The derivative is returned in @var{result} and anestimate of its absolute error is returned in @var{abserr}.The initial value of @var{h} is used to estimate an optimal step-size,based on the scaling of the truncation error and round-off error in thederivative calculation. The derivative is computed using a 5-point rulefor equally spaced abscissae at @math{x-h}, @math{x-h/2}, @math{x},@math{x+h/2}, @math{x}, with an error estimate taken from the differencebetween the 5-point rule and the corresponding 3-point rule @math{x-h},@math{x}, @math{x+h}. Note that the value of the function at @math{x}does not contribute to the derivative calculation, so only 4-points areactually used.@end deftypefun@deftypefun int gsl_deriv_forward (const gsl_function * @var{f}, double @var{x}, double @var{h}, double * @var{result}, double * @var{abserr})This function computes the numerical derivative of the function @var{f}at the point @var{x} using an adaptive forward difference algorithm witha step-size of @var{h}. The function is evaluated only at points greaterthan @var{x}, and never at @var{x} itself. The derivative is returned in@var{result} and an estimate of its absolute error is returned in@var{abserr}. This function should be used if @math{f(x)} has adiscontinuity at @var{x}, or is undefined for values less than @var{x}.The initial value of @var{h} is used to estimate an optimal step-size,based on the scaling of the truncation error and round-off error in thederivative calculation. The derivative at @math{x} is computed using an``open'' 4-point rule for equally spaced abscissae at @math{x+h/4},@math{x+h/2}, @math{x+3h/4}, @math{x+h}, with an error estimate takenfrom the difference between the 4-point rule and the corresponding2-point rule @math{x+h/2}, @math{x+h}. @end deftypefun@deftypefun int gsl_deriv_backward (const gsl_function * @var{f}, double @var{x}, double @var{h}, double * @var{result}, double * @var{abserr})This function computes the numerical derivative of the function @var{f}at the point @var{x} using an adaptive backward difference algorithmwith a step-size of @var{h}. The function is evaluated only at pointsless than @var{x}, and never at @var{x} itself. The derivative isreturned in @var{result} and an estimate of its absolute error isreturned in @var{abserr}. This function should be used if @math{f(x)}has a discontinuity at @var{x}, or is undefined for values greater than@var{x}.This function is equivalent to calling @code{gsl_deriv_forward} with anegative step-size.@end deftypefun@node Numerical Differentiation Examples@section ExamplesThe following code estimates the derivative of the function @c{$f(x) = x^{3/2}$}@math{f(x) = x^@{3/2@}} at @math{x=2} and at @math{x=0}. The function @math{f(x)} isundefined for @math{x<0} so the derivative at @math{x=0} is computedusing @code{gsl_deriv_forward}.@example@verbatiminclude examples/diff.c@end example@noindentHere is the output of the program,@example$ ./a.out@verbatiminclude examples/diff.out@end example@node Numerical Differentiation References@section References and Further ReadingThe algorithms used by these functions are described in the following sources:@itemize @asis@itemAbramowitz and Stegun, @cite{Handbook of Mathematical Functions},Section 25.3.4, and Table 25.5 (Coefficients for Differentiation).@itemS.D. Conte and Carl de Boor, @cite{Elementary Numerical Analysis: AnAlgorithmic Approach}, McGraw-Hill, 1972.@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -