XLPack 6.1
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Qagp()

Sub Qagp ( F As  LongPtr,
A As  Double,
B As  Double,
Npts As  Long,
Points() 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 Limit As  Long = -1,
Optional Last As  Long 
)

Finite interval adaptive quadrature with known singular points (21-point Gauss-Kronrod rule)

Purpose
The routine computes an approximation result to a definite integral I = integral of f(x) over [a, b], satisfying the requested accuracy. Break points of the integration interval, where local difficulties of the integrand may occur (e.g. singularities, discontinuities), can be provided by the user.
Result is obtained by the adaptive integration applying the 21-point Gauss-Kronrod rule to satisfy the requested accuracy.
Parameters
[in]FThe 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]ALower limit of integration a.
[in]BUpper limit of integration b.
[in]NptsNumber of user provided break points. (Npts >= 0)
[in]Points()Array Points(LPoints - 1) (LPoints >= max(NPts, 1))
Points(0) to Points(NPts - 1) are user provided break points. (The break points should be specified inside the integration interval)
[out]ResultApproximation to the integral.
[out]Info= 0: Successful exit.
= -4: The argument npts had an illegal value. (npts < 0)
= -5: The argument Points() is invalid.
= 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.
= 4: Algorithm does not converge due to the roundoff error in the extrapolation table.
= 5: The integral is probably divergent, or slowly convergent.
= 6: Singular points are specified outside 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]Limit(Optional)
Maximum number of subintervals in the partition of the given integration interval [a, b] (limit >= Npts + 1) (default = Npts + 100)
(If Limit < Npts + 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.
∫ x^3*ln(abs((x^2 - 1)(x^2 - 2))) dx [0, 3] (= 52.740748)
There are two singular points at x = 1 and x = √2.
Function F2(X As Double) As Double
F2 = X ^ 3 * Log(Abs((X ^ 2 - 1) * (X ^ 2 - 2)))
End Function
Sub Ex_Qagp()
Const Npts = 2
Dim A As Double, B As Double, Result As Double, Points(Npts - 1) As Double
Dim Info As Long, Neval As Long, EpsRel As Double
A = 0: B = 3
Points(0) = 1: Points(1) = Sqr(2)
EpsRel = 0.00000001 '1.0e-8
Call Qagp(AddressOf F2, A, B, Npts, Points(), Result, Info, , Neval, , EpsRel)
Debug.Print "S =", Result, "Neval =", Neval
Debug.Print "Info =", Info
End Sub
Sub Qagp(F As LongPtr, A As Double, B As Double, Npts As Long, Points() 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 Limit As Long=-1, Optional Last As Long)
Finite interval adaptive quadrature with known singular points (21-point Gauss-Kronrod rule)
Example Results
S = 52.7407483840768 Neval = 3843
Info = 0