EchelonForm.mw

Math 22 Fall 2004

Linear Algebra with Applications


Class Demo for the Echelon Forms

September 27, 2004

    Load the package for doing Linear Algebra

> with(Student[LinearAlgebra]):


   
Define a matrix (4 rows, 5 columns) to work with

> M := <<0|-1|2|-3|4>,<2|-4|4|3|-10>,<3|-1|-4|0|-5>,<1|-2|2|-1|-3>>;

M := Matrix([[0, -1, 2, -3, 4], [2, -4, 4, 3, -10], [3, -1, -4, 0, -5], [1, -2, 2, -1, -3]])

     Step 1: Choose column 1 as our pivot column.

                 We start by transforming  it into an echelon form.

     Step 2: Select any non-zero entry as a pivot and

                  bring it into the pivot position (to the top)

> M := SwapRows(M, 1, 4);          # Bring the pivot entry into the 1st row

M := Matrix([[1, -2, 2, -1, -3], [2, -4, 4, 3, -10], [3, -1, -4, 0, -5], [0, -1, 2, -3, 4]])

     Step 3: Use the row replacement operations to create zeros in

                 all positions below the pivot.

> M := AddRow(M, 2, 1, -2);    # Make entry below the pivot in row 2 zero
M := AddRow(M, 3, 1, -3);    
# Make entry below the pivot in row 3 zero

M := Matrix([[1, -2, 2, -1, -3], [0, 0, 0, 5, -4], [3, -1, -4, 0, -5], [0, -1, 2, -3, 4]])

M := Matrix([[1, -2, 2, -1, -3], [0, 0, 0, 5, -4], [0, 5, -10, 3, 4], [0, -1, 2, -3, 4]])

     Step 4: Repeat Steps 1-3 for the next column

     Pivot column is column 2 now. Bring it into an Echelon Form

> M := SwapRows(M, 2, 4);          # Bring the pivot in the 2nd column to the 2nd row

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, -3, 4], [0, 5, -10, 3, 4], [0, 0, 0, 5, -4]])

> M := AddRow(M, 3, 2, 5);     # Make the entries below the pivot zero

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, -3, 4], [0, 0, 0, -12, 24], [0, 0, 0, 5, -4]])

     Column 3 is in the Echelon Form already. Go to column 4.

> M := MultiplyRow(M, 3, 1/12);    # Scale the row 3 a bit to make our life easier

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, -3, 4], [0, 0, 0, -1, 2], [0, 0, 0, 5, -4]])

> M := AddRow(M, 4, 3, 5);     # Make the entries in column 4 below the pivot zero

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, -3, 4], [0, 0, 0, -1, 2], [0, 0, 0, 0, 6]])

The matrix is in the Echelon Form now

     Step 5: Starting from the last column, make all the pivots 1

                 and all the entries above them zero.

> M := MultiplyRow(M, 3, -1);    # Make the pivot in the 4th column 1

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, -3, 4], [0, 0, 0, 1, -2], [0, 0, 0, 0, 6]])

> M := AddRow(M, 2, 3, 3);      # Make the entry above it in row 2 zero
M := AddRow(M, 1, 3, 1);      
# Make the entry above it in row 1 zero

M := Matrix([[1, -2, 2, -1, -3], [0, -1, 2, 0, -2], [0, 0, 0, 1, -2], [0, 0, 0, 0, 6]])

M := Matrix([[1, -2, 2, 0, -5], [0, -1, 2, 0, -2], [0, 0, 0, 1, -2], [0, 0, 0, 0, 6]])

> M := MultiplyRow(M, 2, -1);     # Make the pivot in column 2 1

M := Matrix([[1, -2, 2, 0, -5], [0, 1, -2, 0, 2], [0, 0, 0, 1, -2], [0, 0, 0, 0, 6]])

> M := AddRow(M, 1, 2, 2);      # Make the entry above the pivot zero

M := Matrix([[1, 0, -2, 0, -1], [0, 1, -2, 0, 2], [0, 0, 0, 1, -2], [0, 0, 0, 0, 6]])

The matrix is in the   reduced Echelon Form now

Conclusion: the original linear system was inconsistent

Modify it: if there were no last row now, the system would be  

> M1 := LinearAlgebra[DeleteRow](M, 4);

M1 := Matrix([[1, 0, -2, 0, -1], [0, 1, -2, 0, 2], [0, 0, 0, 1, -2]])

      This linear system is consistent. It has 1 free variable, x[3],

     and 3 basis variables, x[1], x[2], and x[4].

      Here is the corresponding linear system:

> EqSystem := GenerateEquations(M1, [x[1], x[2], x[3], x[4]]);

EqSystem := [x[1]-2*x[3] = -1, x[2]-2*x[3] = 2, x[4] = -2]

      Its general solution is

> solve(convert(EqSystem, set));

{x[4] = -2, x[2] = 2+2*x[3], x[1] = -1+2*x[3], x[3] = x[3]}

      The parametric description of the solution set is

> LinearSolve(M1);

Vector[column]([[-1+2*_t0[3]], [2+2*_t0[3]], [_t0[3]], [-2]])