XLPack 6.1
Python API Reference Manual
Loading...
Searching...
No Matches

◆ qag()

def qag ( ,
,
,
epsabs  = 1.0e-10,
epsrel  = 1.0e-10,
key  = 1,
limit  = 100 
)

Finite interval adaptive quadrature (15/21/31/41/51/61 point Gauss-Kronrod rule)

Purpose
This routine computes I = integral of f over [a, b], satisfying the requested accuracy, where f is a given function defined by a user supplied subroutine.
15, 21, 31, 41, 51 or 61 point Gauss-Kronrod rule is used, and the integration interval will be adaptively subdivided to satisfy the requested accuracy.
Returns
(result, abserr, info)

result (float):
Approximation to I = integral of f over [a, b].

abserr (float):
Estimate of the modulus of the absolute error, which should equal or exceed the true error.

info (int):
= 0: Successful exit
= -1: The argument f is invalid
= -7: The argument limit had an illegal value (limit < 1)
= 1: Maximum number of subdivisions allowed has been reached
= 2: Requested tolerance cannot be achieved due to roundoff error
= 3: Bad integrand behavior found in the integration interval
Parameters
[in]fThe user supplied subroutine which calculates the integrand function f(x) defined as follows. _CODE def f(x): return computed function value f(x) _ENDCODE
[in]aLower limit of integration.
[in]bUpper limit of integration.
[in]epsabs(Optional)
Absolute accuracy requested.
The requested accuracy is assumed to be satisfied if abserr <= max(epsabs, epsrel*|result|)). (default = 1.0e-10)
[in]epsrel(Optional)
Relative accuracy requested. (default = 1.0e-10)
The requested accuracy is assumed to be satisfied if abserr <= max(epsabs, epsrel*|result|)).
If epsabs <= 0 and epsrel < 50*eps, epsrel is assumed to be 50*eps, where eps is the machine precision.
[in]key(Optional)
Key for choice of local integration rule. (default = 1)
= 1: qk15
= 2: qk21
= 3: qk31
= 4: qk41
= 5: qk51
= 6: qk61
If key < 1, key = 1 is assumed. If key > 6, key = 6 is assumed.
[in]limit(Optional)
Maximum number of subintervals in the partition of the given integration interval [a, b]. (limit >= 1) (default = 100)
Reference
SLATEC (QUADPACK)
Example Program
Compute the following integral.
∫ 1/(1 + x^2) dx [0, 4] (= atan(4))
def f(x):
return 1/(1 + x**2)
def TestQag():
a = 0
b = 4
s, abserr, info = qag(f, a, b)
print(s, abserr, info)
def qag(f, a, b, epsabs=1.0e-10, epsrel=1.0e-10, key=1, limit=100)
Finite interval adaptive quadrature (15/21/31/41/51/61 point Gauss-Kronrod rule)
Example Results
>>> TestQag()
1.3258176636680326 1.2911582553319398e-10 0