GaussKronrod

(Source code, png, hires.png, pdf)

../../_images/GaussKronrod.png
class GaussKronrod(*args)

Adaptive integration algorithm of Gauss-Kronrod.

Parameters
maximumSubIntervalsint

The maximal number of subdivisions of the interval [a,b]

maximumErrorfloat

The maximal error between Gauss and Kronrod approximations.

GKRuleGaussKronrodRule

The rule that fixes the number of points used in the Gauss and Kronrod approximations.

Notes

The Gauss-Kronrod algorithm enables to approximate the definite integral:

\int_{a}^b f(t)\di{t}

with f: \Rset \mapsto \Rset^p, using both approximations : Gauss and Kronrod ones defined by:

\int_{-1}^1 f(t)\di{t} \simeq  \omega_0f(0) + \sum_{k=1}^n \omega_k (f(\xi_k)+f(-\xi_k))

and:

\int_{-1}^1 f(t)\di{t}\simeq  \alpha_0f(0) + \sum_{k=1}^{m} \alpha_k (f(\zeta_k)+f(-\zeta_k))

where \xi_k>0, \zeta_k>0, \zeta_{2j}=\xi_j, \omega_k>0 and \alpha_k>0.

The Gauss-Kronrod algorithm evaluates the integral using the Gauss and the Konrod approximations. If the difference between both approximations is greater that maximumError, then the interval [a,b] is subdivided into 2 subintervals with the same length. The Gauss-Kronrod algorithm is then applied on both subintervals with the sames rules. The algorithm is iterative until the difference between both approximations is less that maximumError. In that case, the integral on the subinterval is approximated by the Kronrod sum. The subdivision process is limited by maximumSubIntervals that imposes the maximum number of subintervals.

The final integral is the sum of the integrals evaluated on the subintervals.

Examples

Create a Gauss-Kronrod algorithm:

>>> import openturns as ot
>>> algo = ot.GaussKronrod(100, 1e-8, ot.GaussKronrodRule(ot.GaussKronrodRule.G11K23))

Methods

getClassName(self)

Accessor to the object’s name.

getId(self)

Accessor to the object’s id.

getMaximumError(self)

Accessor to the maximal error between Gauss and Kronrod approximations.

getMaximumSubIntervals(self)

Accessor to the maximal number of subdivisions of [a,b].

getName(self)

Accessor to the object’s name.

getRule(self)

Accessor to the Gauss-Kronrod rule used in the integration algorithm.

getShadowedId(self)

Accessor to the object’s shadowed id.

getVisibility(self)

Accessor to the object’s visibility state.

hasName(self)

Test if the object is named.

hasVisibleName(self)

Test if the object has a distinguishable name.

integrate(self, \*args)

Evaluation of the integral of f on an interval.

setMaximumError(self, maximumError)

Set the maximal error between Gauss and Kronrod approximations.

setMaximumSubIntervals(self, maximumSubIntervals)

Set the maximal number of subdivisions of [a,b].

setName(self, name)

Accessor to the object’s name.

setRule(self, rule)

Set the Gauss-Kronrod rule used in the integration algorithm.

setShadowedId(self, id)

Accessor to the object’s shadowed id.

setVisibility(self, visible)

Accessor to the object’s visibility state.

__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

getClassName(self)

Accessor to the object’s name.

Returns
class_namestr

The object class name (object.__class__.__name__).

getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getMaximumError(self)

Accessor to the maximal error between Gauss and Kronrod approximations.

Returns
maximumErrorvaluefloat, positive

The maximal error between Gauss and Kronrod approximations.

getMaximumSubIntervals(self)

Accessor to the maximal number of subdivisions of [a,b].

Returns
maximumSubIntervalsfloat, positive

The maximal number of subdivisions of the interval [a,b].

getName(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getRule(self)

Accessor to the Gauss-Kronrod rule used in the integration algorithm.

Returns
ruleGaussKronrodRule

The Gauss-Kronrod rule used in the integration algorithm.

getShadowedId(self)

Accessor to the object’s shadowed id.

Returns
idint

Internal unique identifier.

getVisibility(self)

Accessor to the object’s visibility state.

Returns
visiblebool

Visibility flag.

hasName(self)

Test if the object is named.

Returns
hasNamebool

True if the name is not empty.

hasVisibleName(self)

Test if the object has a distinguishable name.

Returns
hasVisibleNamebool

True if the name is not empty and not the default one.

integrate(self, \*args)

Evaluation of the integral of f on an interval.

Available usages:

integrate(f, interval)

integrate(f, interval, error)

integrate(f, a, b, error, ai, bi, fi, ei)

Parameters
fFunction, f: \Rset \mapsto \Rset^p

The integrand function.

intervalInterval, interval \in \Rset

The integration domain.

errorPoint

The error estimation of the approximation.

a,bfloat

Bounds of the integration interval.

ai, bi, eiPoint;

ai is the set of lower bounds of the subintervals;

bi the corresponding upper bounds;

ei the associated error estimation.

fiSample

fi is the set of \int_{ai}^{bi} f(t)\di{t}

Returns
valuePoint

Approximation of the integral.

Examples

>>> import openturns as ot
>>> f = ot.SymbolicFunction(['x'], ['abs(sin(x))'])
>>> a = -2.5
>>> b = 4.5
>>> algoGK = ot.GaussKronrod(100, 1e-8, ot.GaussKronrodRule(ot.GaussKronrodRule.G11K23))

Use the high-level usage:

>>> value = algoGK.integrate(f, ot.Interval(a, b))[0]
>>> print(value)
4.590...

Use the low-level usage:

>>> error = ot.Point()
>>> ai = ot.Point()
>>> bi = ot.Point()
>>> ei = ot.Point()
>>> fi = ot.Sample()
>>> value2 = algoGK.integrate(f, a, b, error, ai, bi, fi, ei)[0]
>>> print(value2)
4.590...
setMaximumError(self, maximumError)

Set the maximal error between Gauss and Kronrod approximations.

Parameters
maximumErrorvaluefloat, positive

The maximal error between Gauss and Kronrod approximations.

setMaximumSubIntervals(self, maximumSubIntervals)

Set the maximal number of subdivisions of [a,b].

Parameters
maximumSubIntervalsfloat, positive

The maximal number of subdivisions of the interval [a,b].

setName(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setRule(self, rule)

Set the Gauss-Kronrod rule used in the integration algorithm.

Parameters
ruleGaussKronrodRule

The Gauss-Kronrod rule used in the integration algorithm.

setShadowedId(self, id)

Accessor to the object’s shadowed id.

Parameters
idint

Internal unique identifier.

setVisibility(self, visible)

Accessor to the object’s visibility state.

Parameters
visiblebool

Visibility flag.