Read-only forum archive

Reduced Row Echelon Form

Reduced Row Echelon Form

rambiz · Tue Jun 07, 2016 3:27 pm

Hi all,
how can one get the "Reduced Row Echelon Form" of a matrix in Singular, please?

example: (input is a 4x3 matrix)

input=
[1 2 3
4 5 6
7 8 9
10 11 12]

desired output=
[1 0 -1
0 1 2
0 0 0
0 0 0]

My code for the Reduced Row Echelon Form

rambiz · Wed Jun 08, 2016 12:09 am

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?

Re: Reduced Row Echelon Form

hannes · Thu Jun 09, 2016 10:27 am

see http://www.singular.uni-kl.de/Manual/4-0-3/sing_338.htm

ludecomp

rambiz · Thu Jun 09, 2016 4:29 pm

Hi Hannes,
I had actually had a look at the function you suggested before I posted my original message. However, I don't know how that decomposition can be used to get the reduced row echelon form. Can you please elaborate? Thanks.

Re: Reduced Row Echelon Form

hannes · Fri Jun 10, 2016 11:05 am

Code:
ring R=0,x,dp;
matrix m[4][3]=1,2,3,4,5,6,7,8,9,10,11,12;
list L=ludecomp (m);
print(L[3]);
1,2, 3,
0,-3,-6,
0,0, 0,
0,0, 0 

Re: Reduced Row Echelon Form

rambiz · Sat Jun 11, 2016 4:42 pm

According to my definition in a reduced row echelon form the leading terms should all be one, and the remaining entries in the same column should be zero.
In the case of your example:

matrix m[4][3]=1,2,3,4,5,6,7,8,9,10,11,12;

Desired output is:

1 0 -1
0 1 2
0 0 0
0 0 0