Hi all,
I have written a code to implement conversion to the reduced row echelon form.
I used the Groebner Basis approach, which is most probably not the smartest way.
One needs to set the correct number of ring variables manually in the code, and of course, enter the matrix.
In case the number of rows of output is smaller than the number of rows of the matrix, those rows are all zero.
Code:
ring r=0,(x(1..4)),dp; //number of variables must be the same as the number of columns of the matrix for which we want the reduced row echelon form
matrix m[4][4]=16,2,3,13,5,11,10,8,9,7,6,12,4,14,15,1; //enter an arbitrary matrix here
print("m=");print(m);
int nr=nrows(m);
int nc=ncols(m);
int j;
int k;
for(j=1;j<=nr;j=j+1){for(k=1;k<=nc;k=k+1){m[j,k]=m[j,k]*x(k);}};
kill j;
kill k;
matrix ONES[nc][1];
for(int j=1;j<=nc;j=j+1){ONES[j,1]=1;};
kill j;
ideal i=m*ONES;
option(redSB);
ideal g=std(i);
int L=size(g);
for(int j=1;j<=L;j=j+1) {g[j]=g[j]/leadcoef(g[j]);} // set the coefficients of the leading terms to unity
kill j;
matrix RREF[L][nc];
int k;
int j;
for (j=L;j>0;j=j-1){for (k=1;k<=nc;k=k+1){RREF[j,k]=jet(g[L+1-j]/x(k),0);}};
print("RREF=");print(RREF);print("RREF is the Reduced Row Echelon Form of the matrix m")
A) Do you think this code is correct? I have double-checked a few matrices with MATLAB and it seems to be OK.
B)Any suggestion how to improve my code?