Reduced row echelon form: Difference between revisions
Content added Content deleted
(→{{header|Ursala}}: Added zkl) |
|||
Line 2,990: | Line 2,990: | ||
rref = @ySzSX msolve; ^plrNCTS\~& ~&iiDlSzyCK9+ :/1.+ 0.!*t</lang> |
rref = @ySzSX msolve; ^plrNCTS\~& ~&iiDlSzyCK9+ :/1.+ 0.!*t</lang> |
||
=={{header|zkl}}== |
|||
Direct implementation of the pseudo-code given, lots of generating new rows rather than modifying the rows themselves. |
|||
<lang zkl>fcn toReducedRowEchelonForm(m){ // m is modified, the rows are not |
|||
lead,rowCount,columnCount := 0,m.len(),m[1].len(); |
|||
foreach r in (rowCount){ |
|||
if(columnCount<=lead) break; |
|||
i:=r; |
|||
while(m[i][lead]==0){ |
|||
i+=1; |
|||
if(rowCount==i){ |
|||
i=r; lead+=1; |
|||
if(columnCount==lead) break; |
|||
} |
|||
}//while |
|||
m.swap(i,r); // Swap rows i and r |
|||
if(n:=m[r][lead]) m[r]=m[r].apply('/(n)); //divide row r by M[r,lead] |
|||
foreach i in (rowCount){ |
|||
if(i!=r) // Subtract M[i, lead] multiplied by row r from row i |
|||
m[i]=m[i].zipWith('-,m[r].apply('*(m[i][lead]))) |
|||
}//foreach |
|||
lead+=1; |
|||
}//foreach |
|||
m |
|||
}</lang> |
|||
<lang zkl>m:=List( T( 1, 2, -1, -4,), // T is read only list |
|||
T( 2, 3, -1, -11,), |
|||
T(-2, 0, -3, 22,)); |
|||
printM(m); |
|||
println("-->"); |
|||
printM(toReducedRowEchelonForm(m)); |
|||
fcn printM(m){ m.pump(Console.println,rowFmt) } |
|||
fcn rowFmt(row){ ("%4d "*row.len()).fmt(row.xplode()) }</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 2 -1 -4 |
|||
2 3 -1 -11 |
|||
-2 0 -3 22 |
|||
--> |
|||
1 0 0 -8 |
|||
0 1 0 1 |
|||
0 0 1 -2 |
|||
</pre> |
|||
{{omit from|GUISS}} |
{{omit from|GUISS}} |