Several classes integrate arbitrary one-dimensional functions
cos(x)
or sin(x)
: o2scl::inte_qawo_gsl_cos and o2scl::inte_qawo_gsl_sin
All of these classes are children of o2scl::inte, and the relative and absolute tolerances are stored in o2scl::inte::tol_rel and o2scl::inte::tol_abs, respectively.
There are two competing factors that can slow down an adaptive integration algorithm: (1) each evaluation of the integrand can be numerically expensive, depending on how the function is defined, and (2) the process of subdividing regions and recalculating values is almost always numerically expensive in its own right. For integrands that are very smooth (e.g., analytic functions), a high-order Gauss-Kronrod rule (e.g., 61-point) will achieve the desired error tolerance with relatively few subdivisions. For integrands with discontinuities or singular derivatives, a low-order rule (e.g., 15-point) is often more efficient.
For the GSL-based integration routines, the variables o2scl::inte::tol_abs and o2scl::inte::tol_rel have the same role as the quantities usually denoted in the GSL integration routines by epsabs
and epsrel
. In particular, the integration classes attempt to ensure that
and returns an error to attempt to ensure that
where I
is the integral to be evaluated. Even when the corresponding descendant of o2scl::inte::integ() returns success, these inequalities may fail for sufficiently difficult functions. All of the GSL integration routines except for o2scl::inte_qng_gsl use a workspace given in o2scl::inte_workspace_gsl which holds the results of the various subdivisions of the original interval.
The GSL routines were originally based on QUADPACK, which is available at http://www.netlib.org/quadpack .
For adaptive GSL integration classes, the type of Gauss-Kronrod quadrature rule that is used to approximate the integral and estimate the error of a subinterval is set by o2scl::inte_kronrod_gsl::set_rule().
The number of subdivisions of the integration region is limited by the size of the workspace, set in o2scl::inte_kronrod_gsl::set_limit(). The number of subdivisions required for the most recent call to o2scl::inte::integ() or o2scl::inte::integ_err() is given in o2scl::inte::last_iter. This number will always be less than or equal to the workspace size.
The error messages given by the adaptive GSL integration routines tend to follow a standard form and are documented here. There are several error messages which indicate improper usage and cause the error handler to be called regardless of the value of o2scl::inte::err_nonconv :
"Iteration limit exceeds workspace in
class::function()."
[o2scl::exc_einval]"Could not integrate function in class::function() (it
may have returned a non-finite result)."
[o2scl::exc_efailed] This often occurs when the user-specified function returns inf
or nan
."Tolerance cannot be achieved with given value of tol_abs
and tol_rel in class::function()."
[o2scl::exc_ebadtol] "Cannot integrate with singularity on endpoint in
inte_qawc_gsl::qawc()."
[o2scl::exc_einval] The class o2scl::inte_qawc_gsl cannot handle the case when a singularity is one of the endpoints of the integration.There are also convergence errors which will call the error handler unless o2scl::inte::err_nonconv is false (see What is an error?) for more discussion on convergence errors versus fatal errors):
"Cannot reach tolerance because of roundoff error on first
attempt in class::function()."
[o2scl::exc_eround] "A maximum of 1 iteration was insufficient in
class::function()."
[o2scl::exc_emaxiter] "Bad integrand behavior in class::function()."
[o2scl::exc_esing] "Maximum number of subdivisions 'value' reached in
class::function()."
[o2scl::exc_emaxiter] "Roundoff error prevents tolerance from being achieved in
class::function()."
[o2scl::exc_eround] "Roundoff error detected in extrapolation table in
inte_singular_gsl::qags()."
[o2scl::exc_eround] "Integral is divergent or slowly convergent in
inte_singular_gsl::qags()."
[o2scl::exc_ediverge] "Exceeded limit of trigonometric table in
inte_qawo_gsl_sin()::qawo()."
[o2scl::exc_etable] O2scl reimplements the Cubature library for multi-dimensional integration. The h-adaptive and p-adaptive integration methods are implemented in o2scl::inte_hcubature and o2scl::inte_pcubature . See also the Monte Carlo integration routines in Monte Carlo Integration .
This example computes the integral with o2scl::inte_qagi_gsl, the integral
with o2scl::inte_qagiu_gsl, the integral
with o2scl::inte_qagil_gsl, and the integral
with both o2scl::inte_qag_gsl and o2scl::inte_adapt_cern, and compares the computed results with the exact results.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).