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

◆ Fitlag()

Function Fitlag ( X As  Double,
N As  Long,
A() As  Double,
F() As  Double,
Optional Info As  Long,
Optional M As  Long = 5,
Optional Eps As  Double = 1.0e-8 
)

Iterative Lagrange interpolation

Purpose
This routine routine computes the interpolated value using the data table by iterative Lagrange interpolation.
Lagrange interpolation is computed using nearest sample points to the target point. Starting from two points, interpolation is automatically iterated by increasing number of points used for computation until the required tolerance is satisfied.
Returns
Double
The interpolated value at x.
Parameters
[in]XAbscissa x at which the interpolated value is to be computed.
[in]NNumber of data given in the table. (N > 0)
[in]A()Array A(LA - 1) (LA >= N)
Sampling points. Elements of A() must be in ascending order.
[in]F()Array F(LF - 1) (LF >= N)
Data at sampling points A().
[out]Info(Optional)
= 0: Successful exit.
= -2: The argument N had an illegal value. (N <= 0)
= -5: The argument M had an illegal value. (M < 1 or M > 5)
= 1: X is outside the range of sample points (computation to be continued).
= 2: Not converged (given error tolerance not satisfied).
[in]M(Optional)
Maximum number of sampling points to be used in both sides of x for interpolation. (1 <= M <= 5) (default = 5)
[in]Eps(Optional)
Absolute error tolerance. (Eps > 0) (default = 1.0E-8)
If Eps <= 0 then Eps = (machine epsilon) is assumed.
Reference
(Japanese book) Masatake Mori "FORTRAN77 Numerical Calculation Programming (augmented edition)" Iwanami Shoten (1987)
Example Program
Compute ln(0.115) and ln(0.125) by interpolating the following natural logarithm table.
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Fitlag()
Const N As Long = 4
Dim X(N - 1) As Double, Y(N - 1) As Double, Xe As Double, Ye As Double, Info As Long
'-- Data
X(0) = 0.1: Y(0) = -2.3026
X(1) = 0.11: Y(1) = -2.2073
X(2) = 0.12: Y(2) = -2.1203
X(3) = 0.13: Y(3) = -2.0402
'-- Compute ln(0.115) and ln(0.125)
Xe = 0.115
Ye = Fitlag(Xe, N, X(), Y(), Info, , 0.0001)
Debug.Print "ln(" + CStr(Xe) + ") = " + Str(Ye) + " (Info =" + Str(Info) + ")"
Xe = 0.125
Ye = Fitlag(Xe, N, X(), Y(), Info, , 0.0001)
Debug.Print "ln(" + CStr(Xe) + ") = " + Str(Ye) + " (Info =" + Str(Info) + ")"
End Sub
Function Fitlag(X As Double, N As Long, A() As Double, F() As Double, Optional Info As Long, Optional M As Long=5, Optional Eps As Double=1.0e-8) As Double
Iterative Lagrange interpolation
Example Results
ln(0.115) = -2.16285 (Info = 0)
ln(0.125) = -2.079475 (Info = 0)