This page contains the description of one-dimensional integration algorithms included into the ALGLIB package.

Subroutine AutoGKSmooth includes an elementary algorithm of adaptive integration that calculates integrals of smooth functions. The algorithm is based on recursive partition of integration interval and processing the resulting subintervals with the Gauss-Kronrod quadrature formula (current implementation uses a 15-node formula). This quadrature formula allows for calculation of the integral itself and the estimate of its error. Subintervals are added into a heap and then the interval with the biggest absolute error is retrieved from the heap and partitioned again. The process is repeated until the aggregate relative error is not close to machine accuracy (the current implementation uses the following criterion: *|Err| ≤ ··ε·|Integral|*).

There is an alternative subroutine version - AutoGKSmoothW - which makes sure that the interval will be fragmented into subintervals that are no longer then a given value xwidth. This subroutine can be used to integrate functions with narrow peaks that can occur between two nodes of the Gauss-Kronrod quadrature formula and remain unnoticed. The subroutine AutoGKSmoothW makes sure that any peak not less then xwidth wide will be identified and taken into account when integrating the function.

The subroutines described above work well with smooth functions. However, their efficiency is substantially decreased if the function has integrable singularities at the interval ends, i.e. behaves like *(x-a) ^{ α}* or

The AutoGKSingular subroutine solves this problem. By change of variable it can make any singularity like *(x-a) ^{ α}* or

The integration algorithm shall obtain values of a function during its operation. This problem is solved in most program packages by transferring the pointer to the function (C++, Delphi) or delegate (C#) which is used to calculate function value.

The ALGLIB package, differently from other libraries, makes use of reverse communication to solve this problem. When a value of a function needs to be calculated, the algorithm state is stored within a special structure, control is returned to the calling program, which makes all calculations and recalls the computing subroutine.

Thus, the integration algorithm is used in accordance in the following order:

- AutoGKState data structure preparation by means of one of the algorithm initialization subrotuines (AutoGKSmooth, AutoGKSmoothW, AutoGKSingular).
- AutoGKIteration subroutine call.
- If False is returned from the subroutine, then the algorithm operation is completed and integral is successfully calculated (the integral itself can be obtained by calling the MinLMResults subprogram).
- If True is returned from the subroutine, the latter will make a request for information on the function. Calculate function value at State.X and save it in the State.F field. Then call AutoGKIteration again.

Please note that when using the AutoGKSingular subroutine (i.e. when integrating functions with singularities at the ends of the interval) one may need the function value at the point that is too close to one of the interval ends. For instance, when integrating the *f(x) = (1-x) ^{ -0.95}* function at the

To avoid this situation, the following measures are taken. When it is required to calculate the function value, the algorithm fills in both State.X field and the State.XMinusA and State.BMinusX fields. In the example above, State.X and State.XMinusA will be uqual to *1* (when using a double precision arithmetics), the field State.BMinusX will have the value of *10 ^{ -25}*. Using the field State.BMinusX allows for avoiding the zero divide error when calculating the function value. An example of using these fields can be found in the "Subroutines Description" section.

C++ | `autogk` subpackage | |

C# | `autogk` subpackage |

*This article is intended for personal use only.*

C# source.

C++ source.

C++ source. MPFR/GMP is used.

GMP source is available from gmplib.org. MPFR source is available from www.mpfr.org.

FreePascal version.

Delphi version.

VB.NET version.

VBA version.

Python version (CPython and IronPython are supported).

ALGLIB® - numerical analysis library, 1999-2014. |