Page 220 - Excel for Scientists and Engineers: Numerical Methods
P. 220
CHAPTER 9 SYSTEMS OF SIMULTANEOUS EQUATIONS 197
1 : : : Ij:;
0 0 1 0 149
0 0 0 1 154
The advantage of this method is that the calculation of the vector of results is
simplified.
The VBA custom function GaussJordanl, shown in Figure 9-5 incorporates
partial pivoting. Two versions are provided on the CD that accompanies this
book: the first version, GaussJordanl, has the syntax
GaussJordan 1 (coeff-matrix, const-vector, value-index). The value-index
argument specifies the element of the results vector to be returned. The second
version, GaussJordan2, has the syntax GaussJordan2(coeff-matrix,
const-vector), and returns the vector of results. You must select an
appropriately sized range of cells and press CTRL+SHIFT+ENTER (Windows) or
COMMAND+RETURN or CTRL+SHIFT+RETURN (Macintosh).
Option Base 1
Option Explicit
'Solving systems of linear equations by the Gauss-Jordan elimination method
........................................................
Function GaussJordanl (coeff-matrix, const-vector, value-index)
' This version returns a single element of the solution vector,
' specified by value-index.
Dim X() As Double, AugMatrix() As Double, PivotRow() As Integer
Dim PivotLogical() As Boolean
Dim I As Integer, J As Integer
Dim R As Integer, C As Integer, P As Integer
Dim N As Integer
Dim TempMax As Double, factor As Double
N = coeff-matrix.Rows.Count
ReDim X(N), AugMatrix(N, N + I), PivotRow(N), PivotLogical(N)
'Create augmented matrix (AIB) with dimensions N x (N+I)
For I = 1 To N
ForJ = 1 To N
AugMatrix(1, J) = coeff-matrix(1, J)
Next J, I
ForJ=l TON
AugMatrix(J, N + 1) = const-vector(J)
Next J
'Initialize pivot elements for each row
For J = 1 To N: PivotLogical(J) = False: Next