An Analysis of Solving Systems of Simultaneous Equations

November 25, 2009 – 7:36 am

SCHREINER COLLEGE

A THESIS

Submitted in Partial Fulfillment of the Requirements for the Degree of

BACHELOR of ARTS

An Analysis of Solving Systems of

Simultaneous Equations.

A Thesis

by

Blair Rene’ Armeau

Submitted to the Faculty of

Schreiner College

in partial fulfillment of the requirements for the degree of

Bachelor of Arts

May 1989

Subject: Mathematics


TABLE OF CONTENTS

INTRODUCTION. 3

GAUSSIAN ELIMINATION. 5

CRAMER’S RULE of DETERMINANTS. 12

JACOBI ITERATION METHOD. 19

ANALYSIS. 24

CONCLUSION. 27

BIBLIOGRAPHY. 30

APPENDIX A Hand Calculations for Gaussian Elimination. 32

APPENDIX B FORTRAN Program for solving Equations using Gaussian Elimination. 34

APPENDIX C Hand Calculations for Cramer’s Rule of Determinants39

APPENDIX D FORTRAN Program for Solving Equations using Cramer’s Rule of Determinants42

APPENDIX E Hand Calculations for Jacobi Iteration Method. 47

APPENDIX F FORTRAN Program for Solving Equations using Jacobi Iteration Method. 49

INTRODUCTION

          The methods of solving equations have existed since man first began banging rocks together and gathering them into piles which unknowingly resulted in the twinklings of insight which we, today, call Mathematics.  I suppose if the first cavemen had developed board games first, we would all be literate to a greater extent.  But, alas, nobody knows how, when, or why mathematics began; or who started it.  We only have vague ideas of where ideas originated.

          Number theory dates back to ancient Greece.  Pythagoras worked extensively in number theory, and by 200 B.C., Eratothanes had developed the same method by which modern computers determine which numbers are primes.  Around A.D. 250, Diophantus set up the Diophantine analysis which is still used to find integer solutions to systems of equations.  Modern number theory began with the systemization and contribution of Karl Gauss in the early 19th century.  Halfway around the world in what is today called Central America and Mexico, the Mayans had developed their own way of accounting for and counting numbers.  They used combinations of dots and bars as numerals.  The Egyptians, Greeks, and Romans used alphabetic base ten numbering systems with no zero.  Each uses a different method to describe the values that each symbol represents, whether we write 11 in base ten, 1011 in base two, XI in Roman numerals, or <Y in Babylonian, it is still the sum of five and six.  The point is that each system developed a way to find some unknown value that was needed.  Simply recording values does nothing more than painting graffiti on a brick wall.  Solving equations is of more importance and, therefore, is partly the reason this thesis is written.

          This thesis is an expository analysis of the methods of solving systems of simultaneous linear equations using Gaussian Elimination, Cramer’s Rule of Determinants, and the Jacobi Iteration Method.  Each of these methods will be defined and simplified, discussed and explained with the use of examples, examined and analyzed for computer specifications, programmed for a computer, and the programs executed.  Concluding the thesis, the results of each method will be compared and analyzed with certain conclusions drawn.  All programs are written in FORTRAN with a FORTRAN-77 compiler on an IBM-PC compatible computer with listings and sample executions.  All computer program output is placed in Appendices following the main body of the thesis.  All detailed solutions and long form of the equations for all methods are placed in Appendices at the end of the main body of the thesis.



GAUSSIAN ELIMINATION

          The problem of solving a system of linear equations Ax = B is central to the field of matrix computations.  This section focuses on the method of Gaussian Elimination with the algorithm of choice working best when matrices are square, dense, and unstructured (Golub, 1983).  Here, square means the same number of rows as there are columns, dense meaning few, if any, zero elements in the matrix, and unstructured meaning no obvious patterning of number placement or value similarity (i.e., negatives along the diagonal, or zeroes in all four corners).

          Of the three methods to be discussed, Gaussian Elimination is the first and easiest method to understand and implement.  By definition, it is a method for solving a system of linear equations involving transforming the system so that the last equation contains one variable, the next-to-last equation contains only two variables, and so on.  For example, to solve the system:

2x -  3y +  z =   5

6x +   y – 5z =  51

4x + 14y – 8z = 100,

eliminate the term with ‘x’ from the last two equations.  To do this, subtract twice the first equation from the last equation to obtain a new last equation, and three times the first equation from the second equation.  The system now looks like this:

2x – 3y +   z =  5

    10y -  8z = 36

    20y – 10z = 90.

          Now, to eliminate the term with ‘y’ from the last equation, subtract twice the second equation from the last equation.  Here is the new system:

2x -  3y +  z =  5

     10y – 8z = 36

           6z = 18.

          Solve the last equation for ‘z’ (solution: z = 3).  Then insert this value for ‘z’ into the second equation to solve for ‘y’ (solution: y = 6).  Finally, insert the values for ‘z’ and ‘y’ into the first equation to solve for ‘x’ ( solution: x = 10 ) (Douglas, 1987).

          Another way of describing this method is that this a process of reducing a matrix ‘A’, composed of the coefficients of a system of equations, to upper triangular.  The constant matrix ‘B’ is also manipulated at the same time with the coefficient matrix ‘A’ resulting with the last equation having usable values.  With this method, by testing only the last equation and solution, it is easy to see if there is a unique solution to the set of equations (xn = kn; where ‘xn‘ is the final equation and term, and ‘kn‘ is some constant), no solution to the set of equations (xn = 0 = kn; where ‘xn‘ is the final equation and term, and xn = 0 = kn for a result), or infinitely many solutions to the set of equations (xn = 0 = 0; where ‘n’ is the final equation and term).  If the reduction in the equation results in a legitimate answer, the answer is back-substituted into the other equations and a solution is found for the remaining unknowns.  (Same idea as above.) If, at any time, the crucial pivot point for reducing the matrix is found to be zero, the remaining columns and/or rows are interchanged to bring the largest coefficient remaining to the pivot point.  This helps in two ways: 1) it eliminates the zero pivot, assuming there is such a value, and 2) it helps reduce rounding error by putting the larger values back into key positions of the solution process.  Actually, the program in Appendix B automatically finds the largest value in each column below the diagonal to help reduce the errors produced from the computer’s own divisions.

          A similar process to Gaussian Elimination is the Gauss - Jordan Method of Elimination.  In this second method, the matrix is manipulated to the identity matrix resulting in a one-to-one correspondence between each element on the diagonal of the final solved coefficient matrix ‘A’ and that of the constant matrix ‘B’.  This is not as efficient for computer programming because it involves, as mentioned earlier, additional, unnecessary manipulation of the coefficient matrix ‘A’ into the identity matrix.  In both instances, the amount of work done to program a computer to solve the equations is easier, faster, and more accurate than doing each solution by hand.

          Any processing of the coefficient matrix ‘A’ is applied to the constant matrix ‘B’.  The use of this method also leads to the necessity of pivoting the rows or columns of the coefficient matrix ‘A’, either fully or partially, to move a more desirable pivot to the appropriate position on the diagonal.

          Interchanging columns requires keeping records of the swaps so the original matrix can be used to later print the solutions.  It would be rather useless to solve the set of equations and not know which answer belongs to which unknown.  This method has been replaced by the preferred, and simpler, Gaussian Elimination method which uses only row interchanges to perform the calculations leaving the unknowns in their original order.

          The Gaussian Elimination method only requires the partial interchanging of rows and uses back-substitution to solve the other unknowns.  The ability to swap rows and not having to worry about keeping track of columns, is the equivalent of writing the equations in a different order but keeping the order of the unknowns the same.  The comparison of the two methods graphically, assuming that column interchanges are needed in the Gauss-Jordan method, can be seen as follows:

Gauss-Jordan method Illustrated

Given:

            ╓─             ─╖ ╓─    ─╖   ╓─   ─╖

            ║ A11  A12  A13 ║ ║  X1  ║   ║  B1

            ║ A21  A22  A23 ║ ║  X2  ║ = ║  B2

            ║ A31  A32  A33 ║ ║  X3  ║   ║  B3

            ╙─             ─╜ ╙─    ─╜   ╙─   ─╜

then,

Column Interchange

╓─             ─╖   ╓─             ─╖   ╓─             ─╖

║ A11  A12  A13 ║   ║ A11  A12  A13 ║   ║ A11  A13  A12

║ A21  A22  A23 ║ = ║  0   A22  A23 ║ = ║  0   A23  A22 ║ =

║ A31  A32  A33 ║   ║  0   A32  A33 ║   ║  0   A33  A32

╙─             ─╜   ╙─             ─╜   ╙─             ─╜

╓─             ─╖   ╓─             ─╖   ╓─             ─╖

║ A11  A12  A13 ║   ║ A11  A12  A13 ║   ║ A11  A13  A12

║ A21  A22  A23 ║ = ║  0   A22  A23 ║ = ║  0   A23  A22 ║ =

║ A31  A32  A33 ║   ║  0   A32  A33 ║   ║  0   A33  A32

╙─             ─╜   ╙─             ─╜   ╙─             ─╜

                ╓─             ─╖   ╓─             ─╖  

                ║ A11   0   A12 ║   ║ A11   0    0  ║  

                ║  0   A23  A22 ║ = ║  0   A22  A23 ║ =

                ║  0    0   A32 ║   ║  0    0   A32 ║  

                ╙─             ─╜   ╙─             ─╜  

          ╓─             ─╖     ╓─  ─╖            

          ║ A11   0    0  ║     ║ B1 ║     A11 = B1

          ║  0   A23   0  ║  =  ║ B2 ║  =  A23 = B2

          ║  0    0   A32 ║     ║ B3 ║     A32 = B3

          ╙─             ─╜     ╙─  ─╜            

where ‘A’ stands for coefficient matrix ‘A’, ‘B’ stands for constant matrix ‘B’, the first number denotes row number, and the second number denotes column number.  This shows that column two and three have been interchanged but there are no row interchanges.  This is one reason for keeping track of the placement of the columns.  The solution looks like x3 = B3 when in actuality x2 = B3 and x3 = B2.  By not allowing column interchanges, we use the Gaussian Elimination method which follows.

Gaussian Elimination method Illustrated

Again, given:

            ╓─             ─╖ ╓─    ─╖   ╓─   ─╖

            ║ A11  A12  A13 ║ ║  X1  ║   ║  B1

            ║ A21  A22  A23 ║ ║  X2  ║ = ║  B2

            ║ A31  A32  A33 ║ ║  X3  ║   ║  B3

            ╙─             ─╜ ╙─    ─╜   ╙─   ─╜

The same equations become:

           ╓─             ─╖   ╓─             ─╖

           ║ A11  A12  A13 ║   ║ A11  A12  A13

           ║ A21  A22  A23 ║ = ║  0   A22  A23 ║ =

           ║ A31  A32  A33 ║   ║  0   A32  A33

           ╙─             ─╜   ╙─             ─╜

     ╓─             ─╖   ╓─  ─╖       

     ║ A11  A12  A13 ║   ║ B1 ║    A33 = B3

     ║  0   A22  A23 ║ = ║ B2 ║ => A22 = B2 – A33

     ║  0    0   A33 ║   ║ B3 ║    A11 = B1 – A22 – A33

     ╙─             ─╜   ╙─  ─╜

          Again, where ‘A’ stands for coefficient matrix ‘A’, ‘B’ stands for constant matrix ‘B’, the first number denotes row number, and the second number denotes column number.

          Obviously, the amount of matrix manipulations of the Gaussian Elimination method is about half that of the Gauss-Jordan method.  A specific example of a three by three matrix is sufficient to demonstrate the process of the Gaussian Elimination method. 

  The original equations            The coefficient

    as normally viewed:          matrix augmented with

                                  the solution matrix:

      the equations              matrix A and matrix B

                           ╓─         ─╖ ╓─  ─╖   ╓─   ─╖

   X1 +  X2 +  X3 =  2     ║  1  1  1  ║ ║ X1 ║   ║  2  ║

   X1 -  X2 -  X3 =  2 ==> ║  1 -1 -1  ║ ║ X2 ║ = ║  2  ║

      -  X2 + 2X3 = -3     ║  0 -1  2  ║ ║ X3 ║   ║ -3  ║

                           ╙─         ─╜ ╙─  ─╜   ╙─   ─╜

therefore using the method defined above,  X3 = -1.

Back-substituting, we find:  X2 = 1 and X1 = 2.

The complete hand calculations appear in Appendix A.

          This approach is relatively straightforward and easy to program.  The program obviously needs the following major sections to operate efficiently:

          1) an input routine to get the matrix into the computer,

          2) a routine to section off a portion of the matrix for simplification,

          3) a routine to swap rows, which incorporates:

a) a routine to determine the largest coefficient in a particular column of the matrix and store that row number,

b) a routine to actually swap rows of a matrix,

          4) a routine to determine the multiplication factor based on the pivot value (used to reduce the diagonal to one),

          5) a routine to back-substitute, and

          6) a routine to print the results.

          The program, sample runs, and data follow in Appendix B.



CRAMER’S RULE of DETERMINANTS

          Cramer’s Rule of Determinants is the next method of the three for solving equations and is , indeed, significantly different than the previous method.  Cramer’s rule is a method for solving a set of simultaneous linear equations using determinants.  For the ’3 by 3′ system below:

                               matrix A          matrix B

                             ╓─        ─╖ ╓─  ─╖   ╓─  ─╖

a1x1 + a2x2 + a3x3 = k1      ║ a1 a2 a3 ║ ║ x1 ║   ║ k1

b1x1 + b2x2 + b3x3 = k2  =>  ║ b1 b2 b3 ║ ║ x2 ║ = ║ k2

c1x1 + c2x2 + c3x3 = k3      ║ c1 c2 c3 ║ ║ x3 ║   ║ k3

                             ╙─        ─╜ ╙─  ─╜   ╙─  ─╜.

          Where a, b, and c are coefficients of the equations and k is the constants to the equations

The rule states:

                       │ k1 a2 a3 │  

                       │ k2 b2 b3 │  

                       │ k3 c2 c3 │  

             x1 =     ──────────────

                       │ a1 a2 a3 │  

                       │ b1 b2 b3 │  

                       │ c1 c2 c3 │  

                            │ a1 k1 a3 │  

                            │ b1 k2 b3 │  

                            │ c1 k3 c3 │  

                  x2 =     ──────────────

                            │ a1 a2 a3 │   

                            │ b1 b2 b3 │  

                            │ c1 c2 c3 │  

and,

                            │ a1 a2 k1 │  

                            │ b1 b2 k2 │  

                            │ c1 c2 k3 │  

                  x3 =     ──────────────

                            │ a1 a2 a3 │  

                            │ b1 b2 b3 │  

                            │ c1 c2 c3 │  .

          In this case the determinant of a matrix is written in standard form with vertical lines outside the matrix.

          To use Cramer’s rule, first calculate the determinant of the matrix of coefficients (matrix ‘A’).  This determinant appears in the denominator of the solutions for each variable.  To calculate the numerator for any variable, set up the same matrix but make one substitution: cross out the column that contains the coefficients of that variable and replace that column with the column of constants (matrix ‘B’) from the other side of the equal sign.

          There is one obvious drawback.  In order to use the rule to solve any system of ‘n’ equations with ‘n’ unknowns, there will have to be ‘n + 1′ determinants of dimension ‘n by n’ calculated.  This procedure could get tedious and more error prone, but it is the kind of repetitive, accurate calculation that is well suited to be performed by a computer.

          In other words, this is a method of solving a series of simultaneous equations by substituting one column of the coefficient matrix, composed from the coefficients of the set of equations, with the solution matrix (also, ’1 by n’ in size).  By calculating the determinant of the new matrix and dividing by the determinant of the original coefficient matrix, the result is the exact solution for that particular unknown associated with the specific column substituted.  Repeating this method for all the columns results in the solving of all the unknowns for the given set of equations.

          An advantage is if only one unknown is needed, only that unknown needes to be solved and can be solved independently of the others.

          The major problem associated with this method occurs when the determinant of the original coefficient matrix is zero.  It is commonly known in mathematics that zero cannot be used as a divisor; thus, this method fails completely.  Fortunately, this downfall is easy to check and avoid.  In the case of linear dependency, the determinant of any square matrix is zero. 

          Upon calculation of the determinant of the coefficient matrix ‘A’, and finding the determinant of that matrix not equal to zero, the equations have either a unique solution or infinitely many solutions.  If the new determinant is zero, the system of equations has either no solution or infinitely many solutions, and the solution fails.  This is explained in two cases: by the zero divided by a constant case, and a zero divided by zero case.

          In this situation, if any numerator is zero, the result is no solution to the equations.  If all the numerators are zero, the result is infinitely many solutions.

          Equations with two variables accurately describe lines.  Using two, two variable equations, we can visualize how the lines interact to give either a unique solution, no solution, or infinitely many solutions.  When two lines touch at one point, that point is the point that is common to both lines and, therefore, the unique solution that solves both equations.  When there are two independent parallel lines, the lines do not touch at any point and the equations have no solution.  If the lines are actually one and the same, and the two lines would graph upon one another, there are actually infinitely many solutions

that satisfy both equations.

          With three, three variable equations, the equations represent planes that may intersect, from the fact that three non-colinear points determine a plane.  There is no simple graphic or logical description of a four, or more, variable equation, except that a four-variable equation, with the points non-coplaner, represent some space.  To almost everyone, it is very difficult to visualize having two spaces intersect at a plane, or having two four dimensional spaces intersect at a three dimensional space.

          The solution is shown easily in the solving of a three by three matrix equation:

    original equations         Matrix A              Matrix B

                            ╓─           ─╖ ╓   ─╖   ╓─    ─╖

    X1 – X2 + 2X3 = -3      ║  1  -1   2  ║ ║ X1 ║   ║  -3  ║

         X2 +  X3 = -1  =>  ║  0   1   1  ║ ║ X2 ║ = ║  -1  ║

     X1     +  X3 =  0      ║  1   0   1  ║ ║ X3 ║   ║   0  ║

                            ╙─           ─╜ ╙─  ─╜   ╙─    ─╜

          First, find the determinant of the coefficient equation.  This can easily be done by reducing a large matrix into its minors and complements or cofactors.   Using this method, we can find the determinant of the original equation.   Expanding the following matrix into its minors and cofactors allows the reduction of the determinant of a large matrix into many small, and more manageable determinants.

          The determinant expanded about a1, b1, and c1:

      │ a1 b1 c1

      │ a2 b2 c2 │ becomes    

      │ a3 b3 c3 │     

   │ b2 c2 │      │ a2 c2 │     │ a2 b2

a1 │ b3 c3 │ – b1 │ a3 c3 │ + c1│ a3 b3 │.

          Therefore the equations we want to solve become:

         │  1  -1   2  │  

 det (A) =  │  0   1   1  │  =

         │  1   0   1  │  

       │ 1 1 │              │ 0 1 │             │ 0 1 │

(-1)1+1│ 0 1 │ + (-1)1+2(-1)│ 1 0 │ + (-1)1+3(2)│ 1 0 │ =

         │ 1 1 │             │ 0 1 │            │ 0 1 │

(-1)2(1) │ 0 1 │ + (-1)3(-1) │ 1 0 │ + (-1)4(2) │ 1 0 │ =

               │ 1 1 │   │ 0 1 │    │ 0 1 │

            =  │ 0 1 │ + │ 1 0 │ + 2│ 1 0 │ =

(1(1) – 0(1)) + (0(0) – 1(1)) + 2 (0(0) – 1(1)) =

(1 – 0) + (0 – 1) + 2(0 – 1) = 1 – 1 – 2 = -2

therefore, the det(A) = -2

          Using the same method, the determinant of the original matrix with the substitution of matrix ‘B’ into the first column to find the first unknown:

                            │ -3  -1   2  │

                det (A1) =  │ -1   1   1  │  =  -4

                            │  0   0   1  │

          Next, find the determinant of the original matrix with the substitution of matrix ‘B’ into the second column to find the second unknown:

                            │  1  -3   2  │      

                det (A2) =  │  0  -1   1  │  =  -2

                            │  1   0   1  │      

          Again, modify the determinant of the original matrix with the substitution of matrix ‘B’ into the third column to solve for the third unknown:

                             │  1  -1  -3 │     

                 det (A3) =  │  0   1  -1 │  =  4

                             │  1   0   0 │     

          Applying the previous determinants to solve the equations with Cramer’s method, we find:

      det (A1)   -4                   det (A2)   -2

X1 =  ─────── = ──── =  2,      X2 =  ─────── = ──── =  1,

      det (A)    -2                   det (A)    -2

                   det (A3)    4

       and   X3 =  ─────── = ──── = -2

                   det (A)    -2

          The complete hand calculations for this problem are found in Appendix C. 

          Another way to find the determinant of a matrix is to first make the matrix upper triangular as with Gaussian Elimination.  Then, the determinant is calculated by multiplying the values along the diagonal.  The same work is done using this method as was done using Gaussian Elimination, although the application of the result is different.  To save time programming, only the section which reduces the matrix to upper triangular will be used for finding the determinants in Cramer’s Rule.

          The program obviously needs the following major sections to operate efficiently and some of the requirements are the same as with the Gaussian Elimination method:

          1) an input routine to get the matrix into the computer,

          2) a method to construct the determinant matrices,

          3) a method to calculate the determinant,

          4) a method to calculate the solutions,

          5) a routine to print the results.

          The program, sample runs, and data follow in Appendix D.



JACOBI ITERATION METHOD

          The Jacobi Iteration Method is the third and final method of solving a set of simultaneous linear equations discussed in this thesis.  This method is commonly referred to as the method of relaxation.  Basically, any method that finds an approximation based on a previous calculation can be classified as an iteration or a relaxation method.  Here, the approximations will be the actual answers for a set of equations.  Using this method, all variables are initially set to some arbitrary constant, ‘c’.  The equations are calculated with these constants in place, and as a result, some variables change their values away from that constant toward those of the actual solution for that unknown.  These newly calculated values for the variables are reinserted into the equations and the iteration continues until, with enough iterations, all unknowns are solved to within a preset degree of accuracy.  Assuming that the equations are not ill-conditioned, diverging, and  do not have large oscillating results at the onset of the solutions, the values in the variables will approach the solution of the set of equations.  When either a predetermined precision is achieved or the number of iterations is reached, the iteration stops.

          In order to construct a problem of this nature, a representation of the equations in standard form will be easier than that of the matrix method to understand.  This method takes more thinking and creativity to set up the equations than with the other methods and, therefore, will be represented as such a manner as to logically generate a set of equations.

          The equations must be interrelated more than with the previous methods, and as such, almost require the use of a situation to demonstrate.  In other words, not every set of equations will converge to an answer.  The equations to be discussed will be constructed from the following diagram.

                          North = 0

                  ╔══════════════════════╗

                  ║╔══════╤══════╤══════╗║

                  ║║      │      │      ║║

                  ║║      │      │      ║║

                  ║╟─────P 1────P 2─────╢║

                  ║║      │      │      ║║

         West = 0 ║║      │      │      ║║ East = 0

                  ║╟─────P 3────P 4─────╢║

                  ║║      │      │      ║║

                  ║║      │      │      ║║

                  ║╙──────┴──────┴──────╜║

                  ╙─────────   ──────────╜

                      South = 1 = exit

          For example, imagine a person starting from any intersection in the square who can only ‘escape’ by emerging from the south edge, represented in this example by one.  Emerging from the  north, west, or east side is the same as not ‘escaping’, represented by zero.  Assume the chances of going in any direction from any intersection are all equally likely.  Thus, the resulting description of position one is:

P1 = 1/4 0 + 1/4 0 + 1/4 P2 + 1/4 P3

or, more commonly,

P1 = 1/4 (0 + 0 + P2 + P3)

or possible escape routes are P2 and P3 of which each is 1/4 likely to happen.  In other words, the only way a person at P1 can ‘escape’ is if he travels in the direction of P2 or P3, and each of those is equally likely.  Other escapes are similarly defined as:

P2 = 1/4 (P1 + 0 + 0 + P4)

P3 = 1/4 (0 + P1 + P4 + 1)

P4 = 1/4 (P3 + P2 + 0 + 1)

          The only way to escape from P1 is to correctly travel through P2, P3, or P4 and only emerging from the south side.  By looking at the diagram, it should be easier to escape from P3 and P4 than from P1 or P2.  Here, all the positions are given some arbitrarily chosen constant (say, zero) and calculated with that value.

Recall:Iteration 0

P1 = 0

P2 = 0

P3 = 0

P4 = 0

Iteration 1

      the equations           insert current values  result

P1 = 1/4 (0 + 0 + P2 + P3) =  .25 (0 + 0 + 0 + 0)   = .000

P2 = 1/4 (P1 + 0 + 0 + P4) =  .25 (0 + 0 + 0 + 0)   = .000

P3 = 1/4 (0 + P1 + P4 + 1) =  .25 (0 + 0 + 0 + 1)   = .250

P4 = 1/4 (P3 + P2 + 0 + 1) =  .25 (.25 + 0 + 0 + 1) = .313

          The only values that changed are P3 and P4 caused by the one in the original equations.  Those values are inserted and recalculated to get new results.

Iteration 2

  again, the equations          the latest values    result

P1 = 1/4 (0 + 0 + P2 + P3) = .25(0 + 0 + 0 + .25)     =.063

P2 = 1/4 (P1 + 0 + 0 + P4) = .25(.063 + 0 + 0 + .313) =.094

P3 = 1/4 (0 + P1 + P4 + 1) = .25(0 + .063 + .313 + 1) =.344

P4 = 1/4 (P3 + P2 + 0 + 1) = .25(.344 + .094 + 0 + 1) =.360

and again,

Iteration 3

P1 = .25 (0 + 0 + .094 + .344)  = .110

P2 = .25 (.110 + 0 + 0 + .360)  = .117

P3 = .25 (0 + .110 + .360 + 1)  = .368

P4 = .25 (.368 + .117 + 0 + 1)  = .370

and so on.  After about eight iterations, P1 and P2 converge to .125, while P3 and P4 converge to .375.  The entire work and calculations are in Appendix E.

          Going back to matrices, rewriting the equations in standard form of Ax = B results in the transformation as follows:

P1 = 1/4 (0 + 0 + P2 + P3) => 4P1 = P2 + P3 + 0 + 0

and similarly for the other equations:

                                  P2 = P1 + P4 + 0 + 0

                                4P3 = P1 + P4 + 0 + 1

                                4P4 = P2 + P3 + 0 + 1

and thus,

                 4P1 -  P2 -  P3 +   0 =  0

                            P1 – 4P2 +   0 +  P4 =  0

                            P1 +   0 – 4P3 +  P4 = -1

                             0 +  P2 +  P3 – 4P4 = -1

                     ╓─            ─╖ ╓── ─╖   ╓─  ─╖

therefore,           ║  4 -1 -1  0  ║ ║ P1 ║   ║  0 ║

                     ║  1 -4  0  1  ║ ║ P2 ║   ║  0 ║

                     ║  1  0 -4  1  ║ ║ P3 ║ = ║ -1 ║

                     ║  0  1  1 -4  ║ ║ P4 ║   ║ -1 ║

                     ╙─            ─╜ ╙─  ─╜   ╙─  ─╜

          This approach takes some care and forethought to program but the method of repetitive calculations is ideally suited for a personal computer which can perform the calculations quickly and accurately enough to acquire adequate solutions.

          The program obviously needs the following major sections to operate efficiently and some of the requirements are the same as with the previous methods:

          1) an input routine to get the matrix into the computer,

          2) a method to cycle through as many iterations as necessary to achieve

                    a) absolute value of the current accuracy

                    b) maximum iterations allowed

          3) a method to calculate the iteration,

          4) a routine to print the results.

          The program, sample runs, and data follow in Appendix F.



ANALYSIS

          With Gaussian Elimination, Cramer’s Rule of Determinants, and the Jacobi Iteration Method described, we are able to compare the results and the programs for each of the three methods. The program lengths are all within a page of each other with the greatest difference being 2254 bytes between Gaussian Elimination and Jacobi Iteration.  This is a result of the additional programming required for back-substituting and more detailed error checking in the Gaussian Elimination method.

          All the programs incorporate the same basic sections of Main, Heading, Input Matrix, Calaculate, and Print Result; and each section, with the obvious exception of Calculation, is written about the same.  The only difference is that Cramer’s Rule of Determiants uses an additional subroutine named Determinant which calculates the determinant of a matrix passed to it as an argument. The calculation of the determinant is accomplished by using

a modified version of Gaussian Elimination.  Here the determinant of a matrix is calculated by mainipulating the matrix the same as with Gaussian Elimination and reducing the matrix to upper triangular.  The determinant is calculated by multiplying the elements along the diagonal.

          The Calculate section of the Jacobi Iteration Method is smaller and more direct than the other two methods discussed. This section is almost one and one-half pages shorter than both the Gaussian Elimination Calculate section, and the Cramer’s Rule Calculate and Determinant sections.

          The equations used for testing the programs needed to work in all the programs.  The Jacobian Iteration Method would not calculate the solutions of either the Gaussian Elimination or the Cramer’s Rule equations.  As a result, all three programs were executed with the Jacobi Iteration Equations.  Each program was executed with the examples previously worked by hand.  Because all the programs executed perfectly, they were excluded from the Appendix.  The first execution is with the matrix:

                  matrix A             matrix B

              ╓─            ─╖ ╓── ─╖   ╓─  ─╖

              ║  4 -1 -1  0  ║ ║ X1 ║   ║  0 ║

              ║  1 -4  0  1  ║ ║ X2 ║   ║  0 ║

              ║  1  0 -4  1  ║ ║ X3 ║ = ║ -1 ║

              ║  0  1  1 -4  ║ ║ X4 ║   ║ -1 ║

              ╙─            ─╜ ╙─  ─╜   ╙─  ─╜

          The second execution wses a similar matrix from BASIC Matrix Methods:

                  matrix A               matrix B

            ╓─               ─╖ ╓─  ─╖    ╓   ─╖

            ║ -30   1   1   1 ║ ║ X1 ║    ║ -30 ║

            ║   1 -30   1   1 ║ ║ X2 ║    ║   0 ║

            ║   1   1 -30   1 ║ ║ X3 ║  = ║ -30 ║

            ║   1   1   1 -30 ║ ║ X4 ║    ║   0 ║

            ╙─               ─╜ ╙─  ─╜    ╙─   ─╜

          The calculated answers to this matrix are X1 = 1.0389, X2 = .0711, X3 = 1.0389, and X4 = .0711 (Butterworths, 1984).

          The calculations are done in double precision in order to generate enough decimals for comparison. The only descrepancy found is ± 1 in the sixteenth decimal position of Gaussian Elimination.  This is caused by the failure of the computer to accurately store decimals of more than 15 digits.  The others are all equivalent to the last computed decimal.  Even though having an error within 10-15 may not be remarkable for a computer, using the computer is indeed more precise than doing the calculations by hand.

          With this analysis of three different methods for solving simultaneous equations, it can be seen that all three methods can acheive a great deal of precision using the given matrices.  A problem occurs with the Jacobi Iteration with ill-conditioned matrices and those matrices which do not converge fast enough to find a solution. Other methods such as Gaussian Elimination or Cramer’s Rule of Determinants can be used in these instances.



CONCLUSION

          What lies before were three different analyses for Solving Systems of Simultaneous Equations using Gaussian Elimination, Cramer’s Rule of Determinants, and the Jacobi Iteration Method.  Each method is distinctly different but ends with the same results.

          Gaussian Elimination reduces a matrix to upper triangular through a series of multiplications, divisions, and subtractions.  The final equation is checked, and if the results are usable and meaningful, the solution is back-substituted into previous equations solving for each unknown along the way.

          Cramer’s Rule of Determinants finds the Determinant for the coefficient matrix and uses this as the divisor for modified matrices.  The modified matrices are constructed from the original matrix with the constant matrix replacing the column associated with the unknown being solved.          Jacobi Iteration Method uses previous calculations to find actual solutions of the set of equations which are either very large or are unable to be solved easily by another method.

          For regular small matrices, Gaussian Elimination and Cramer’s Rule are more direct, quicker methods.  When Gaussian Elimination is used on matrices that are very large (greater than one-hundred equations with one-hundred unknowns), the accuracy is limited by the amount of precision carried throughout the solution process.  The more precision there is, frequently the more accurate the answer is.  Problems arise when the storage of decimals is beyond the storage capacity of a computer’s memory.  Having matrices with extremely positive values or extremely negative values results in the same problem.

          Cramer’s Rule of Determinants is a method of solving simultaneous equations through determinants.  The determinants can become rather difficult to calculate by hand once the matrices get to be large, as with Gaussian Elimination, but this is simply warm up exercise for a computer.  Other methods can be applied to finding the determinant in easier or faster ways, but this still would include calculating ‘n + 1′ determinants and substituting columns as needed to find the unknowns.

          Jacobi Iteration is the best choice for calculating matrices that would be a burden for either Gaussian Elimination or Cramer’s Rule.  An initial guess far from the solution may take a few more iterations to approach the actual solution than a guess that was relatively close to the actual solution.  Solving for all the unknowns at the same time theoretically reduces the error that would normally accumulate if Gaussian Elimination would have been used.  The only condition that is required is that the set of equations must converge to a solution.  If not, the iterations would continue to diverge away from the actual solution.

          Gaussian Elimination, Cramer’s Rule of Determinants, and Jacobi Iteration Method are effective and different methods to determine the solutions of simultaneous equations.  Gaussian Elimination calculates the solutions by old fashioned number crunching and the use of the strong arm, weak mind method of solving equations.  When calculating a very large matrix, only the hardy should attempt this method by hand.  Cramer’s Use of Determinants uses a method that is ingenious by calculating determinants of various forms of the original equations.  This method is designed  for those people who like to do the same thing repeatedly and accurately.  Jacobi Iteration Method should be performed by those who do not like to work with algebra and would like to sit and use a relaxation method to solve their problems.

          Looking into our own prehistoric history, whatever method is applicable in other civilized sections of our Galaxy, the undeveloped sections need to remember to “bang the rocks together” (Adams, 1987).



BIBLIOGRAPHY

Adams, Douglas. The Hitchhiker’s Guide to the GalaxyConnecticut: Longmeadow Press, 1987.

Ambrose, William G.  College Algebra New York: Macmillan Publishing Co. , 1976.

Ayres, Frank. Matrices New York: McGraw-Hill Book Company, 1962.

Cheney, Ward; Kincaid, David. Numerical Mathematics and Computing Monterey: Brooks/Cole PublishingCompany, 1980.

Cole, J.W. Perry ANSI Fortran IV with Fortran-77 Extentions a structured programming approach Iowa: Wm. C. Brown Company Publishers, 1978.

Dahlquist, Germund.  Numerical methods New Jersey: Prentice Hall Inc., 1974.

Downing, Douglas. Dictionary of Mathematical Terms, New York: Barron’s Educational Series. Inc., 1987.

Handscomb, D.  C.  Methods of Numerical Approximation Oxford: Pergamon Press Ltd. , 1966.

Hart, William L. College Algebra Boston: D.C. Heath and Company, 1938.

Mason, J. C.  BASIC Matrix Methods, including approximation and data fitting London: Butterworth & Co. Ltd., 1984.

McKeown, Patrick G. Structured Programming Using Fortran 77, San Diego: Harcourt Brace Jovanovich Inc., 1985.

Miller, Allen R.  BASIC Programs for Scientists and Engineers California: Sybex Inc., 1981.

Ortega, J.  M. ; Rheinboldt, W.  C.  Iterative Solution of Nonlinear Equations in Several Variables California: Academic Press, 1970.

Press, William H.; Flannery, Brian P.; Teukolsky, Saul A.; Vetterling, William T.  Numerical Recipes the Art of Scientific Computing New York: Cambridge University Press, 1986.

Scheid, Francis, Numerical Analysis New York: McGraw-Hill Book Co., 1968.

Stein, Sherman K.  Calculus and Analytic Geometry New York: McGraw-Hill, Inc., 1973.

Strang, Gilbert.  Linear Algebra and Its Applications, Florida: Academic Press, 1980.

The Universal Illustrated Encyclopedia New York: Banner Press, 1978.

Uspensky, J. V.  Theory of Equations New York: McGraw-Hill Book Co., 1948.

Golub, Gene H.; Van Loan, Charles F. Matrix Computations, Maryland: The John Hopkins University Press, 1983.



APPENDIX A
Hand Calculations for Gaussian Elimination

  The original equations            The coefficient

    as normally viewed:          matrix augmented with

                                  the solution matrix:

      the equations              matrix A and matrix B

                           ╓─         ─╖ ╓─  ─╖   ╓─   ─╖

   X1 +  X2 +  X3 =  2     ║  1  1  1  ║ ║ X1 ║   ║  2  ║

   X1 -  X2 -  X3 =  2 ==> ║  1 -1 -1  ║ ║ X2 ║ = ║  2  ║

      -  X2 + 2X3 = -3     ║  0 -1  2  ║ ║ X3 ║   ║ -3  ║

                           ╙─         ─╜ ╙─  ─╜   ╙─   ─╜

   ╓─         ─╖   ╓─   ─╖      ╓          ─╖   ╓─   ─╖

   ║  1  1  1  ║   ║  2  ║      ║  1  1  1  ║   ║  2  ║

   ║  1 -1 -1  ║ = ║  2  ║  =>  ║  0 -2 -2  ║ = ║  0  ║ =>

   ║  0 -1  2  ║   ║ -3  ║      ║  0 -1  2  ║   ║ -3  ║

   ╙─          ╜   ╙─   ─╜      ╙─          ╜   ╙─   ─╜

          section removed

        for simplification

        ╓─     ─╖   ╓─  ─╖    ╓─     ─╖   ╓─  ─╖   

        ║ -2 -2 ║   ║  0 ║    ║ -2 -2 ║   ║  0 ║   

        ║ -1  2 ║ = ║ -3 ║ => ║ -1  2 ║ = ║ -3 ║ =>

        ╙─     ─╜   ╙─  ─╜    ╙─     ─╜   ╙─  ─╜   

                          section removed

                        for simplification

        ╓─     ─╖   ╓─ ─╖    ╓─       ─╖   ╓─ ─╖   

        ║ -1 -1 ║   ║ 0 ║    ║  -1 -1  ║   ║ 0 ║   

        ║ -1  2 ║ = ║ 3 ║ => ║   0  3  ║ = ║-3 ║ =>

        ╙─     ─╜   ╙─ ─╜    ╙─       ╜   ╙─ ─╜   

           ╓─  ─╖   ╓─  ─╖    ╓─ ─╖   ╓─  ─╖    

           ║  3 ║ = ║ -3 ║ => ║ 1 ║ = ║ -1 ║ = -1

           ╙─  ─╜   ╙─  ─╜    ╙─ ─╜   ╙─  ─╜    

therefore, X3 = -1.

Back-substituting, we find:     -X2 + 2(-1) = -3

                                    -X2 – 2 = -3

                                        -X2 = -1

                                         X2 =  1

and thus,                     X1 + 1 + (-1) =  2

                                 X1 + 1 – 1 =  2

                                         X1 =  2

or X3 = -1, X2 = 1, and X1 = 2.



APPENDIX B
FORTRAN Program for solving Equations using Gaussian Elimination

        PROGRAM Gaussian Elimination

C Program Name: GAUSSIAN.FOR

C Author: Blair Rene’ Armeau

C Regarding: Senior Thesis for Bachelor of Arts in Mathematics

C Problem:  This program uses the method of Gaussian Elimination

C             to solve and print the solutions to a set of equations C          as selected by the user.  If there is no solution the

C             program will print out why the equations cannot be solved.

C Section Description

C      MAIN     the main program which calls major sub-programs

C       HEADING         a sub-program to print the heading

C      INPUT MATRIX   a sub-program to input the matrices to calculate

C       CALCULATE       a sub-program to calculate the solutions

C      PRINT RESULT   a sub-program to print the solutions

C Variable Definitions

C      flag     an error flag set during calculations

C      matrix a         the coefficient matrix that will be manipulated

C      matrix b         the constant matrix

C      matrix c         the resulting solution matrix

C      max              the maximum number of equations to be solved C       min              the minimum number of equations to be solved C       ncols    the number of columns used in the array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved) C       save a   a copy of the original matrix as entered C       save b   a copy of the original matrix as entered

C **********************

C MAIN

        PARAMETER (max = 10, min = 2)

        DOUBLE PRECISION matrix a(max,max), matrix b(max), matrix c(max)

        DOUBLE PRECISION save a(max,max), save b(max)

        INTEGER nrows, ncols, flag

        CALL HEADING(max, min)

        CALL INPUT MATRIX (matrix a, matrix b, max, min,

       +    nrows, ncols, save a, save b)

        CALL CALCULATE (matrix a, matrix b, matrix c, max,

       +    nrows, ncols, flag)

        CALL PRINT RESULT( save a, save b, matrix c, max,

       +    nrows, ncols, flag)

        END

C **********************

        SUBROUTINE HEADING(max, min)

C Variable Definitions

C      max              the maximum number of equations to be solved C       min              the minimum number of equations to be solved

        INTEGER max, min

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ Program Name: GAUSS.FOR ‘

        PRINT’(15X,A)’,” Author: Blair Rene’ Armeau “

        PRINT’(15X,A)’,’ Regarding: Senior Thesis for Bachelor of Arts ‘

        PRINT’(15X,A)’,’ Problem: This program uses the method of ‘

        PRINT’(15X,A)’,’       Gaussian Elimination to solve a set ‘

        PRINT’(15X,A)’,’       of equations.’

        PRINT’(15X,A)’,’ This program uses the method of Gaussian ‘

        PRINT’(15X,A)’,’ Elimination to solve and print the solutions’

        PRINT’(15X,A)’,’ to a set of equations as selected by the user. ‘

        PRINT’(15X,A)’,’ If there is no solution to the equations, the ‘

        PRINT’(15X,A)’,’ program will print why the equations cannot ‘

        PRINT’(15X,A)’,’ be solved.’

        PRINT’(15X,A,I2)’,’ The program is set up for a ‘,max

        PRINT’(15X,A,I2,A)’,’ by ‘,max,’ coefficient matrix A and a 1 by’

        PRINT’(15X,A,I2,A)’, ‘ ‘,max,’ solution matrix B.’

        PRINT’(15X,A)’,’ The program will only alow a minimum of ‘

        PRINT’(15X,A,I2,A)’, ‘ ‘,min,’ equations to solve per execution.’

        END

C **********************

        SUBROUTINE INPUT MATRIX (a, b, max, min, nrows,

       +    ncols, save a, save b)

C Variable Definitions

C      a               the coefficient matrix that will be manipulated

C      b               the solution matrix

C      i               a loop counter C      j               a loop counter C      max     the maximum number of equations to be solved C   min       the minimum number of equations to be solved C   ncols     the number of columns used in the array

C      nrows   the number of used rows in the array

C                             (also, the number of equations to be solved)

C      save a         a copy of the original matrix as entered C     save b   a copy of the original matrix as entered

        INTEGER max, min, nrows, ncols, i, j

        DOUBLE PRECISION a(max,max), b(max), save a(max,max), save b(max)

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ What is the number of equations ‘

        PRINT’(15X,2(A,I2),A)’,’ to be solved. (‘,min,’ to’,max,’ only)>’

        READ *,nrows

10     IF (( nrows .GT. max ).OR.( nrows .LT. min)) THEN

            PRINT’(15X,A)’,’ Invalid Input. Try again.’

            PRINT’(15X,A)’,’ What is the number of equations ‘

            PRINT’(15X,A)’,’ to be solved. ‘

            PRINT’(15X,2(A,I2),A)’,'     (‘,min,’ to ‘,max,’ only ) >’

            READ *,nrows

            GOTO 10

        END IF

        PRINT’(15X,A)’,’ Please enter the coefficient matrix “A” one’

        PRINT’(15X,A)’,’ matrix element at a time.  The values are to’

        PRINT’(15X,A)’,’ be entered row by row.’

        ncols = nrows

        DO 100 i = 1, nrows

            DO 150 j = 1, ncols

                  PRINT’(15X,2(A,I2),A)’,’ Enter coefficient matrix a(‘,

       +                i,’,',j,’) >’

                  READ *,a(i,j)

150       CONTINUE

100   CONTINUE

        PRINT’(A)’,’1′

        DO 200 i = 1, nrows

            PRINT’(15X,A,I2,A)’,’ Enter solution matrix b(‘,i,’) >’

            READ *,b(i)

200   CONTINUE

C      copy all values to a safe place for later

        DO 300 i = 1, nrows

            DO 400 j = 1, ncols

                  save a(i,j) = a(i,j)

400       CONTINUE

            save b(i) = b(i)

300   CONTINUE

        END

C **********************

        SUBROUTINE CALCULATE (a, b, c, max, nrows, ncols, flag)

C Variable Definitions

C      a          the coefficient matrix that will be manipulated

C      accum     an accumulator for back-substituting

C      b          the constant and solution matrix

C       biggest   the biggest value below the diagonal

C      c          the resulting constant matrix for the solution

C      flag      an error flag set during calculations

C       i,j,k,l   4 loop counters

C      max        the maximum number of equations to be solved C       multiplr  the multiplier for reducing the matrix

C      ncols     the number of columns used in the array

C      nrows     the number of used rows in the array

C                       (also, the number of equations to be solved) C       temp      a temporary storage place

        INTEGER max, nrows, ncols, row, flag

        DOUBLE PRECISION a( max, max), b(max), c(max)

        DOUBLE PRECISION biggest, temp, multplr, accum

        INTEGER i, j, k, l

        flag = 0

C      find biggest value in ‘i’th column below diagonal

C      start at the diagonal

        DO 50 i = 1, nrows-1

            biggest = abs( a(i,i))

            row = i

C          go from below the diagonal through all the equations

            DO 100 k = i + 1, nrows

                  IF (abs( a(k,i)) .GT. biggest) then

                        biggest = abs(a(k,i))

                        row = k

                  END IF

100       CONTINUE

C          if the biggest value is zero, there is a zero pivot point,

C                 discontinue calculations, and jump-exit from subroutine

            IF (biggest .EQ. 0) THEN

                  PRINT’(A)’,’1′

                  PRINT’(15X,A)’,’ ERROR – THE MATRIX IS SINGULAR’

                  PRINT’(15X,A)’,’ A zero pivot has been encountered’

                  PRINT’(15X,A)’,’ upon solving the matrix.  Unable to’

                  PRINT’(15X,A)’,’ continue. Column transposes may be’

                  PRINT’(15X,A)’,’ possible. Check the equations and’

                  PRINT’(15X,A)’,’ try again.’

                  flag = 1

                  GOTO 999

            END IF

C          swap ‘row’ with ‘i’th row as long as ‘row’ C               and ‘i’th row are not the same

            IF (i .NE. row) then

                  DO 200 j = 1, ncols

                        temp =  a(row,j)

                        a(row,j) =  a(i,j)

                        a(i,j) = temp

200        CONTINUE

C                swap ‘row’ with ith row in matrix b

                  temp =  b(row)

                  b(row) =  b(i)

                  b(i) = temp

            END IF

C       multiply and reduce through rest of matrix below diagonal

            DO 300 k = i + 1, nrows

                  multplr =  a(k,i)/ a(i,i)

                  DO 400 l = i , ncols

                        a(k,l) =  a(k,l) – multplr* a(i,l) 400        CONTINUE

                  b(k) =  b(k) – multplr* b(i)

300       CONTINUE

C      check if a zero pivot has occured, there is an error. determine error, C          print error, discontinue calculations, and jump-exit from loop.

        IF (a(nrows,ncols) .EQ. 0) THEN

            PRINT’(A)’,’1′

            PRINT’(15X,A)’, ‘ ERROR – THE MATRIX IS SINGULAR’

            IF(b(nrows) .EQ. 0) THEN

                  PRINT’(15X,A)’,’ A condition of zero equal to zero ‘

                  PRINT’(15X,A)’,’ occured. The equations have infinitely’

                  PRINT’(15X,A)’,’ many solutions.’

                  flag = 2

                  GOTO 999

            ELSE

                  PRINT’(15X,A)’,’ A condition of zero equal to a’

                  PRINT’(15X,A)’,’ constant has occured.  There is no ‘

                  PRINT’(15X,A)’,’ solution to the equations.’

                  flag = 3

                  GOTO 999

            END IF

        END IF

50     CONTINUE

C      back substitution

        c(nrows) =  b(nrows)/ a(nrows,ncols)

        DO 500 i = nrows – 1, 1, -1

            accum = 0

            DO 600 j = i + 1, ncols

                  accum = accum +  a(i,j)*c(j) 600       CONTINUE

            c(i) = ( b(i) – accum ) / a(i,i)

C           jump exit location if an error occured 500   CONTINUE 999   CONTINUE

        END

C **********************

        SUBROUTINE PRINT RESULT( orig a, orig b, c, max, nrows,

       +      ncols, flag)

C Variable Definitions

C      c               the resulting constant matrix and the solution C      i,j     2 loop counters

C      max     the maximum number of equations to be solved

C      ncols   the number of columns used in the array

C      nrows   the number of used rows in the array

C                             (also, the number of equations to be solved) C       orig a   the original coefficient matrix to be printed

C      orig b   the original constant matrix to be printed

        INTEGER max, nrows, ncols, flag, i, j

        DOUBLE PRECISION orig a(max, max), orig b(max), c(max)

        PRINT’(A)’,’1′

        IF (flag .NE. 0) THEN

            PRINT’(15X,A)’, ‘ An error has occured.’

        END IF

C      print original matrix a

        PRINT’(15X,A)’,’ The original matrix a’

        DO 100 i = 1, nrows

            PRINT’(15X,10D11.3)’,(orig a(i,j), j = 1, ncols) 100   CONTINUE

        PRINT’(15X,A)’, ‘ The original matrix b’

        DO 200 i = 1, nrows

            PRINT’(15X,D11.3)’, orig b(i) 200   CONTINUE

C      print solution matrix b

        PRINT’(15X,A)’, ‘ The resulting solutions for x(i)’

        DO 300 i = 1, nrows

            PRINT’(15X,A,I2,A,D25.20)’, ‘     X(‘,i,’) =’,c(i) 300   CONTINUE

        END

C **********************



APPENDIX C
Hand Calculations for Cramer’s Rule of Determinants

             ╓─           ─╖

             ║ -3  -1   2  ║                  │ 1 1 │

 det (A1) =  ║ -1   1   1  ║  =  (-1)1+1(-3)  │ 0 1 │ +

             ║  0   0   1  ║

             ╙─           ─╜                      │ -1 1 │

                                     (-1)1+2(-1)  │  0 1 │ +

                                                    │ -1 1 │

                                        (-1)1+3(2)  │  0 0 │ =

         │ 1 1 │            │ -1 1 │           │ -1 1 │

(-1)2(-3)│ 0 1 │ + (-1)3(-1)│  1 0 │ + (-1)4(2)│  0 0 │=

      │ 1 1 │            │ -1 1 │        │ -1 1 │

1(-3) │ 0 1 │ + (-1)(-1) │  0 1 │ + 1(2) │  0 0 │  =

   │ 1 1 │   │ 0 1 │     │ 0 1 │

-3 │ 0 1 │ + │ 0 1 │ + 2 │ 1 0 │ =

-3 ( 1(1) – 0(1) ) + ( -1(1) – 0(1) ) + 2 ( -1(0) – 0(1) ) =

-3 (1 – 0) + (-1 – 0) + 2 (0 – 0)  =  -3 – 1 + 0 = -4

therefore, the det(A1) = -4

          Next find the determinant of the original matrix with the substitution of matrix ‘B’ into the second column.

             ╓─           ─╖

             ║  1  -3   2  ║                │ -1  1 │

 det (A2) =  ║  0  -1   1  ║  =  (-1)1+1(1) │  0  1 │ +

             ║  1   0   1  ║

             ╙─           ─╜                   │ 0 1 │

                                   (-1)1+2(-3) │ 1 1 │ +

                                                  │ 0 -1 │

                                      (-1)1+3(2)  │ 1  0 │ =

        │ -1 1 │            │ 0 1 │           │ 0 -1 │

(-1)2(1)│  0 1 │ + (-1)3(-3)│ 1 1 │ + (-1)4(2)│ 1  0 │ =

     │ -1 1 │            │ 0 1 │        │ 0 -1 │

1(1) │  0 1 │ + (-1)(-3) │ 1 1 │ + 1(2) │ 1  0 │  =

│ -1 1 │     │ 0 1 │     │ 0 -1 │

│  0 1 │ + 3 │ 1 1 │ + 2 │ 1  0 │ =

 ( (-1)(1) – 0(1) ) + 3 ( 0(1) – 1(1) ) + 2 ( 0(0) – 1(-1) ) =

( -1 – 0) + 3 ( 0 – 1) + 2 ( 0 – 1)  = -1 – 3 + 2= -2

therefore, the det(A2) = -2

          Next find the determinant of the original matrix with the substitution of matrix ‘B’ into the third column.

             ╓─          ─╖

             ║  1  -1  -3 ║                │ 1 -1 │

 det (A3) =  ║  0   1  -1 ║  =  (-1)1+1(1) │ 0  0 │ +

             ║  1   0   0 ║

             ╙─          ─╜                  │ 0 -1 │

                                 (-1)1+2(-1) │ 1  0 │ +

                                                │ 0 1 │

                                   (-1)1+3(-3)  │ 1 0 │ =

        │ 1 -1 │            │ 0 -1 │            │ 0 1 │

(-1)2(1)│ 0  0 │ + (-1)3(-1)│ 1  0 │ + (-1)4(-3)│ 1 0 │ =

     │ 1 -1 │            │ 0 -1 │         │ 0 1 │

1(1) │ 0  0 │ + (-1)(-1) │ 1  0 │ + 1(-3) │ 1 0 │  =

│ 1 -1 │   │ 0 -1 │     │ 0 1 │

│ 0  0 │ + │ 1  0 │ – 3 │ 1 0 │ =

 ( (1)(0) – 0(-1) ) + ( 0(0) – 1(-1) ) – 3 ( 0(0) – 1(1) ) =

( 0 – 0 ) + ( 0 + 1 ) – 3 ( 0 – 1 )  = 0 + 1 + 3 = 4

therefore, the det(A3) = 4

Applying the determinants to solve with Cramer’s method, we

find:

     det(A1)    -4                  det(A2)    -2

X =  ─────── = ──── =  2,      Y =  ─────── = ──── =  1,

     det(A)     -2                  det(A)     -2

                  det(A3)     4

       and   Z =  ─────── = ──── = -2

                  det(A)     -2



APPENDIX D
FORTRAN Program for Solving Equations using Cramer’s Rule of Determinants

        PROGRAM Cramers use of Determinants

C Program Name: CRAMER.FOR

C Author: Blair Rene’ Armeaux

C Regarding: Senior Thesis for Bachelor of Arts in Mathematics

C Problem: This program uses the method of Cramer’s use of Determinants C             to solve and print the solutions to a set of equations

C             as selected by the user.  If there is no solution the

C             program will print out why the equations cannot be solved.

C Section Description

C      MAIN     the main program which calls major sub-programs

C       HEADING         a sub-program to print the heading

C      INPUT MATRIX   a sub-program to input the matrices to calculate

C       CALCULATE       a sub-program to calculate the solutions

C      PRINT RESULT   a sub-program to print the solutions

C Variable Definitions

C      flag()   an error flag set during calculations for each

C                             unknown

C      matrix a         the coefficient matrix that will be manipulated

C      matrix b         the constant matrix C       matrix c         the solution matrix C       max              the maximum number of equations to be solved C       min              the minimum number of equations to be solved C       ncols    the number of columns used in the array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved) C       save a   a copy of the original matrix as entered C       save b   a copy of the original matrix as entered

C **********************

C MAIN

        PARAMETER (max = 10, min = 2)

        DOUBLE PRECISION matrix a(max,max), matrix b(max), matrix c(max)

        DOUBLE PRECISION save a(max,max), save b(max)

        INTEGER nrows, ncols, flag(max)

        CALL HEADING(max, min)

        CALL INPUT MATRIX (matrix a, matrix b, max, min,

       +    nrows, ncols, save a, save b)

        CALL CALCULATE (matrix a, matrix b, matrix c, save a, max,

       +    nrows, ncols, flag)

        CALL PRINT RESULT( save a, save b,

       +    matrix c, max, nrows, ncols, flag)

        END

C **********************

        SUBROUTINE HEADING(max, min)

C Variable Definitions

C      max              the maximum number of equations to be solved C       min              the minimum number of equations to be solved

        INTEGER max, min

C      max     the maximum number of equations to be solved C   min       the minimum number of equations to be solved

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ Program Name: CRAMER.FOR ‘

        PRINT’(15X,A)’,” Author: Blair Rene’ Armeaux “

        PRINT’(15X,A)’,’ Regarding: Senior Thesis for Bachelor of Arts ‘

        PRINT’(15X,A)’,’ Problem: This program uses the method of ‘

        PRINT’(15X,A)’,”       Cramer’s use of Determiants to solve “

        PRINT’(15X,A)’,’       a set of equations.’

        PRINT’(15X,A)’,’ This program uses the method of Cramers use of’

        PRINT’(15X,A)’,’ Determinants to solve and print the solutions ‘

        PRINT’(15X,A)’,’ to a set of equations as selected by the user.’

        PRINT’(15X,A)’,’ If there is no solution the program will print’

        PRINT’(15X,A)’,’ out why the equations cannot be solved.’

        PRINT’(15X,A,I3)’,’ The program is set up for a ‘,max

        PRINT’(15X,A,I3,A,A,I3)’,’ by ‘,max,’ coefficient matrix A and ‘,

       +             ‘output and a 1 by ‘, max

        PRINT’(15X,A)’,’ solution matrix B.’

        PRINT’(15X,A)’,’ The program will only alow a minimum of ‘

        PRINT’(15X,I3,A)’, min,’ equations to solve per execution.’

        END

C **********************

        SUBROUTINE INPUT MATRIX (a, b, max, min, nrows,

       +    ncols, save a, save b)

C Variable Definitions

C      a                the coefficient matrix that will be manipulated

C      b                the constant matrix

C      i,j              2 loop counters

C      max              the maximum number of equations to be solved C       min              the minimum number of equations to be solved C       ncols    the number of columns used in the array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved)

C      save a   a copy of the original matrix as entered C       save b   a copy of the original matrix as entered

        INTEGER max, min, nrows, ncols, i, j

        DOUBLE PRECISION a(max,max), b(max), save a(max,max), save b(max)

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ What is the number of equations ‘

        PRINT’(15X,2(A,I3),A)’,'to be solved. (‘,min,’ to’,max,’ only)>’

        READ *,nrows

10     IF (( nrows .GT. max ).OR.( nrows .LT. min)) THEN

            PRINT’(15X,A)’,’ Invalid Input. Try again.’

            PRINT’(15X,A)’,’ What is the number of equations ‘

            PRINT’(15X,A)’,’ to be solved. ‘

            PRINT’(15X,2(A,I3),A)’,'     (‘,min,’ to ‘,max,’ only ) >’

            READ *,nrows

            GOTO 10

        END IF

        PRINT’(15X,A)’,’ Please enter the coefficient matrix “A” one’

        PRINT’(15X,A)’,’ matrix element at a time.  The values are to’

        PRINT’(15X,A)’,’ be entered horizontally.’

        ncols = nrows

        DO 100 i = 1, nrows

            DO 150 j = 1, ncols

                  PRINT’(15X,2(A,I3),A)’,’ Enter coefficient matrix a(‘,

       +                i,’,',j,’) >’

                  READ *,a(i,j)

150       CONTINUE

100   CONTINUE

        PRINT’(A)’,’1′

        DO 200 i = 1, nrows

            PRINT’(15X,A,I3,A)’,’ Enter solution matrix b(‘,i,’) >’

            READ *,b(i)

200   CONTINUE

C      copy all values to a safe place for later

        DO 300 i = 1, nrows

            DO 400 j = 1, ncols

                  save a(i,j) = a(i,j)

400       CONTINUE

            save b(i) = b(i)

300   CONTINUE

        END

C **********************

        SUBROUTINE CALCULATE (a, b, c, save a, max, nrows, ncols, flag)

C Variable Definitions

C      a          the coefficient matrix that will be manipulated

C      b          the constant and solution matrix

C      c          the resulting constant matrix for the solution

C      det a     the determinant of matrix a

C      dedt x    the determinant of matrix a with column x substituted

C      flag      an error flag set during calculations

C      i,j,k     3 loop counters

C      max        the maximum number of equations to be solved C       multiplr  the multiplier for reducing the matrix

C      ncols     the number of columns used in the array

C      nrows     the number of used rows in the array

C                       (also, the number of equations to be solved) C       save a   a copy of the original matrix as entered

        INTEGER max, nrows, ncols, flag(max)

        DOUBLE PRECISION a(max, max), b(max), c(max), save a(max,max),

       +        det a, det x

        INTEGER i,j,k

        DO 50 i=1, nrows

               flag(i) = 0 50     CONTINUE

        det a = determinant (a, max, nrows, ncols)

        IF (det a .EQ. 0) THEN

               PRINT’(A)’,’1′

               PRINT’(15X,A)’,’ The determinant for the whole matrix is ‘

               PRINT’(15X,A)’,’ zero. Therefore there is dependance ‘

               PRINT’(15X,A)’,’ among the equations. Please check and try’

               PRINT’(15X,A)’,’ again.’

               GOTO 999

        END IF

        DO 100 i = 1, ncols

            DO 200 j = 1, ncols

                 DO 300 k = 1, nrows

                      a(k,j) = save a(k,j) 300       CONTINUE

200       CONTINUE

            DO 400 j = 1, nrows

                      a(j,i) = b(j) 400       CONTINUE

        do 450 k = 1, nrows

450   continue

            det x = determinant( a, max, nrows, ncols)

            IF (det x .EQ. 0) THEN

                 PRINT’(A)’,’1′

                 PRINT’(15X,A,I2,A)’,’ The determinant of x(‘,i,

       +             ‘) is zero.’

                 flag(i) = 1

            END IF

            c(i) = det x / det a

100   CONTINUE

999   CONTINUE

        END

C **********************

        FUNCTION DETERMINANT(a, max, nrows, ncols)

C Variable Definitions

C      a          the coefficient matrix that will be manipulated C       accum     an accumulator for back-substituting C       biggest   the biggest value below the diagonal C       i,j,k,l   4 loop counters

C      max        the maximum number of equations to be solved C       multplr   the multiplier for reducing the matrix

C      ncols     the number of columns used in the array

C      nrows     the number of used rows in the array

C                       (also, the number of equations to be solved) C       row        the current row number

C      swap      a variable that keeps track of row interchanges

C      temp      a temporary storage place

        INTEGER max, nrows, ncols, row

        DOUBLE PRECISION a(max, max)

        DOUBLE PRECISION biggest, temp, multplr, accum

        INTEGER i, j, k, l, swap

        swap = 1

C      find biggest value in ‘i’th column below diagonal

C      start at the diagonal

        DO 50 i = 1, nrows-1

            biggest = abs( a(i,i))

            row = i

C          go from below the diagonal through all the equations

            DO 100 k = i + 1, ncols

                  IF (abs( a(k,i)) .GT. biggest) THEN

                        biggest = abs(a(k,i))

                        row = k

                  END IF

100       CONTINUE

            IF (biggest .EQ. 0) THEN

                  accum = 0

                  GOTO 999

            END IF

C          swap ‘row’ with ‘i’th row as long as ‘row’ C               and ‘i’th row are not the same

            IF (i .NE. row) then

                  DO 200 j = 1, ncols

                        temp =  a(row,j)

                        a(row,j) =  a(i,j)

                        a(i,j) = temp

200        CONTINUE

                  swap = -swap

            END IF

C       multiply and reduce through rest of matrix below diagonal

            DO 300 k = i + 1, nrows

c                  IF(a(i,i) .EQ. 0) THEN

c                       accum = 0

c                       GOTO 999 c                END IF

                  multplr =  a(k,i)/ a(i,i)

                  DO 400 l = i, ncols

                        a(k,l) =  a(k,l) – multplr* a(i,l) 400        CONTINUE

300       CONTINUE

50     CONTINUE

C       Calculate the determinant from the resulting diagonal

        accum = swap

        DO 500 i = 1, nrows

            accum = accum * a(i,i)

500   CONTINUE

999   DETERMINANT = accum

        END

C **********************

        SUBROUTINE PRINT RESULT( orig a, orig b, c, max, nrows,

       +      ncols, flag)

C Variable Definitions

C      c                the solution matrix

C      flag()   an error flag set during calculations for each C                           unknown

C      i,j              2 loop counters

C      max              the maximum number of equations to be solved

C      ncols    the number of columns used in the array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved) C       orig a   a copy of the original matrix as entered C       orig b   a copy of the original matrix as entered C       sum              an accumulator

        INTEGER max, nrows, ncols, flag(max), i, j, sum

        DOUBLE PRECISION orig a(max, max), orig b(max), c(max)

C      a               the coefficient matrix that will be printed C     nrows     the number of used rows in the array

C                             (also, the number of equations to be solved) C  ncols     the number of columns used in the array

        PRINT’(A)’,’1′

C      print original matrix a

        PRINT’(15X,A)’,’ The original matrix a’

        DO 100 i = 1, nrows

            PRINT’(15X,10D11.3)’,(orig a(i,j), j = 1, ncols) 100   CONTINUE

        PRINT’(15X,A)’, ‘ The original matrix b’

        DO 200 i = 1, nrows

            PRINT’(15X,D11.3)’, orig b(i) 200   CONTINUE

        sum = 0

        DO 250 i = 1, nrows

            sum = sum + ABS(flag(i)) 250   CONTINUE

        IF (sum .EQ. 0) THEN

C           print solution matrix b

            PRINT’(15X,A)’, ‘ The resulting solutions for x(i)’

            DO 300 i = 1, nrows

                 PRINT’(15X,A,I2,A,D25.20)’, ‘    X(‘,i,’) =’,c(i) 300       CONTINUE

        ELSE

            IF (sum .GE. nrows) THEN

                 PRINT’(15X,A,A)’,’ There are no solutions to the set ‘,

       +             ‘of equations’

            ELSE

                 PRINT’(15X,A)’,’ There are infinitely many solutions ‘

                 PRINT’(15X,A)’,’ to this set of equations.’

            END IF

        END IF

        END

C **********************



APPENDIX E
Hand Calculations for Jacobi Iteration Method

Hand Calculations of Jacobi Iteration Method

Note: All calculations are to three decimal places.

P1 = 1/4 (0 + 0 + P2 + P3)

P2 = 1/4 (P1 + 0 + 0 + P4)

P3 = 1/4 (0 + P1 + P4 + 1)

P4 = 1/4 (P3 + P2 + 0 + 1)

Recall:Iteration 0

P1 = 0

P2 = 0

P3 = 0

P4 = 0

Iteration 1

P1 = 1/4 (0 + 0 + P2 + P3) = .25 (0 + 0 + 0 + 0)   =  0

P2 = 1/4 (P1 + 0 + 0 + P4) = .25 (0 + 0 + 0 + 0)   =  0

P3 = 1/4 (0 + P1 + P4 + 1) = .25 (0 + 0 + 0 + 1)   = .25

P4 = 1/4 (P3 + P2 + 0 + 1) = .25 (.25 + 0 + 0 + 1) = .313

Iteration 2

P1 = 1/4(0 + 0 + P2 + P3) = .25(0 + 0 + 0 + .25)      =.063

P2 = 1/4(P1 + 0 + 0 + P4) = .25(.063 + 0 + 0 + .313)  =.094

P3 = 1/4(0 + P1 + P4 + 1) = .25(0 + .063 + .313 + 1)  =.344

P4 = 1/4(P3 + P2 + 0 + 1) = .25(.344 + .094 + 0 + 1)  =.360

and again, simplified,

Iteration 3

P1 = .25 (0 + 0 + .094 + .344)  = .110

P2 = .25 (.110 + 0 + 0 + .360)  = .117

P3 = .25 (0 + .110 + .360 + 1)  = .368

P4 = .25 (.368 + .117 + 0 + 1)  = .370

Iteration 4

P1 = .25 (0 + 0 + .117 + .368)  =  .121

P2 = .25 (.121 + 0 + 0 + .370)  =  .122

P3 = .25 (0 + .121 + .370 + 1)  =  .373

P4 = .25 (.373 + .122 + 0 + 1)  =  .373

Iteration 5

P1 = .25 (0 + 0 + .122 + .373)  =  .124

P2 = .25 (.124 + 0 + 0 + .373)  =  .125

P3 = .25 (0 + .124 + .373 + 1)  =  .374

P4 = .25 (.374 + .125 + 0 + 1)  =  .375

Iteration 6

P1 = .25 (0 + 0 + .125 + .374)  =  .124

P2 = .25 (.124 + 0 + 0 + .375)  =  .125

P3 = .25 (0 + .124 + .375 + 1)  =  .375

P4 = .25 (.375 + .125 + 0 + 1)  =  .374

Iteration 7

P1 = .25 (0 + 0 + .125 + .375)  =  .124

P2 = .25 (.124 + 0 + 0 + .374)  =  .124

P3 = .25 (0 + .124 + .374 + 1)  =  .374

P4 = .25 (.374 + .124 + 0 + 1)  =  .375

Iteration 8

P1 = .25 (0 + 0 + .124 + .374)  =  .125

P2 = .25 (.125 + 0 + 0 + .374)  =  .125

P3 = .25 (0 + .125 + .375 + 1)  =  .375

P4 = .25 (.375 + .125 + 0 + 1)  =  .375

Thus, after the eigth iteration the answers converge to .125 for P1 and P2, and .375 for P3 and P4.



APPENDIX F
FORTRAN Program for Solving Equations using Jacobi Iteration Method

        PROGRAM Jacobi Iterative Method

C Program Name: JACOBI.FOR

C Author: Blair Rene’ Armeau

C Regarding: Senior Thesis for Bachelor of Arts in Mathematics

C Problem: This program uses the method of Jacobi Iteration to solve

C              and print the solutions to a set of equations as selected

C           by the user.. If there is no solution the program will

C             print out why the equations cannot be solved.

C Section Description

C      MAIN     the main program which calls major sub-programs

C       HEADING         a sub-program to print the heading

C      INPUT MATRIX   a sub-program to input the matrices to calculate

C       CALCULATE       a sub-program to calculate the solutions

C      PRINT RESULT   a sub-program to print the solutions

C Variable Definitions

C      err              the maximum error allowed

C      flag()   an error flag set during calculations for each

C                             unknown

C      matrix a         the coefficient matrix that will be manipulated

C      matrix b         the constant matrix

C      max              the maximum number of equations to be solved

C      max iter      the maximum iterations allowed

C      min              the minimum number of equations to be solved

C      ncols    the number of columns used in the array

C      new x    the current solution array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved)

C       old x    the previous solution array

C      save a   a copy of the original matrix as entered

C       save b   a copy of the original matrix as entered

C **********************

C MAIN

C   Max should not be over 14 without adjusting print routine

C   at least 2 equations are needed to effectively solve a matrix

        PARAMETER (max = 10, min = 2)

        DOUBLE PRECISION matrix a(max,max), matrix b(max), save a(max,max)

        DOUBLE PRECISION save b(max), new x(max), old x(max), err

        INTEGER nrows, ncols, max iter

        CALL HEADING(max, min)

        CALL INPUT MATRIX (matrix a, matrix b, max, min,

       +    nrows, ncols, save a, save b, old x, err, max iter)

        CALL CALCULATE (matrix a, matrix b, old x, new x, max,

       +    nrows, ncols, err, max iter)

        CALL PRINT RESULT( save a, save b, old x, max,

       +    nrows, ncols)

        END

C **********************

        SUBROUTINE HEADING(max, min)

C Variable Definitions

C      max              the maximum number of equations to be solved

C       min              the minimum number of equations to be solved

        INTEGER max, min

C      max     the maximum number of equations to be solved

C   min       the minimum number of equations to be solved

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ Program Name: JACOBI.FOR ‘

        PRINT’(15X,A)’,” Author: Blair Rene’ Armeau “

        PRINT’(15X,A)’,’ Regarding: Senior Thesis for Bachelor of Arts ‘

        PRINT’(15X,A)’,’ Problem: This program uses the Jacobi Iteration’

        PRINT’(15X,A)’,’       Method to solve a set of equations.’

        PRINT’(15X,A)’,’ This program uses the Jacobi Iteration ‘

        PRINT’(15X,A)’,’ Method to solve and print the solutions to a ‘

        PRINT’(15X,A)’,’ set of equations as selected by the user. ‘

        PRINT’(15X,A,I2)’,’ The program is set up for a ‘,max

        PRINT’(15X,A,I2,A)’,’ by ‘,max,’ coefficient matrix A and a 1 by’

        PRINT’(15X,A,I2,A)’, ‘ ‘,max,’ solution matrix B.’

        PRINT’(15X,A)’,’ The program will only alow a minimum of ‘

        PRINT’(15X,A,I2,A)’, ‘ ‘,min,’ equations to solve per execution.’

        PRINT’(15X,A)’,’ The program requires the accuracy required and’

        PRINT’(15X,A)’,’ the maximum number of iterations allowed.’

        END

C **********************

        SUBROUTINE INPUT MATRIX (a, b, max, min, nrows,

       +    ncols, save a, save b, old x, error, max iter)

C      a               the coefficient matrix that will be manipulated

C      b               the solution matrix

C      choice   the user choice

C      error   the maximum error allowed

C      i,j     2 loop counters

C      max     the maximum number of equations to be solved

C   min       the minimum number of equations to be solved

C   nrows     the number of used rows in the array

C                             (also, the number of equations to be solved)

C  ncols     the number of columns used in the array

C      old x   the initial conditions for the solution

C    save a   a copy of the original matrix as entered

C     save b   a copy of the original matrix as entered

        INTEGER max, min, nrows, ncols, i, j, max iter

        DOUBLE PRECISION a(max,max), b(max), save a(max,max)

        DOUBLE PRECISION save b(max), oldx(max)

        PRINT’(A)’,’1′

        PRINT’(15X,A)’,’ What is the number of equations ‘

        PRINT’(15X,2(A,I2),A)’,’ to be solved. (‘,min,’ to’,max,’ only)>’

        READ *,nrows

10     IF (( nrows .GT. max ).OR.( nrows .LT. min)) THEN

            PRINT’(15X,A)’,’ Invalid Input. Try again.’

            PRINT’(15X,A)’,’ What is the number of equations to be  ‘

            PRINT’(15X,2(A,I2),A)’,’ solved. (‘,min,’ to’,max,’ only)>’

            READ *,nrows

            GOTO 10

        END IF

        ncols = nrows

        PRINT’(15X,A)’,’ Please enter the coefficient matrix “A” one’

        PRINT’(15X,A)’,’ matrix element at a time.  The values are to’

        PRINT’(15X,A)’,’ be entered row by row.’

        DO 100 i = 1, nrows

            DO 150 j = 1, ncols

                  PRINT’(15X,2(A,I2),A)’,’ Enter coefficient matrix a(‘,

       +                i,’,',j,’) >’

                  READ *,a(i,j)

150       CONTINUE

100   CONTINUE

        PRINT’(A)’,’1′

        DO 200 i = 1, nrows

            PRINT’(15X,A,I2,A)’,’ Enter solution matrix b(‘,i,’) >’

            READ *,b(i)

200   CONTINUE

C      copy all values to a safe place for later

        DO 300 i = 1, nrows

            DO 400 j = 1, ncols

                  save a(i,j) = a(i,j)

400       CONTINUE

            save b(i) = b(i)

300   CONTINUE

        PRINT’(15X,A)’,’ What is the absolute accuracy required. >’

        READ*, error

        error = ABS(error)

        PRINT’(15X,2A)’, ‘ What is the maximum number of iterations ‘,

       +      ‘allowed. >’

        READ*,max iter

        max iter = ABS(max iter)

        PRINT’(15X,2A)’, ‘ Do you want an initial vector. ‘,

       +      ‘(0 = no, other = yes)>’

        READ*, choice

        IF (choice .NE. 0) THEN

               DO 230 i = 1, nrows

                      PRINT’(15X,A,I3,A)’, ‘ initial x(‘,i,’) = ‘

                      READ*, old x(i)

230     CONTINUE

        ELSE

               DO 140 i = 1, nrows

                      old x(i) = 1 140          CONTINUE

        END IF

        END

C **********************

        SUBROUTINE CALCULATE (a, b, old x, new x, max, nrows,

       +    ncols, error, max iter)

C Variable Definitions

C      a                the coefficient matrix that will be manipulated

C       b                the constant matrix

C      curr acc       the current absolute accuracy

C      error    the maximum error allowed

C      i                a loop counter

C      iter num       the current iteration number

C      j                a loop counter

C      max              the maximum number of equations to be solved

C      max iter      the maximum iterations allowed

C      min              the minimum number of equations to be solved

C      ncols    the number of columns used in the array

C      new x    the current solution array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved)

C       old x    the previous solution array

C      temp     a temporary storage variable

        INTEGER max, nrows, ncols, max iter, iter num

        DOUBLE PRECISION a(max,max), b(max), old x(max), new x(max)

        DOUBLE PRECISION error, curr acc, new acc, temp

        DO 100 iter num = 1, max iter

               curr acc = 0

               DO 200 i = 1, nrows

                      temp = b(i)

                      IF (i .NE. 1) THEN

                             DO 300 j = 1, i-1

                                    temp = temp – a(i,j)* old x(j)

300                     CONTINUE

                      END IF

                      IF (i .NE. nrows) THEN

                             DO 400 j = i+1, ncols

                                    temp = temp – a(i,j)* old x(j)

400                     CONTINUE

                      END IF

                      new x(i) = temp / a(i,i)

                      new acc = ABS( new x(i) – old x(i) )

                      IF ( curr acc .LE. new acc) THEN

                             curr acc = new acc

                      END IF

200     CONTINUE

               DO 500 i = 1, nrows

                      old x(i) = new x(i)

500     CONTINUE

               IF (curr acc .LE. error) GOTO 600

100   CONTINUE

600   END

C **********************

        SUBROUTINE PRINT RESULT( save a, save b, x, max, nrows,

       +      ncols)

C Variable Definitions

C      i,j              2 loop counters

C      max              the maximum number of equations to be solved

C       ncols    the number of columns used in the array

C      nrows    the number of used rows in the array

C                             (also, the number of equations to be solved)

C       save a   a copy of the original matrix as entered

C       save b   a copy of the original matrix as entered

C       x                the solution array

        INTEGER max, nrows, ncols, i, j

        DOUBLE PRECISION save a(max, max), save b(max), x(max)

        PRINT’(A)’,’1′

C      print original matrix a

        PRINT’(15X,A)’,’ The original matrix a’

        DO 100 i = 1, nrows

            PRINT’(15X,10D11.3)’,(save a(i,j), j = 1, ncols) 100   CONTINUE

        PRINT’(15X,A)’, ‘ The original matrix b’

        DO 200 i = 1, nrows

            PRINT’(15X,D11.3)’, save b(i) 200   CONTINUE

C      print solution matrix b

        PRINT’(15X,A)’, ‘ The resulting solutions for x(i)’

        DO 300 i = 1, nrows

            PRINT’(15X,A,I2,A,D25.20)’, ‘     X(‘,i,’) =’,x(i) 300   CONTINUE

        END

C **********************

Sorry, comments for this entry are closed at this time.