|
|
◆ Qag()
| Sub Qag |
( |
F As |
LongPtr, |
|
|
A As |
Double, |
|
|
B As |
Double, |
|
|
Result As |
Double, |
|
|
Info As |
Long, |
|
|
Optional AbsErr As |
Double, |
|
|
Optional Neval As |
Long, |
|
|
Optional EpsAbs As |
Double = -1, |
|
|
Optional EpsRel As |
Double = -1, |
|
|
Optional Key As |
Long = -1, |
|
|
Optional Limit As |
Long = -1, |
|
|
Optional Last As |
Long |
|
) |
| |
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.
- Parameters
-
| [in] | F | The user supplied subroutine which calculates the integrand function f(x) defined as follows. Function F(X As Double) As Double
F = f(X)
End Function
X should not be changed. |
| [in] | A | Lower limit of integration a. |
| [in] | B | Upper limit of integration b. |
| [out] | Result | Approximation to the integral. |
| [out] | Info | = 0: Successful exit.
= 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 behavior occurs at some points of the integration interval. |
| [out] | AbsErr | (Optional)
Estimate of the modulus of the absolute error, which should equal or exceed the true error. |
| [out] | Neval | (Optional)
Number of integrand evaluations. |
| [in] | EpsAbs | (Optional)
Absolute accuracy requested. (default = 0)
The requested accuracy is assumed to be satisfied if AbsErr <= max(EpsAbs, EpsRel*|Result|))
(If EpsAbs < 0, the default value will be used) |
| [in] | EpsRel | (Optional)
Relative accuracy requested. (default = 1.0e-12)
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.
(If EpsRel < 0, the default value will be used) |
| [in] | Key | (Optional)
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 used. If Key > 6, Key = 6 is used) |
| [in] | Limit | (Optional)
Maximum number of subintervals in the partition of the given integration interval [a, b] (limit >= 1) (default = 100)
(If Limit < 1, the default value will be used) |
| [out] | Last | (Optional)
Number of subintervals produced in the subdivision process. |
- Reference
- SLATEC (QUADPACK)
- Example Program
- Compute the following integral.
∫ 1/(1 + x^2) dx [0, 4] (= atan(4))
Function F1(X As Double) As Double
F1 = 1 / (1 + X ^ 2)
End Function
Sub Ex_Qag()
Dim A As Double, B As Double, Result As Double, Info As Long
A = 0: B = 4
Call Qag(AddressOf F1, A, B, Result, Info)
Debug.Print "S =", Result, "S(true) =", Atn(4)
Debug.Print "Info =", Info
End Sub
Sub Qag(F As LongPtr, A As Double, B As Double, Result As Double, Info As Long, Optional AbsErr As Double, Optional Neval As Long, Optional EpsAbs As Double=-1, Optional EpsRel As Double=-1, Optional Key As Long=-1, Optional Limit As Long=-1, Optional Last As Long) Finite interval adaptive quadrature (15/21/31/41/51/61 point Gauss-Kronrod rule)
- Example Results
S = 1.32581766366803 S(true) = 1.32581766366803
Info = 0
|