Module for Gauss-Jordan Elimination

Check out the new Numerical Analysis Projects page.

 

    In this module we develop a algorithm for solving a general linear system of equations [Graphics:Images/GaussJordanMod_gr_1.gif] consisting of n equations and n unknowns where it is assumed that the system has a unique solution.  The method is attributed Johann Carl Friedrich Gauss (1777-1855) and Marie Ennemond Camille Jordan (1838-1922).  The following theorem states the sufficient conditions for the existence and uniqueness of solutions of a linear system [Graphics:Images/GaussJordanMod_gr_2.gif].  

Theorem (Unique Solutions) Assume that [Graphics:Images/GaussJordanMod_gr_3.gif] is an [Graphics:Images/GaussJordanMod_gr_4.gif] matrix.  The following statements are equivalent.

     (i) Given any [Graphics:Images/GaussJordanMod_gr_5.gif] matrix [Graphics:Images/GaussJordanMod_gr_6.gif], the linear system [Graphics:Images/GaussJordanMod_gr_7.gif] has a unique solution.
     
    (ii) The matrix [Graphics:Images/GaussJordanMod_gr_8.gif] is nonsingular (i.e., [Graphics:Images/GaussJordanMod_gr_9.gif] exists).
    
   (iii) The system of equations [Graphics:Images/GaussJordanMod_gr_10.gif] has the unique solution [Graphics:Images/GaussJordanMod_gr_11.gif].  
   
   (iv) The determinant of [Graphics:Images/GaussJordanMod_gr_12.gif] is nonzero, i.e. [Graphics:Images/GaussJordanMod_gr_13.gif].  

    It is convenient to store all the coefficients of the linear system [Graphics:Images/GaussJordanMod_gr_14.gif] in one array of dimension [Graphics:Images/GaussJordanMod_gr_15.gif].  The coefficients of [Graphics:Images/GaussJordanMod_gr_16.gif] are stored in column [Graphics:Images/GaussJordanMod_gr_17.gif] of the array (i.e. [Graphics:Images/GaussJordanMod_gr_18.gif]).  Row [Graphics:Images/GaussJordanMod_gr_19.gif] contains all the coefficients necessary to represent the [Graphics:Images/GaussJordanMod_gr_20.gif] equation in the linear system. The augmented matrix is denoted [Graphics:Images/GaussJordanMod_gr_21.gif] and the linear system is represented as follows:

         [Graphics:Images/GaussJordanMod_gr_22.gif][Graphics:Images/GaussJordanMod_gr_23.gif]  

    The system [Graphics:Images/GaussJordanMod_gr_24.gif], with augmented matrix [Graphics:Images/GaussJordanMod_gr_25.gif], can be solved by performing row operations on [Graphics:Images/GaussJordanMod_gr_26.gif].  The variables  are placeholders for the coefficients and cam be omitted until the end of the computation.

Theorem (Elementary Row Operations). The following operations applied to the augmented matrix [Graphics:Images/GaussJordanMod_gr_27.gif] yield an equivalent linear system.

     (i) Interchanges:    The order of two rows can be interchanged.  
     
    (ii) Scaling:       Multiplying a row by a nonzero constant.
    
   (iii) Replacement:    Row r can be replaced by the sum of that tow and a nonzero multiple of any other row;
                               that is:  [Graphics:Images/GaussJordanMod_gr_28.gif].      

    It is common practice to implement (iii) by replacing a row with the difference of that row and a multiple of another row.  

Definition (Pivot Element). The number [Graphics:Images/GaussJordanMod_gr_29.gif] in the coefficient matrix [Graphics:Images/GaussJordanMod_gr_30.gif] that is used to eliminate [Graphics:Images/GaussJordanMod_gr_31.gif] where [Graphics:Images/GaussJordanMod_gr_32.gif], is called the [Graphics:Images/GaussJordanMod_gr_33.gif] pivot element, and the [Graphics:Images/GaussJordanMod_gr_34.gif] row is called the pivot row.      

Theorem (Gaussian Elimination with Back Substitution). Assume that [Graphics:Images/GaussJordanMod_gr_35.gif] is an [Graphics:Images/GaussJordanMod_gr_36.gif] nonsingular matrix. There exists a unique system [Graphics:Images/GaussJordanMod_gr_37.gif] that is equivalent to the given system [Graphics:Images/GaussJordanMod_gr_38.gif], where [Graphics:Images/GaussJordanMod_gr_39.gif] is an upper-triangular matrix with [Graphics:Images/GaussJordanMod_gr_40.gif] for [Graphics:Images/GaussJordanMod_gr_41.gif].  After  [Graphics:Images/GaussJordanMod_gr_42.gif] are constructed, back substitution can be used to solve [Graphics:Images/GaussJordanMod_gr_43.gif] for [Graphics:Images/GaussJordanMod_gr_44.gif].  

Algorithm I. (Limited Gauss-Jordan Elimination).  Construct the solution to the linear system  [Graphics:Images/GaussJordanMod_gr_45.gif]  by using Gauss-Jordan elimination under the assumption that row interchanges are not needed.  The following subroutine uses row operations to eliminate  [Graphics:Images/GaussJordanMod_gr_46.gif]  in column  p  for  [Graphics:Images/GaussJordanMod_gr_47.gif].

Mathematica Subroutine (Limited Gauss-Jordan Elimination).

[Graphics:Images/GaussJordanMod_gr_48.gif]

Example 1. Use the Gauss-Jordan elimination method to solve the linear system  [Graphics:Images/GaussJordanMod_gr_49.gif].  
Use the menu "Input" then submenu "Create Table/Matrix/Palette" to enter matrices A and M and vector B.
Solution 1.

 

Example 2. Interchange rows 2 and 3 and try to use the Gauss-Jordan elimination subroutine to solve the linear system  [Graphics:Images/GaussJordanMod_gr_63.gif].  
Use lists in the subscript to select rows 2 and 3 and perform the row interchange.
Solution 2.

 

Provide for row interchanges in the Gauss-Jordan subroutine.

Add the following loop that will interchange rows and perform partial pivoting.

[Graphics:Images/GaussJordanMod_gr_78.gif]

To make these changes, copy your subroutine GaussJordan and place a copy below. Then you can copy the above lines by selecting them and then use the "Edit" and "Copy" menus. The improved Gauss-Jordan subroutine should look like this (blue is for placement information only).  Or just use the active Mathematica code given below.

Algorithm II. (Complete Gauss-Jordan Elimination).  Construct the solution to the linear system  [Graphics:Images/GaussJordanMod_gr_79.gif]  by using Gauss-Jordan elimination.  Provision is made for row interchanges if they are needed.  

Mathematica Subroutine (Complete Gauss-Jordan Elimination).

[Graphics:Images/GaussJordanMod_gr_80.gif]

Example 3. Use the improved Gauss-Jordan elimination subroutine with row interchanges to solve the linear system  [Graphics:Images/GaussJordanMod_gr_81.gif].  
Use the matrix A and vector B in example 2.
Solution 3.

 

Example 4. Use the Gauss-Jordan elimination method to solve the linear system  [Graphics:Images/GaussJordanMod_gr_98.gif].  
Solution 4.

 

Use the subroutine "GaussJordan" to find the inverse of a matrix.

Theorem (Inverse Matrix) Assume that [Graphics:Images/GaussJordanMod_gr_120.gif] is an [Graphics:Images/GaussJordanMod_gr_121.gif] nonsingular matrix. Form the augmented matrix [Graphics:Images/GaussJordanMod_gr_122.gif] of dimension  [Graphics:Images/GaussJordanMod_gr_123.gif].  Use Gauss-Jordan elimination to reduce the matrix [Graphics:Images/GaussJordanMod_gr_124.gif] so that the identity [Graphics:Images/GaussJordanMod_gr_125.gif] is in the first [Graphics:Images/GaussJordanMod_gr_126.gif] columns.  Then the inverse [Graphics:Images/GaussJordanMod_gr_127.gif] is located in columns [Graphics:Images/GaussJordanMod_gr_128.gif].      
 

Example 5. Use Gauss-Jordan elimination to find the inverse of the matrix  A.
Enter the matrix  A  and create a 4 by 4 identity matrix and store it in the variable Iden.
Solution 5.

 

Algorithm III. (Concise Gauss-Jordan Elimination).  Construct the solution to the linear system  [Graphics:Images/GaussJordanMod_gr_156.gif]  by using Gauss-Jordan elimination.  The print statements are for pedagogical purposes and are not needed.  

Mathematica Subroutine (Concise Gauss-Jordan Elimination).

[Graphics:Images/GaussJordanMod_gr_157.gif]

Remark. The Gauss-Jordan elimination method is the "heuristic" scheme found in most linear algebra textbooks.  The line of code
        [Graphics:Images/GaussJordanMod_gr_158.gif]
divides each entry in the pivot row by its leading coefficient [Graphics:Images/GaussJordanMod_gr_159.gif].  Is this step necessary?  A more computationally efficient algorithm will be studied which uses upper-triangularization followed by back substitution.  The partial pivoting strategy will also be employed, which reduces propagated error and instability.

 

Old Lab Project (Gauss-Jordan Elimination  Gauss-Jordan Elimination).  Internet hyperlinks to an old lab project.  

 

Research Experience for Undergraduates

Gauss-Jordan Elimination and Pivoting  Gauss-Jordan Elimination and Pivoting  
Internet hyperlinks to web sites and a bibliography of articles.  
 

 

Downloads (Gauss Jordan Elimination Gauss Jordan Elimination).  
Download this Mathematica notebook.  

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2003