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

◆ qag()

function qag ( f::Function  ,
a::Real  ,
b::Real  ,
epsabs::Real  = 1.0e-10,
epsrel::Real  = 1.0e-10,
key::Integer  = 1,
limit::Integer  = 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 (Float64):
Approximation to I = integral of f over [a, b].

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

info (Int32):
= 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 function f(x) returns computed function value f(x). end _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))
function TestQag()
f(x) = 1/(1 + x^2)
a = 0
b = 4
s, abserr, info = qag(f, a, b)
println(s, " ", abserr, " ", info)
end
function qag(f::Function, a::Real, b::Real, epsabs::Real=1.0e-10, epsrel::Real=1.0e-10, key::Integer=1, limit::Integer=100)
Finite interval adaptive quadrature (15/21/31/41/51/61 point Gauss-Kronrod rule)
Example Results
> TestQag()
1.3258176636680326 1.2911582553319398e-10 0