|
|
◆ Qagi()
| Sub Qagi |
( |
F As |
LongPtr, |
|
|
Bound As |
Double, |
|
|
Inf As |
Long, |
|
|
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 Limit As |
Long = -1, |
|
|
Optional Last As |
Long |
|
) |
| |
Infinite interval automatic quadrature (adaptive automatic quadrature)
- 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, +∞]
- 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] | 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) |
| [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.
= 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. |
| [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] | Limit | (Optional)
Maximum number of subintervals in the partition of the given integration interval (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, +∞] (= π/2)
Function F1(X As Double) As Double
F1 = 1 / (1 + X ^ 2)
End Function
Sub Ex_Qagi()
Dim Bound As Double, Inf As Long, Result As Double, Info As Long
Bound = 0: Inf = 1
Call Qagi(AddressOf F1, Bound, Inf, Result, Info)
Debug.Print "S =", Result, "S(true) =", Dconst(13) / 2
Debug.Print "Info =", Info
End Sub
Function Dconst(I As Long, Optional Info As Long) As Double Numerical quantities
Sub Qagi(F As LongPtr, Bound As Double, Inf As Long, 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 Limit As Long=-1, Optional Last As Long) Infinite interval automatic quadrature (adaptive automatic quadrature)
- Example Results
S = 1.5707963267949 S(true) = 1.5707963267949
Info = 0
|