XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Avint()

Sub Avint ( N As  Long,
X() As  Double,
Y() As  Double,
A As  Double,
B As  Double,
Result As  Double,
Info As  Long 
)

Finite interval quadrature for a function with tabulated data (approximation with overlapping parabolas)

Purpose
This routine integrates a function tabulated at arbitrarily spaced abscissas. The limits of integration need not coincide with the tabulated abscissas.
A method of overlapping parabolas fitted to the data is used provided that there are at least 3 abscissas between the limits of integration.
Avint also handles two special cases.
  • If the limits of integration are equal, Avint returns a result of zero regardless of the number of tabulated values.
  • If there are only two function values, Avint uses the trapezoid rule.
Parameters
[in]NNumber of data. (N >= 2)
[in]X()Array X(LX - 1) (LX >= N)
Abscissas (strictly in increasing order).
[in]Y()Array Y(LY - 1) (LY >= N)
Ordinates (function values).
[in]ALower limit of integration. (A <= B)
[in]BUpper limit of integration. (A <= B)
[out]ResultComputed approximate value of integral.
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N < 2)
= -2: The argument X() is invalid.
= -3: The argument Y() is invalid.
= -4: The argument A (or B) had an illegal value. (A > B)
= 1: Less than 3 function values between the limits of integration.
= 2: Abscissas not strictly in increasing order.
Reference
SLATEC
Example Program
Using the following table, compute S = integral of 1/(1 + x^2) dx [0, 4] (= atan(4)).
x 1/(1 + x^2)
----- -------------
-1 0.5
0 1
1 0.5
2 0.2
3 0.1
4 0.05882
5 0.03846
----- -------------
Sub Ex_Avint()
Const N = 7, A = 0, B = 4
Dim X(N - 1) As Double, Y(N - 1) As Double, S As Double
Dim Info As Long, I As Long
'-- Data
X(0) = -1: Y(0) = 0.5
X(1) = 0: Y(1) = 1
X(2) = 1: Y(2) = 0.5
X(3) = 2: Y(3) = 0.2
X(4) = 3: Y(4) = 0.1
X(5) = 4: Y(5) = 0.05882
X(6) = 5: Y(6) = 0.03846
'-- Compute integral 1/(1 + x^2) dx [0, 4] (= atan(4))
Call Avint(N, X(), Y(), A, B, S, Info)
Debug.Print "S =", S, "S(true) =", Atn(4)
Debug.Print "Info =", Info
End Sub
Sub Avint(N As Long, X() As Double, Y() As Double, A As Double, B As Double, Result As Double, Info As Long)
Finite interval quadrature for a function with tabulated data (approximation with overlapping parabol...
Example Results
S = 1.33197416666667 S(true) = 1.32581766366803
Info = 0