Anonymous user
Reduced row echelon form: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments.
m (Use "strformat".) |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 3,505:
''Reduced Row Echelon Form'' (a.k.a. ''row canonical form'') of a matrix, with optimization added.
<lang rexx>/*REXX pgm performs Reduced Row Echelon Form (RREF), AKA row canonical form on a matrix)*/
cols= 0;
mat.=; mat.1= ' 1 2 -1 -4 '
mat.2= ' 2 3 -1 -11 '
mat.3= ' -2 0 -3 22 '
do r=1 until mat.r==''; _=mat.r /*build @.row.col from (matrix) mat.X*/
do c=1 until _='';
w= max(w, length(@.r.c) + 1)
end /*c*/
cols= max(cols, c)
end /*r*/
rows= r
call showMat 'original matrix' /*display the original
!=
/* ┌──────────────────────◄────────────────◄──── Reduced Row Echelon Form on matrix.*/
do r=1 for rows while cols>! /*begin to perform the heavy lifting. */
j=
do while @.j.!==0; j= j + 1
if j==rows then do; j= r;
end /*while*/
/* [↓] swap rows J,R (but not if same)*/
do _=1 for cols while j\==r; parse value @.r._ @.j._ with @.j._ @._._
end /*_*/
?= @.r.!
do d=1 for cols while ?\=1; @.r.d= @.r.d / ?
end /*d*/ /* [↑] divide row J by @.r.p ──unless≡1*/
Line 3,535:
end /*s*/
end /*k*/ /* [↑] for the rest of numbers in row.*/
!= !
end /*r*/
Line 3,541:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: parse arg title; say;
say _
{{out|output|text= when using the default (internal) input:}}
<pre>
|