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

◆ Polint()

Sub Polint ( N As  Long,
X() As  Double,
Y() As  Double,
C() As  Double,
Info As  Long 
)

Polynomial interpolation

Purpose
This routine produces a polynomial which interpolates a set of discrete data points. Polint sets up information in the array c[] which can be used by subroutine Polyvl to evaluate the polynomial and its derivatives and by subroutine Polcof to produce the coefficients.
Parameters
[in]NThe number of data points. (N >= 1)
[in]X()Array X(LX - 1) (LX >= N)
The array of abscissas. (All of which must be distinct)
[in]Y()Array Y(LY - 1) (LY >= N)
The array of ordinates.
[out]C()Array C(LC - 1) (LC >= N)
An array of information used by subroutines Polyvl and Polcof.
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N <= 0)
= -2: The argument X() is invalid.
= -3: The argument Y() is invalid.
= -4: The argument C() is invalid.
= 1: The abscissas are not distinct.
Reference
SLATEC
Example Program
Compute ln(0.115) and its derivative ln'(0.115) 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_Polint()
Const N As Long = 4
Dim X(N - 1) As Double, Y(N - 1) As Double, C(N - 1) As Double
Dim Xe As Double, Ye As Double, Yep(0) As Double
Dim 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
'-- Polynomial interpolation
Call Polint(N, X(), Y(), C(), Info)
If Info <> 0 Then
Debug.Print "Error in Polint: Info =", Info
Exit Sub
End If
'-- Compute interpolated values
Xe = 0.115
Call Polyvl(1, Xe, Ye, Yep(), N, X(), C(), Info)
Debug.Print "ln(" + CStr(Xe) + ") =", Ye
Debug.Print "ln'(" + CStr(Xe) + ") =", Yep(0)
Debug.Print "Info =", Info
End Sub
Sub Polyvl(Nder As Long, XX As Double, Yfit As Double, Yp() As Double, N As Long, X() As Double, C() As Double, Info As Long)
Value of polynomial and derivatives
Sub Polint(N As Long, X() As Double, Y() As Double, C() As Double, Info As Long)
Polynomial interpolation
Example Results
ln(0.115) = -2.16285
ln'(0.115) = 8.69416666666669
Info = 0