Anonymous user
Reduced row echelon form: Difference between revisions
Shorter D code
(→{{header|Euphoria}}: Euphoria example added) |
(Shorter D code) |
||
Line 700:
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.array, std.conv;
const ncols =
if (ncols <= lead) return;▼
▲ foreach (r; 0 .. rowCount) {
▲ return;
int i = r;
while (M[i][lead] == 0)
i = r;
}
swap(M[i], M[r]);
M[r][] /= M[r][lead];
foreach (j; 0 ..
if (j != r)
M[j][] -= M[r][] * M[j][lead];
Line 742 ⟶ 725:
void main() {
auto
toReducedRowEchelonForm(
writeln("[", array(map!text(A)).join("\n "), "]");
}</lang>
Output:
<pre>[[1, 0, 0, -8]
[0, 1, 0, 1]
[0, 0, 1, -2]]</pre>
=={{header|Euphoria}}==
|