Page 233 - Excel for Scientists and Engineers: Numerical Methods
P. 233
210 EXCEL: NUMERICAL METHODS
V(C) * (1 - incr)))
A(R, C) = (Y2 - Y1) / (2 * incr * V(C))
Next C
Next R
'Augment matrix of derivatives with vector of constants.
ForR=l TON
FormulaString(R) = Application.ConvertForrnula(equations(R).Formula, -
xlAl, xlAl , xlAbsolute)
ForC = 1 To N
FormulaString(R) = Application.Substitute(FormulaString(R), VarAddr(C), -
V(CN
Next C
A(R, N + 1) = con(R) - Evaluate(FormulaString(R))
Next R
For I = 1 To N
If Abs((A(1, N + 1)) I V(I)) > tolerance Then GoTo Refine
Next I
SimultEqNL = Application.Transpose(V)
Exit Function
Refine: Call GaussJordan3(N, A, B)
'Update V values
For I = 1 To N
V(I) = V(1) + A(I, N + 1)
Next I
Next J
' Exit here if no convergence after 50 cycles of iteration
SimultEqNL = CVErr(x1ErrNA)
End Function
..............................................................
Sub GaussJordan3(N, AugMatrix, TempMatrix)
Dim I As Integer, J As Integer, K As Integer, L As Integer, P As Integer
Dim pivot As Double, temp As Double
For K = 1 To N
' Locate largest matrix element, use as pivot.
pivot = AugMatrix(K, K): P = K
ForL=K+IToN
If Abs(AugMatrix(L, K)) < Abs(pivot) Then GoTo EndOfLoop
pivot = AugMatrix(L, K)
P=L
EndOfLoop: Next L
' Swap rows
ForJ = 1 To N + 1
temp = AugMatrix(K, J)
AugMatrix(K, J) = AugMatrix(P, J)
AugMatrix(P, J) = temp
Next J