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:

>