Share | home | contents | send comment | send link | add bookmark |

Gauss Jordan 4×4 Solver

by Stephen R. Schmitt

Solves a system of 4 linear equations with 4 variables.

Enter the augmented matrix of the system:

:
:
:
:

   next step:


Contents

  1. About
  2. Source code
  3. Discussion

1. About

This JavaScript program solves a linear system of equations represented by an augmented system matrix. For example, the augmented matrix:

0 2 4 : 16
0 4 1 : 11
5 2 0 : 9

represents the following system of linear equations:

    2y + 4z = 16
    4y + z = 11
5x + 2y     = 9

On completion of the algorithm, the augmented matrix would be transformed to:

1 0 0 : 1
0 1 0 : 2
0 0 1 : 3

which means that the solution to the system of equations is

 x = 1,  y = 2,  z = 3.

To operate the solver, enter the elements of the augmented matrix into the cells above. Press the [ Initialize ] key set the state of the solver to the starting value. Press the [ Single Step ] key to advance through each step of the algorithm. The [ Test ] key loads a test case to demonstrate how the calculator works.

If the algorithm determines that the system is singular, having no solution, a pop-up message will be displayed. The algorithm will not advance any further.

Return to Contents


2. Source Code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitablility of this source code for your use.

Return to Contents


3. Discussion

The Gauss-Jordan method enables us to solve a set of linear equations. It is done by manipulating an augmented system matrix using elementary row operations to put the matrix into reduced row echelon form. The following criteria apply:

  1. The first non-zero number in the row is 1.
  2. Any rows entirely made up of zeros are grouped at the bottom of the matrix.
  3. The leading 1 in a lower row occurs farther to the right that the leading 1 in a higher row.
  4. Each column containing a leading 1 has zeros everywhere else.

The Gauss-Jordan algorithm performs operations to arrange the system matrix to meet the above criteria. This allows the solution to be found by inspection. All that remains in the matrix is a main diagonal of ones and the augmentation column. Since the matrix is representing the coefficients of the system variables, the augmentation column represents the values of each of those variables.

Gauss-Jordan Elimination Algorithm:

  1. Start at the first diagonal element.
  2. Check for a zero in the current diagonal element ai,i ). If it is zero, interchange the current row with the first row beneath it in which the element in the same column is not zero.
  3. Zeroize each element aj,i ) below the current diagonal element ai,i ) by applying the following to each element of row ( j ):
    aj,k ) ← aj,k ) − m × ai,k )

    where

    m = aj,i ) / ai,i )
  4. Move to the next diagonal element.
  5. Repeat steps 2 . . . 4 until the last element in the diagonal is done.
  6. Now start at the last diagonal element.
  7. Zeroize each element aj,i ) above the current diagonal element ai,i ) using the method of step 3.
  8. Move to the previous diagonal element.
  9. Repeat steps 7 . . . 8 until the first diagonal element is reached.
  10. Now start at the first diagonal element.
  11. Normalize each element in the row ( i ) by multiplying by:
    m = 1 / ai,i )
  12. Move to the next diagonal element.
  13. Repeat steps 11 . . . 12 until the last element in the diagonal is done.

Return to Contents


Share | home | contents | send comment | send link | add bookmark |


Copyright © 2004, Stephen R. Schmitt