Linear Equations -- JHU MATLAB Help Page
LINEAR EQUATIONS
 

Creating a Matrix
Substituting Within a Symbolic Matrix
Manipulating Regular Matrices
Vectors
Scalar Multiplication
Addition of Matrices
Gauss-Jordan Elimination
Reduced Row-Echelon Form
Dot Product
Rank
Number of Solutions
Gauss-Jordan Elimination
How to Examples Exercise
How to:
Gauss-Jordan Elimination is a technique for solving systems of linear equations. We start by placing a "cursor" at the top entry of the first nonzero column of the matrix. We call this the cursor entry, and the row it is in, the cursor row.

Step 1 - If the cursor entry is zero, swap the cursor row with some row below to make the cursor entry nonzero (We know there exists such a row because we placed the cursor at the top of a NONZERO column).
We already learned how to
swap rows. For a refresher, let's swap the 1st row with the 2nd row:
     A = A([2, 1, 3, ...], :)

Step 2 - Divide the cursor row by the cursor entry (in step 1 we made sure that the cursor entry was NONZERO, so we know we won't cause an error dividing by it).
Division works just like scalar multiplication:
     A(cursor row, :) = A(cursor row, :)/cursor entry

Step 3 - Eliminate all other entries in the cursor column, by subtracting suitable multiples of the cursor row from all other rows.
Since all the rows have the same dimensions (all are single rows with the same amount of columns), we can use our techniques for addition (and subtraction) of matrices. We want to subtract from our non-cursor rows, the cursor row multiplied by this row's entry in the cursor column:
     A(non-cursor row, :) = A(non-cursor row, :) - A(cursor row, :)*(entry in cursor column)

Step 4 - Move the cursor down one row and over one column. If the new cursor entry and all entries below are zero, move the cursor to the next column (remaining in the same row). Repeat the last step if necessary.
Again, choosing the cursor has nothing to do with MATLAB, it is simply there for our own usage to keep straight which rows/columns/entries we are working with.

Return to Step 1 - The process ends when we run out of rows or columns. Then, the matrix is in Reduced Row-Echelon Form (rref).


Examples:
Now, we will go step-by-step through the Gauss-Jordan Elimination process. Let's start R = [2 4 4; 1 2 9; 2 4 15].
So, our first cursor entry is '2' in the 1st row/1st column. Since '2' is non-zero, we can go right to Step 2. We need to divide the entire 1st row by the cursor entry, '2':
     R(1, :) = R(1, :)/2

Our matrix now has '1 2 2' in the 1st row. Moving on to Step 3. We need to make the other values in the cursor (1st) column all equal to zero:
     R(2, :) = R(2, :) - R(1, :)*1
     R(3, :) = R(3, :) - R(1, :)*2

Our matrix now has '0 0 7' in the 2nd row and '0 0 9' in the 3rd row. We move onto Step 4, choosing a new cursor. We move our cursor from the 1st row/1st column down one row and over one column to the 2nd row/2nd column. But the cursor entry, and all the entries below it (the 3rd row/2nd column) are zero. So, we have to move the cursor the the next column.

So, our cursor is at the '7' in the 2nd row/3rd column and we return to Step 1. Our cursor entry is non-zero, so we're onto Step 2:
     R(2, :) = R(2, :)/7

So, now we have '0 0 1' in the 2nd row, and we move along to Step 3:
     R(1, :) = R(1, :) - R(2, :)*2
     R(3, :) = R(3, :) - R(2, :)*9

We end up with '1 2 0' in the 1st row and '0 0 0' in the 3rd row. Moving onto Step 4, we try and choose a new cursor, but we are out of columns, so we're done! The matrix is officially in
Reduced Row-Echelon Form and looks like this: R = [1 2 0; 0 0 1; 0 0 0].


Exercise: