Step-by-Step Gauss Elimination -- "stepgauss" Program

>

The program below follows exactly the Gauss elimination algorithm as presented in our text. It shows all steps and displays the list of elements by which you are dividing during elimination. The latter is important if you apply the procedure to matrices with parametric entries. You know that the final result is valid for all values of entries except those for which divisors are zero. Click on the command line below to activate the program.

Note: The program stepgauss will not work, unless you have loaded the linear algebra package with(linalg): . If you haven't done it above, you must do it now and then activate the program.

>

>

> stepgauss:= proc(MM) local M,m,pival, pivals,
prow,i,j,fprow,nrows,ncols,minrc,pivots,swaps;
if (MM=0) then RETURN(); else M:=MM; fi;
nrows:=rowdim(M); ncols:=coldim(M); minrc:=min(nrows,ncols);
prow:=1; swaps:=NULL; pivots:=NULL; pivals:=NULL;
printf("Matrix:\n"); print(evalm(M));
for j from 1 to minrc do
printf("Starting column %a\n",j);
fprow:=-1;
for i from prow to nrows do
if not(M[i,j]=0) then fprow:=i; break; fi;
od;
if (fprow=-1) then
printf("No pivot in col %a\n", j);
else
if (fprow>prow) then
printf("Swap row %a and row %a\n", fprow, prow);
swaps:=swaps,[fprow,prow];
M:= swaprow(M,fprow,prow);
print(evalm(M));
fi;
pivots:=pivots,[prow,j];
printf("Pivot at [%a,%a]\n",prow,j);
pival:=M[prow,j];
pivals:=pivals,pival;
if (prow < nrows) then
for i from (prow+1) to nrows do
m:=-M[i,j];
if not(m=0) then
printf("Add %a times row %a to row %a\n",m/pival,prow,i);
M:=simplify(addrow(M,prow,i,m/pival));
print(evalm(M));
fi;
od;
prow:=prow+1;
fi;
fi; ##end of main conditional
od; ##end of main loop of columns
printf("Row echelon form: \n"); RETURN(evalm(M));end:

>

Example 7. Let's perform Gauss elimination of the matrix Baup defined above.

> stepgauss(Baup);

>

Scroll up to see the consecutive steps.

Example 8. Let's apply the procedure to the matrix A which has parametric entries.

> stepgauss(A);

>

We obtain a row echelon matrix row equivalent to A. At each step we see the term by which we are dividing. The elimination is valid only if those divisors are not 0. Hence, in our example, the final result is valid whenever a is not zero. Observe that in that case [Maple Math] and [Maple Math] are not zero, either. It should be mentioned that, according to the rules of command line arithmetic, Maple is using the following convention in the displays above a/b/c=(a/b)/c and a/b*c=(a/c)*c.

>

Example 9. For all possible values of a , determine the rank of the matrix S defined in the previous section.

Gauss elimination can be used to determine the rank of a matrix. As you know, the ranks of row equivalent matrices is the same, and the rank of a matrix in the echelon form can be easily seen. For matrices with numerical entries, the command rank works unmistakably. For matrices with parametric entries, you will be better off using stepgauss .

> stepgauss(S);

>

From the steps above, we see that during the process of elimination we had to divide only by a . Hence, the row echelon form is valid for all a different from 0. Hence, rank S is 4 for a different from -1,1 and 0. In this case, we see the rank clearly from the row echelon form. If a is 1 or -1, the rank is 2. The latter also follows from the row echelon form. The case of a equal to 0, we have to examine separately. Note the rather awkward syntax of substituting a value of a parameter into a matrix.

> evalm(subs(a=0,evalm(S))); rank(%);

>

We see that the rank for a = 0 is 4.

>