Reduced row echelon form: Difference between revisions

Line 2,642:
Note that the negative zeros in the output are innocuous,
and also occur in the Perl 5 version.
 
=={{header|Phix}}==
{{Trans|Euphoria}}
<lang Phix>function ToReducedRowEchelonForm(sequence M)
integer lead = 1,
rowCount = length(M),
columnCount = length(M[1]),
i
sequence temp
for r=1 to rowCount do
if columnCount<=lead then exit end if
i = r
while M[i][lead]=0 do
i += 1
if rowCount=i then
i = r
lead += 1
if columnCount=lead then exit end if
end if
end while
temp = M[i]
M[i] = M[r]
M[r] = sq_div(temp,temp[lead])
for j=1 to rowCount do
if j!=r then
M[j] = sq_sub(M[j],sq_mul(M[j][lead],M[r]))
end if
end for
lead += 1
end for
return M
end function
? ToReducedRowEchelonForm(
{ { 1, 2, -1, -4 },
{ 2, 3, -1, -11 },
{ -2, 0, -3, 22 } })</lang>
{{out}}
<pre>
{{1,0,0,-8},{0,1,0,1},{0,0,1,-2}}
</pre>
 
=={{header|PHP}}==
7,820

edits