Page 234 - Excel for Scientists and Engineers: Numerical Methods
P. 234

CHAPTER 9       SYSTEMS OF SIMULTANEOUS EQUATIONS                    21 1




                   ' Normalize pivot row
                   ForJ = 1 To N + 1
                   TempMatrix(K, J) = AugMatrix(K, J) / pivot
                   Next J
                   ' Do the Gauss elimination.
                   For I  = 1 To N
                   If  I = K Then GoTo EndOfLoop2
                   For J = 1 To N + 1
                   TempMatrix(1, J) = AugMatrix(1, J) - AugMatrix(1, K) * TempMatrix(K, J)
                   Next J
                   EndOfLoop2: Next I
                   For I = 1 To N
                   ForJ = 1 To N + 1
                   AugMatrix(1, J) = TempMatrix(1, J)
                   Next J
                   Next I

                   Next K
                   End Sub
                        Figure 9-14.  VBA code for the SimultEqnNL function procedure.
                (folder 'Chapter 09 Simultaneous Equations', workbook 'NonLinNewton', module 'NewtonIterationlFunction')

                   As an example of the use of the SimultEqNL function, consider the following
                set of four equations:
                                         w3 + 2w2 + 3w + 4 =  12.828
                                              wx + XY + YZ = -3.919
                                             w2+2wx+x2=          1

                                              w + x + y - z = -3.663
                   The corresponding Excel formulas were entered in Ell:E14 of Figure 9-15,
                as follows:
                   =A1 1"3+2*A1 1 "2+3*A11+4

                   =A1 l*B11 +B1 I'CI  1 +C11 *D11
                   =A1 1 "2+2*A11 *B11 +B1 l"2

                   =A 1 1 +B 1 1  +C 1 1 -D 1 1
                   The constants were entered in cells F11 :F14 and trial values of the unknowns
                in cells A1 1 :D11.
   229   230   231   232   233   234   235   236   237   238   239