Reduced row echelon form: Difference between revisions
Added 11l
(Added algorithm coded in Rust) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 55:
</pre>
<br><br>
=={{header|11l}}==
{{trans|Python}}
<lang 11l>F ToReducedRowEchelonForm(&M)
V lead = 0
V rowCount = M.len
V columnCount = M[0].len
L(r) 0 .< rowCount
I lead >= columnCount
R
V i = r
L M[i][lead] == 0
i++
I i == rowCount
i = r
lead++
I columnCount == lead
R
swap(&M[i], &M[r])
V lv = M[r][lead]
M[r] = M[r].map(mrx -> mrx / Float(@lv))
L(i) 0 .< rowCount
I i != r
lv = M[i][lead]
M[i] = zip(M[r], M[i]).map((rv, iv) -> iv - @lv * rv)
lead++
V mtx = [[ 1.0, 2.0, -1.0, -4.0],
[ 2.0, 3.0, -1.0, -11.0],
[-2.0, 0.0, -3.0, 22.0]]
ToReducedRowEchelonForm(&mtx)
L(rw) mtx
print(rw.join(‘, ’))</lang>
{{out}}
<pre>
1, 0, 0, -8
0, 1, 0, 1
0, 0, 1, -2
</pre>
=={{header|360 Assembly}}==
|