Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Gauss Jordan Elimination

Gauss-Jordan Elimination

The steps of the Gauss-Jordan elimination process are as follows:

  1. Input augmented matrix A
  2. Get the reduced echelon form for A using elementary row operations. This is done by first creating leading 1s, then ensuring that columns containing leading 1s have only 0s above and below the leading 1, column by column starting with the first column.
  3. The matrix in reduced echelon form will either give the solution or demonstrate that there is no solution.

Two matrices A and B are row equivalent if A =>* B by elementary row operations. During the process of Gauss-Jordan elimination all matrices are row equivalent to the original and each other.

Example

 x1 + 2x2 + x3 =  1
2x1 + 4x2 - x3 = -1

[ 1   2   1   1 ]    [ 1   2   1   1 ]
[ 2   4  -1  -1 ] => [ 0   0  -3  -3 ] R2 := R2 - 2R1

[ 1   2   1   1 ]
[ 0   0   1   1 ] R2 := R2 / -3

To fix column 3:

[ 1   2   0   0 ] R1 := R1 - R2
[ 0   0   1   1 ] (this is in reduced echelon form)

So...

x1 = -2x2
x2 = anything
x3 = 1

The system has many solutions.

In general, any columns without a leading one of them correspond to a variable that can be any value.

The difficult part of Gauss-Jordan elimination is the bit in the middle—deciding which columns to manipulate and how to convert them in to leading 1s. Consider a matrix An x m in the middle of the computation. Some number il of rows have leading 1s in them and some number j of columns have been processed. j ≥ il

    [ a1 ... a1m   b1 ]
A = [ ...            ]
    [ an ... anm   bn ]

The matrix now looks like this:

                               j
   0   0  ...  0   1   0  ...  0  ...  
    ...
il 0   0  ...  0   0   0  ...  1  ...
    ...
   0   0  ...  0   0   0  ...

Next step: Increment j. Look in column j for aoj ≠ 0, with i > il—now interchange row i and row il + 1 (if nothing found, move on to next columns. Create a leading 1, then reduce column j.

Pseudo code for Gauss-Jordan elimination

il = 0 (number of leading 1s created)
for j = 1 ... m do:
    if ∃ i > il such that aij ≠ 0 then:
        il = il + 1
        interchange row i and row il (this brings the new row
          just below the row you have just done)
        divide row i by ailj creating a leading 1
        Reduce all other entries in the column to 0

Complexity

Suppose A is n x m. We can measure complexity by the number of +, -, *, / operations that are carried out. To do this we look at the pseudo code. If we run the main loop m times:

  • The interchange operation takes 2m operations
  • Dividing row i by ailj takes m-j operations
  • The reduce other entries bit takes nm operations

So the complexity of the operation is O(mnm) or O(nm2)

Additional Resources

Homogeneous Systems

A system of linera equations is homogeneous if all of the constant terms are 0. For example:

3x1 + 2x2 = 0
 x1 -  x2 = 0

A homogeneous system in n variables always has the trivial solution x1 = x2 = ... = 0—so there is no chance that the system will have no solutions, reducing the possible outcomes from three to two.

Theorem

A homogeneous system with more unknowns than equations always has many solutions

Proof

Suppose the system has n equations with m unknowns, and m > n.

Let A = the augmented matrix

Find R = reduced echelon form of A using Gauss-Jordan elimination.

         m
  1 . . . . . . .
  0 1 . . . . . .
n 0 0 1 . . . . .
  0 0 0 1 . . . .
  0 0 0 0 1 . . .

R has ≤ n leading 1s, so at least m-n of the variables can take any value. This shows that there are many solutions.

Example

x1 + 2x2 + x3 = 0
      x2 - x3 = 0

This is the intersection of two planes through the origin in 3D space.

Matrix notation for a system of equations

[ a11x1 + ... + a1mxm = b1 ]
[  ...                   ] can be written as AX = B
[ an1x1 + ... + anmxm = bn ]

    [ a1  ... a1m ]
A = [  ...       ]
    [ an1 ... anm ]

    [ x1 ]      [ b1 ]
X = [ .  ]  B = [    ]
    [ xn ]      [ bn ]

This is Gauss Jordan Elimination by Simon Willison, posted on 1st October 2002.

View blog reactions

Next: Applications

Previous: Basic Lisp

46 comments

  1. hello!!I have to do a project where the point is to count the number of floating operations in the Gauss elimination . Do you know any resources to look for?

    george mouschis - 24th November 2002 23:41 - #

  2. I AM ASTUNDENT OF COMPUTER SC1ENCE OSUN STATE POLYTECHNIC,IREE OSUN STATE ,NIGERIA.I NEED YOUR HEIP ON COMPUTATION GAUSS JORDAN ELIMIINATION METHOD USING V.BASIC TO CODE IT.

    OGUNGBAIGBE - 13th December 2002 01:52 - #

  3. I AM ASTUNDENT OF COMPUTER SC1ENCE OSUN STATE POLYTECHNIC,IREE OSUN STATE ,NIGERIA.I NEED YOUR HEIP ON COMPUTATION GAUSS JORDAN ELIMIINATION METHOD USING V.BASIC TO CODE IT.I WILL BE VRRY HAPPY IF CAN RECEIVED IT BEFORE JANUARY FIRST

    OGUNGBAIGBE - 13th December 2002 02:02 - #

  4. dear sir, kindly send me the solution to the following problem: "solve the following system of equations by the Gauss-Jordan method" x1-2x2+3x3=0 2x1+5x2=6x3=0 regards

    roy - 21st September 2003 18:55 - #

  5. dear sir, kindly send me the solution to the following problem: "solve the following system of equations by the Gauss-Jordan method" x1-2x2+3x3=0, 2x1+5x2=6x3=0 regards

    roy - 21st September 2003 18:56 - #

  6. Dear sir, pls. pls. help me. I really don't understand anything about gauss-jordan method. pls. give me the step by step procedures and some examples on how to solve using gauss-jordan elimination method.

    Jilcae - 18th February 2004 08:22 - #

  7. Dear sir, pls help me. Pls kindly send me the gwbasic program for solving linear equations by gauss-jordan elimination method. Thanks

    bikesh - 15th September 2004 04:09 - #

  8. can u pls explain fully the procedure for solving linear equation by gauss-jorda elimination method. thanks

    Ryan - 2nd November 2004 20:36 - #

  9. Any help you can provide in locating source code in GWBASIC for solving (non-homogeneous) simultaneous linear systems (up to 10x10) would be very much appreciated!

    Steve Granados - 15th February 2005 03:22 - #

  10. I need to create Matlab functions that solve systems of linear algebraic equations using Gauss-Elimination and Gauss-Jordan methods by obtaining the co-efficient matrix, [A], and the right hand side values, {b}, as input and output the matrix of unknown values. Then, use these functions in a simple Matlab code to solve a system of linear algebraic equations based on a user's choice. Any m-files you have to help me with this would be great

    Derek Hodkinson - 21st February 2005 22:48 - #

  11. sir , can u plz send me the source code of Gaussian jordan elimination in c. also plz tell how to implement it parallely using MPI (source code if avilable)..

    Abhishek - 30th March 2005 10:37 - #

  12. please help me with books on this topic my adress APLIED BIOLOGY NATIONAL UNIVERSITY OF SCIENCE AND TECHNOLOGY PO BOX 939 ASCOT BULAWAYO ZIMBABWE

    tirivacho jacha - 17th May 2005 09:11 - #

  13. PLEASE SEND ME GAUSS ELIMINATION ONQUADRATIC EQUATIONS

    tirivacho jacha - 17th May 2005 09:14 - #

  14. sir , can u plz send me the source code of Gaussian jordan elimination in c. also plz tell how to implement it parallely using MPI (source code if avilable)..

    G.selvendran - 2nd July 2005 17:40 - #

  15. sir , can u plz send me the source code of Gaussian jordan elimination in c. also plz tell how to implement it parallely using MPI (source code if avilable)..

    G.selvendran - 2nd July 2005 18:02 - #

  16. Dear sir please help me, I really don't know how to solve Gauss-Jordan elimination. Can u send me the answer of this equation, 2x+3y=14 and 3x-2y = -5 in Gauss-Jordan elimination.

    Marseille Aranco - 10th September 2005 07:20 - #

  17. Dear sir please help me, I really don't know how to solve Gauss-Jordan elimination. Can u send me the answer of this equation, 2x+3y=14 and 3x-2y = -5 in Gauss-Jordan elimination.

    Marseille Aranco - 10th September 2005 07:32 - #

  18. hello... dear sir,im asking for your help.. pls. pls help me on how i will use gauss jordan and how i will input it or to put it in the program and how to run it,please help me thanks!!! i really need your help as soon as possible.. thank you very much

    carl - 23rd September 2005 01:29 - #

  19. well i need a problem relating to this method and also its diagram (with solution)if it is granted i will be thank ful.........

    anam - 6th December 2005 11:32 - #

  20. Jesus ****ing christ! He explained everything SO WELL! and you idiots are either asking him to do your homework or to code programs for you? Do you guys HAVE ANY sort of intelligence? Please do not reply since I will not come back. Just think about what I said.

    GOD! - 12th December 2005 10:29 - #

  21. Hi, It's possible to get the C source code of the gaussian-jordan elimination? Can you send it to me? Thanks a lot!

    Luca - 22nd December 2005 16:25 - #

  22. Ops....my email is spelux82 at hotmail dot com

    Luca - 22nd December 2005 16:27 - #

  23. Good afternoon: I am experiencing problems trying to solve this problem: x+y+z=2 1+1+1=2 2x-3y+z=-11 2-3+1=-11 -x+2y-z=8 -1+2-1=8 Once the problem is converted into an augmented matrix and I add two of the rows together, I don't understand the next steps that should take place. Thank you for your assistance

    Roosevelt - 24th December 2005 21:19 - #

  24. i want gaussian elimination method in c+ MPI for training!

    said badr - 14th March 2006 02:31 - #

  25. Hai. Iam a post graduate student from Pondicherry(India). I need a python or matlab code for Gauss elimination method.

    rajesh>k - 16th March 2006 10:45 - #

  26. can i get a C source code for Gauss-Jordan method

    rajesh.k - 16th March 2006 10:53 - #

  27. Can I get Gauss elimination code for banded matrix (for semi-bandwidth) in C language.

    Anand - 21st March 2006 09:00 - #

  28. hi! well i have already made a program to find the lu decomposition of matrix, but now i would like to use the gaussian elimination,i would like to know how to do that thxxx

    neetish - 22nd March 2006 16:58 - #

  29. Respected sir, I am a MBA Student.As this is totally new subject for me,please provide me solution of below question as soon as possible.. Solve the following system of equation by Gauss - Jordan Elimination. 2x1 - 2x2 + x3 = 3; 3x1 + x2 - x3 = 7; x1 - 3x2 + 2x3 = 0 Thanking you, Chaxu

    Ms.Chaxu Vyas - 23rd March 2006 06:29 - #

  30. Hi, Dear sir, D you have the code to solve gauss elimination using Mat Lab, if you do so, please, would you send that to me? Thank you. Arnildo

    Arnildo - 3rd April 2006 21:41 - #

  31. Hi sir, could I please have the code to solve gaussian elimination using Python...thanks a million

    Lila - 10th April 2006 22:30 - #

  32. Respected sir, could you please send me the code to solve gaussian elimination using Python, this will be a great help to me, thanking you in advance

    Aysha - 16th April 2006 11:31 - #

  33. PLEASE THROW MORE LIGHT ON THE THEOREM

    ZED - 17th April 2006 15:17 - #

  34. pliz explain how I can use Gaussian elimination to implement a program that solves linear equations in c++.

    philip - 21st April 2006 18:21 - #

  35. metodo gauss jordan

    danielsantos - 8th July 2006 17:20 - #

  36. sir/madam, pls. help me in my problem. i cant solve, this is the equation: 20X1+10X2+15X3=23, 2x1+6x2+5x3=6.2, 15x1+10x2+5x3=16, solve it using gauss jordan method........................... thank you for the time.............................................. ............................

    marc miranda - 24th July 2006 06:41 - #

  37. sir i want c programming of 2x1+4x2+2x3=15 2x1+x2+3x3=-5 4x1+x2-2x3=0

    ashish - 4th August 2006 13:08 - #

  38. sir i want c programming of 2x1+4x2+2x3=15 2x1+x2+3x3=-5 4x1+x2-2x3=0

    ashish - 4th August 2006 13:10 - #

  39. sir i want c++ programming of 2x1+4x2+2x3=15 2x1+x2+3x3=-5 4x1+x2-2x3=0 using gauss elimination method.

    Durga Shankar - 6th August 2006 11:14 - #

  40. could you solve this x+2y+z=0 -3x+3y+2z=-7 4x-2y-3z=2 using Gaussian elimination and back substitution solve using cramer's rule 2x+4y+6z=2 x+2z=0 2x+3y-z=-5

    alan garris - 9th August 2006 05:07 - #

  41. Sir i want C programming of 5X+6Y+3Z=6,2x+5y+9z=8,9x+6y+4z=10 using Gauss Jordan elimination method.

    Sanjoy bhowmik - 15th August 2006 21:07 - #

  42. sir, please help how to solve 9x9 matrix using gaussian elimination in MATLAB software..i nid it badly..as soon as possible..i nid it this week..thanks!!!

    reggie - 22nd August 2006 13:58 - #

  43. sir, can you send me the c or matlab code for gauss elimination method, i need this for solving my source panel method

    Ramya - 30th August 2006 15:56 - #

  44. sir, I am gauss elimnation method, so don't question me! FEAR the guassian, and vectorize my matrix. RAWR!

    rofl - 12th September 2006 18:25 - #

  45. am augandan student in makerere university doing quantitative economics could u plizz help me with how to go with da gauss -elimination method and afew of worked out examples.thanx

    jonathan - 18th September 2006 11:01 - #

  46. Sir, Can you please send me a C program that solves three simultaneous equations..

    Phumy - 24th October 2006 16:34 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2002/10/01/gaussJordanElimination

A django site