|
|
◆ qagi()
| def qagi |
( |
f |
, |
|
|
bound |
, |
|
|
inf |
, |
|
|
epsabs |
= 1.0e-10, |
|
|
epsrel |
= 1.0e-10, |
|
|
limit |
= 100 |
|
) |
| |
Semi-infinite/infinite interval adaptive quadrature (15-point Gauss-Kronrod rule)
- Purpose
- This routine computes I = integral of f(x) over [bound, +inf], [-inf, bound] or [-inf, +inf], satisfying the requested accuracy, where f(x) is a given function defined by a user supplied subroutine.
15-point Gauss-Kronrod rule is used, and the integration interval will be adaptively subdivided to satisfy the requested accuracy.
The semi-infinite integration range is mapped onto the interval [0, 1], and then the integration rule is applied to compute the required integral. ∫ f(x)dx [bound, +∞] = ∫ f(bound + (1 - t)/t) / t^2 dt [0, 1]
The infinite integral will be computed as the sum of two semi-infinite integrals. ∫ f(x)dx [-∞, +∞] = ∫ (f(x) + f(-x)) dx [0, +∞]
- Returns
- (result, abserr)
result (float):
Approximation to the integral.
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
= -6: The argument limit had an illegal value (limit < 1)
= 1: Maximum number of subdivisions allowed has been achieved
= 2: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved
= 3: Extremely bad integrand behaviour occurs at some points of the integration interval
= 4: The algorithm does not converge. It is presumed that the requested tolerance cannot be achieved, and that the returned result is the best which can be obtained
= 5: The integral is probably divergent, or slowly convergent
- Parameters
-
| [in] | f | The 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] | bound | The finite bound of original integration range. (Not referenced if interval is doubly infinite (inf = 2)) |
| [in] | inf | The kind of integration range.
= 1: Semi-infinite integral [bound, +∞]
= -1: Semi-infinite integral [-∞, bound]
= 2: Infinite integral [-∞, +∞]
(If other value is specified, inf = 2 is assumed) |
| [in] | epsabs | (Optional)
Absolute accuracy requested. (default = 1.0e-10)
The requested accuracy is assumed to be satisfied if abserr <= max(epsabs, epsrel*|result|)). |
| [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] | limit | (Optional)
Maximum number of subintervals in the partition of the given integration interval. (limit >= 1) (default = 100) |
- Reference
- SLATEC (QUADPACK)
- Example Program
- Compute the following integral.
∫ 1/(1 + x^2) dx [0, +∞] (= π/2)
def f(x):
return 1/(1 + x**2)
def TestQagi():
bound = 0.0
inf = 2
s, abserr, info = qagi(f, bound, inf)
print('qagi [-inf, +inf]')
print(s, abserr, info)
inf = 1
s, abserr, info = qagi(f, bound, inf)
print('qagi [0, +inf]')
print(s, abserr, info)
inf = -1
s, abserr, info = qagi(f, bound, inf)
print('qagi [-inf, 0]')
print(s, abserr, info)
def qagi(f, bound, inf, epsabs=1.0e-10, epsrel=1.0e-10, limit=100) Semi-infinite/infinite interval adaptive quadrature (15-point Gauss-Kronrod rule)
- Example Results
>>> TestQagi()
3.141592653589793 2.5779659138999894e-10 0
1.5707963267948966 1.2889829569499947e-10 0
1.5707963267948966 1.2889829569499947e-10 0
|