Page 117 - Excel for Scientists and Engineers: Numerical Methods
P. 117
94 EXCEL: NUMERICAL METHODS
If C c 2 Then C = 2
If C > known-y's.Count - 2 Then C = knownj's.Count - 2
ForN=l To4
Create array of four knownj's, four known-z's, four known-x's
Check values to see whether ascending or descending,
and transfer input data to arrays in ascending order always.
XX(N) = known-x's(R + N - 2)
If known-y's(C + 2) > knownj's(C - 1) Then
ForM=l TO4
W(M) = knownj's(C + M - 2)
If known-z's(R + N - 2, C + M - 2) = "" Then InterpC2 = -
CVErr(x1ErrNA): Exit Function
ZZ(M) = known-z's(R + N - 2, C + M - 2)
Next M
Else
ForM=l To4
W(M) = known-y's(C - M + 3)
If known-z's(R + N - 2, C - M + 3) = "" Then InterpC2 = -
CVErr(x1ErrNA): Exit Function
ZZ(M) = known-z's(R + N - 2, C - M + 3)
Next M
End If
Zlnterp(N) = Cl(y-lookup, W, ZZ)
'This is array of interpolated Z values at y-lookup
Next N
InterpC2 = Cl(x-lookup, XX, Zlnterp)
End Function
..............................................................
Private Function Cl(lookup-value, known-x's, known-y's)
' Performs cubic interpolation, using an array of known-x's, knownj's (four
values of each)
' This is a modified version of the function InterpC.
Dim i As Integer, j As Integer
Dim Q As Double, Y As Double
For i = 1 To 4
Q=l
Forj=ITo4
If i c> j Then Q = Q (lookup-value - known-x*s(j)) I (known-x's(i) - -
known-x's(j))
Next j
Y = Y + Q * known-y's(i)
Next i
CI =Y
End Function
Figure 5-21. Cubic interpolation function procedure for use with a two-way table.
(folder 'Chapter 05 Interpolation', workbook 'Interpolation II', module 'CubicZWay')