📄 integration.texi
字号:
@cindex singular functions, numerical integration ofThe QAWS algorithm is designed for integrands with algebraic-logarithmicsingularities at the end-points of an integration region. In order towork efficiently the algorithm requires a precomputed table ofChebyshev moments.@deftypefun {gsl_integration_qaws_table *} gsl_integration_qaws_table_alloc (double @var{alpha}, double @var{beta}, int @var{mu}, int @var{nu})This function allocates space for a @code{gsl_integration_qaws_table}struct and associated workspace describing a singular weight function@math{W(x)} with the parameters @math{(\alpha, \beta, \mu, \nu)},@tex\beforedisplay$$W(x) = (x - a)^\alpha (b - x)^\beta \log^\mu (x - a) \log^\nu (b - x)$$\afterdisplay@end tex@ifinfo@exampleW(x) = (x-a)^alpha (b-x)^beta log^mu (x-a) log^nu (b-x)@end example@end ifinfo@noindentwhere @math{\alpha > -1}, @math{\beta > -1}, and @math{\mu = 0, 1},@math{\nu = 0, 1}. The weight function can take four different formsdepending on the values of @math{\mu} and @math{\nu},@tex\beforedisplay$$\matrix{W(x) = (x - a)^\alpha (b - x)^\beta \hfill~ (\mu = 0, \nu = 0) \crW(x) = (x - a)^\alpha (b - x)^\beta \log(x - a) \hfill~ (\mu = 1, \nu = 0) \crW(x) = (x - a)^\alpha (b - x)^\beta \log(b - x) \hfill~ (\mu = 0, \nu = 1) \crW(x) = (x - a)^\alpha (b - x)^\beta \log(x - a) \log(b - x) \hfill~ (\mu = 1, \nu = 1)}$$\afterdisplay@end tex@ifinfo@exampleW(x) = (x-a)^alpha (b-x)^beta (mu = 0, nu = 0)W(x) = (x-a)^alpha (b-x)^beta log(x-a) (mu = 1, nu = 0)W(x) = (x-a)^alpha (b-x)^beta log(b-x) (mu = 0, nu = 1)W(x) = (x-a)^alpha (b-x)^beta log(x-a) log(b-x) (mu = 1, nu = 1)@end example@end ifinfo@noindentThe singular points @math{(a,b)} do not have to be specified until theintegral is computed, where they are the endpoints of the integrationrange.The function returns a pointer to the newly allocated@code{gsl_integration_qaws_table} if no errors were detected, and 0 inthe case of error.@end deftypefun@deftypefun int gsl_integration_qaws_table_set (gsl_integration_qaws_table * @var{t}, double @var{alpha}, double @var{beta}, int @var{mu}, int @var{nu})This function modifies the parameters @math{(\alpha, \beta, \mu, \nu)} ofan existing @code{gsl_integration_qaws_table} struct @var{t}.@end deftypefun@deftypefun void gsl_integration_qaws_table_free (gsl_integration_qaws_table * @var{t})This function frees all the memory associated with the@code{gsl_integration_qaws_table} struct @var{t}.@end deftypefun@deftypefun int gsl_integration_qaws (gsl_function * @var{f}, const double @var{a}, const double @var{b}, gsl_integration_qaws_table * @var{t}, const double @var{epsabs}, const double @var{epsrel}, const size_t @var{limit}, gsl_integration_workspace * @var{workspace}, double *@var{result}, double *@var{abserr})This function computes the integral of the function @math{f(x)} over theinterval @math{(a,b)} with the singular weight function@math{(x-a)^\alpha (b-x)^\beta \log^\mu (x-a) \log^\nu (b-x)}. The parameters of the weight function @math{(\alpha, \beta, \mu, \nu)} are taken from thetable @var{t}. The integral is,@tex\beforedisplay$$I = \int_a^b dx\, f(x) (x - a)^\alpha (b - x)^\beta \log^\mu (x - a) \log^\nu (b - x).$$\afterdisplay@end tex@ifinfo@exampleI = \int_a^b dx f(x) (x-a)^alpha (b-x)^beta log^mu (x-a) log^nu (b-x).@end example@end ifinfo@noindentThe adaptive bisection algorithm of QAG is used. When a subintervalcontains one of the endpoints then a special 25-point modifiedClenshaw-Curtis rule is used to control the singularities. Forsubintervals which do not include the endpoints an ordinary 15-pointGauss-Kronrod integration rule is used.@end deftypefun@node QAWO adaptive integration for oscillatory functions@section QAWO adaptive integration for oscillatory functions@cindex oscillatory functions, numerical integration ofThe QAWO algorithm is designed for integrands with an oscillatoryfactor, @math{\sin(\omega x)} or @math{\cos(\omega x)}. In order towork efficiently the algorithm requires a table of Chebyshev momentswhich must be pre-computed with calls to the functions below.@deftypefun {gsl_integration_qawo_table *} gsl_integration_qawo_table_alloc (double @var{omega}, double @var{L}, enum gsl_integration_qawo_enum @var{sine}, size_t @var{n})This function allocates space for a @code{gsl_integration_qawo_table}struct and its associated workspace describing a sine or cosine weightfunction @math{W(x)} with the parameters @math{(\omega, L)},@tex\beforedisplay$$\eqalign{W(x) & = \left\{\matrix{\sin(\omega x) \cr \cos(\omega x)} \right\}}$$\afterdisplay@end tex@ifinfo@exampleW(x) = sin(omega x)W(x) = cos(omega x)@end example@end ifinfo@noindentThe parameter @var{L} must be the length of the interval over which thefunction will be integrated @math{L = b - a}. The choice of sine orcosine is made with the parameter @var{sine} which should be chosen fromone of the two following symbolic values:@exampleGSL_INTEG_COSINEGSL_INTEG_SINE@end example@noindentThe @code{gsl_integration_qawo_table} is a table of the trigonometriccoefficients required in the integration process. The parameter @var{n}determines the number of levels of coefficients that are computed. Eachlevel corresponds to one bisection of the interval @math{L}, so that@var{n} levels are sufficient for subintervals down to the length@math{L/2^n}. The integration routine @code{gsl_integration_qawo}returns the error @code{GSL_ETABLE} if the number of levels isinsufficient for the requested accuracy.@end deftypefun@deftypefun int gsl_integration_qawo_table_set (gsl_integration_qawo_table * @var{t}, double @var{omega}, double @var{L}, enum gsl_integration_qawo_enum @var{sine})This function changes the parameters @var{omega}, @var{L} and @var{sine}of the existing workspace @var{t}.@end deftypefun@deftypefun int gsl_integration_qawo_table_set_length (gsl_integration_qawo_table * @var{t}, double @var{L})This function allows the length parameter @var{L} of the workspace@var{t} to be changed.@end deftypefun@deftypefun void gsl_integration_qawo_table_free (gsl_integration_qawo_table * @var{t})This function frees all the memory associated with the workspace @var{t}.@end deftypefun@deftypefun int gsl_integration_qawo (gsl_function * @var{f}, const double @var{a}, const double @var{epsabs}, const double @var{epsrel}, const size_t @var{limit}, gsl_integration_workspace * @var{workspace}, gsl_integration_qawo_table * @var{wf}, double *@var{result}, double *@var{abserr})This function uses an adaptive algorithm to compute the integral of@math{f} over @math{(a,b)} with the weight function @math{\sin(\omega x)} or @math{\cos(\omega x)} defined by the table @var{wf},@tex\beforedisplay$$\eqalign{I & = \int_a^b dx\, f(x) \left\{ \matrix{\sin(\omega x) \cr \cos(\omega x)}\right\}}$$\afterdisplay@end tex@ifinfo@exampleI = \int_a^b dx f(x) sin(omega x)I = \int_a^b dx f(x) cos(omega x)@end example@end ifinfo@noindentThe results are extrapolated using the epsilon-algorithm to acceleratethe convergence of the integral. The function returns the finalapproximation from the extrapolation, @var{result}, and an estimate ofthe absolute error, @var{abserr}. The subintervals and their results arestored in the memory provided by @var{workspace}. The maximum number ofsubintervals is given by @var{limit}, which may not exceed the allocatedsize of the workspace.Those subintervals with ``large'' widths @math{d}, @math{d\omega > 4} arecomputed using a 25-point Clenshaw-Curtis integration rule, which handles theoscillatory behavior. Subintervals with a ``small'' width@math{d\omega < 4} are computed using a 15-point Gauss-Kronrod integration.@end deftypefun@node QAWF adaptive integration for Fourier integrals@section QAWF adaptive integration for Fourier integrals@cindex Fourier integrals, numerical@deftypefun int gsl_integration_qawf (gsl_function * @var{f}, const double @var{a}, const double @var{epsabs}, const size_t @var{limit}, gsl_integration_workspace * @var{workspace}, gsl_integration_workspace * @var{cycle_workspace}, gsl_integration_qawo_table * @var{wf}, double *@var{result}, double *@var{abserr})This function attempts to compute a Fourier integral of the function@var{f} over the semi-infinite interval @math{[a,+\infty)}.@tex\beforedisplay$$\eqalign{I & = \int_a^{+\infty} dx\, f(x) \left\{ \matrix{ \sin(\omega x) \cr \cos(\omega x) } \right\}}$$\afterdisplay@end tex@ifinfo@exampleI = \int_a^@{+\infty@} dx f(x) sin(omega x)I = \int_a^@{+\infty@} dx f(x) cos(omega x)@end example@end ifinfoThe parameter @math{\omega} is taken from the table @var{wf} (the length@var{L} can take any value, since it is overridden by this function to avalue appropriate for the fourier integration). The integral is computedusing the QAWO algorithm over each of the subintervals,@tex\beforedisplay$$\eqalign{C_1 & = [a, a + c] \crC_2 & = [a + c, a + 2c] \cr\dots & = \dots \crC_k & = [a + (k-1) c, a + k c]}$$\afterdisplay@end tex@ifinfo@exampleC_1 = [a, a + c]C_2 = [a + c, a + 2 c]... = ...C_k = [a + (k-1) c, a + k c]@end example@end ifinfo@noindentwhere @c{$c = (2 \,\hbox{floor}(|\omega|) + 1) \pi/|\omega|$}@math{c = (2 floor(|\omega|) + 1) \pi/|\omega|}. The width @math{c} ischosen to cover an odd number of periods so that the contributions fromthe intervals alternate in sign and are monotonically decreasing when@var{f} is positive and monotonically decreasing. The sum of thissequence of contributions is accelerated using the epsilon-algorithm.This function works to an overall absolute tolerance of@var{abserr}. The following strategy is used: on each interval@math{C_k} the algorithm tries to achieve the tolerance@tex\beforedisplay$$TOL_k = u_k \hbox{\it abserr}$$\afterdisplay@end tex@ifinfo@exampleTOL_k = u_k abserr@end example@end ifinfo@noindentwhere @c{$u_k = (1 - p)p^{k-1}$}@math{u_k = (1 - p)p^@{k-1@}} and @math{p = 9/10}. The sum of the geometric series of contributions from each intervalgives an overall tolerance of @var{abserr}.If the integration of a subinterval leads to difficulties then theaccuracy requirement for subsequent intervals is relaxed,@tex\beforedisplay$$TOL_k = u_k \max(\hbox{\it abserr}, \max_{i<k}\{E_i\})$$\afterdisplay@end tex@ifinfo@exampleTOL_k = u_k max(abserr, max_@{i<k@}@{E_i@})@end example@end ifinfo@noindentwhere @math{E_k} is the estimated error on the interval @math{C_k}.The subintervals and their results are stored in the memory provided by@var{workspace}. The maximum number of subintervals is given by@var{limit}, which may not exceed the allocated size of the workspace.The integration over each subinterval uses the memory provided by@var{cycle_workspace} as workspace for the QAWO algorithm.@end deftypefun@node Numerical integration error codes@section Error codesIn addition to the standard error codes for invalid arguments thefunctions can return the following values,@table @code@item GSL_EMAXITERthe maximum number of subdivisions was exceeded.@item GSL_EROUNDcannot reach tolerance because of roundoff error,or roundoff error was detected in the extrapolation table.@item GSL_ESING a non-integrable singularity or other bad integrand behavior was foundin the integration interval.@item GSL_EDIVERGEthe integral is divergent, or too slowly convergent to be integratednumerically.@end table@node Numerical integration examples@section ExamplesThe integrator @code{QAGS} will handle a large class of definiteintegrals. For example, consider the following integral, which has aalgebraic-logarithmic singularity at the origin,@tex\beforedisplay$$\int_0^1 x^{-1/2} \log(x) \,dx = -4$$\afterdisplay@end tex@ifinfo@example\int_0^1 x^@{-1/2@} log(x) dx = -4@end example@end ifinfo@noindentThe program below computes this integral to a relative accuracy bound of@code{1e-7}.@example@verbatiminclude examples/integration.c@end example@noindentThe results below show that the desired accuracy is achieved after 8subdivisions. @examplebash$ ./a.out @verbatiminclude examples/integration.out@end example@noindentIn fact, the extrapolation procedure used by @code{QAGS} produces anaccuracy of almost twice as many digits. The error estimate returned bythe extrapolation procedure is larger than the actual error, giving amargin of safety of one order of magnitude.@node Numerical integration References and Further Reading@section References and Further Reading@noindentThe following book is the definitive reference for @sc{quadpack}, and waswritten by the original authors. It provides descriptions of thealgorithms, program listings, test programs and examples. It alsoincludes useful advice on numerical integration and many references tothe numerical integration literature used in developing @sc{quadpack}.@itemize @asis@itemR. Piessens, E. de Doncker-Kapenga, C.W. Uberhuber, D.K. Kahaner.@cite{@sc{quadpack} A subroutine package for automatic integration}Springer Verlag, 1983.@end itemize@noindent
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -