Reduced row echelon form: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) m →{{header|Perl 6}}: Update to more modern, idiomatic syntax |
m →{{header|REXX}}: added/changed comments and whitespace. |
||
Line 2,958:
mat.2= ' 2 3 -1 -11 '
mat.3= ' -2 0 -3 22 '
do r=1 until mat.r==''; _=mat.r
cols=max(cols, c)
end /*r*/
rows=r -
call showMat 'original matrix' /*display the original matrix to screen*/
!=1 /*set the working column pointer to 1.*/
/*
do r=1 for rows while cols>! /*begin to perform the heavy lifting. */
j=r /*use a subsitute index for the DO loop*/
do while @.j.!==0; j=j + 1
if j==rows then do; j=r; !=! + 1; if cols==! then leave r; end
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
do k=1 for rows;
if k==r | ?=0 then iterate
do s=1 for cols; @.k.s= @.k.s - ? * @.r.s
!=! + 1 /*bump the column pointer. */
end /*r*/
Line 2,988 ⟶ 2,990:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
showMat: parse arg title; say; say center(title, 3 + (cols+1) * w, '─');
do r=1 for rows; _=
do c=1 for cols
if @.r.c=='' then do; say "***error*** matrix element isn't defined:"
say 'row' row", column" c'.';
end
_=_ right(@.r.c, w)
end /*c*/
say _ /*display a matrix row
end
{{out|output|text= when using the default (internal) input:}}
<pre>
|