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

◆ Polcof()

Sub Polcof ( XX As  Double,
N As  Long,
X() As  Double,
C() As  Double,
D() As  Double,
Info As  Long 
)

Coefficients of polynomial interpolation

Purpose
This routine computes the coefficients of the polynomial fit produced by a previous call to Polint.
Parameters
[in]XXThe point about which the Taylor expansion is to be made.
[in]NThe number of data points (must remain unchanged between the call to Polint and the call to Polcof).
[in]X()Array X(LX - 1) (LX >= N)
The array of abscissas (must remain unchanged between the call to Polint and the call to Polcof).
[out]C()Array C(LC - 1) (LC >= N)
An array of information produced by subroutines Polint (must remain unchanged between the call to Polint and the call to Polcof).
[out]D()Array D(LD - 1) (LD >= N)
The array of coefficients for the Taylor expansion about XX.
P(Z) = D(0) + D(1)*(Z-XX) + D(2)*((Z-XX)^2) + ... + D(N-1)*((Z-XX)^(N-1))
[out]Info= 0: Successful exit
= -2: The argument N had an illegal value (N < 1)
= -3: The argument X() is invalid
= -4: The argument C() is invalid
= -5: The argument D() is invalid
Reference
SLATEC
Example Program
Compute the coefficients of the polynomial fit by interpolating the following natural logarithm table. Then compute ln(0.115) and ln(0.125) using obtained polynomial.
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Polcof()
Const N As Long = 4
Dim X(N - 1) As Double, Y(N - 1) As Double, C(N - 1) As Double, D(N - 1) As Double
Dim Xe As Double, XX 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
'-- 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 coefficients of polynomial
XX = 0.12
Call Polcof(XX, N, X(), C(), D(), Info)
Debug.Print D(0), D(1), D(2), D(3)
'-- Compute ln(0.115) and ln(0.125)
Xe = 0.115
Debug.Print "ln(" + CStr(Xe) + ") =", D(0) + D(1) * (Xe - XX) + D(2) * ((Xe - XX) ^ 2) + D(3) * ((Xe - XX) ^ 3)
Xe = 0.125
Debug.Print "ln(" + CStr(Xe) + ") =", D(0) + D(1) * (Xe - XX) + D(2) * ((Xe - XX) ^ 2) + D(3) * ((Xe - XX) ^ 3)
Debug.Print "Info =", Info
End Sub
Sub Polint(N As Long, X() As Double, Y() As Double, C() As Double, Info As Long)
Polynomial interpolation
Sub Polcof(XX As Double, N As Long, X() As Double, C() As Double, D() As Double, Info As Long)
Coefficients of polynomial interpolation
Example Results
-2.1203 8.33166666666668 -34.5000000000022 233.333333333222
ln(0.115) = -2.16285
ln(0.125) = -2.079475
Info = 0