LU decomposition: Difference between revisions
Content added Content deleted
m (→{{header|Tcl}}: Smarten up) |
(Simplified D code) |
||
Line 265:
#2A((1 0 0 0) (0 0 1 0) (0 1 0 0) (0 0 0 1))</lang>
=={{header|D}}==
{{trans|Common Lisp}}
<lang d>import std.stdio, std.algorithm, std.typecons;
▲// plus functions from Matrix multiplication task
/// Creates a nxn identity matrix.
Line 280 ⟶ 281:
return m;
}
/// Creates the pivoting matrix for m.
Line 298 ⟶ 294:
T max = m[j][j];
int row = j;
foreach (i; j .. n)
if (m[i][j] > max) {
max = m[i][j];
row = i;
}
if (j != row)
}
Line 334 ⟶ 329:
s1 += U[k][j] * L[i][k];
U[i][j] = A2[i][j] - s1;
}
foreach (i; j .. n) {
Line 346 ⟶ 340:
return tuple(L, U, P);
}
void main() {
enum double[][] a = [[1, 3, 5], [2, 4, 7], [1, 1, 0]];
writeln(prettyPrint(
writeln();
enum double[][] b = [[11, 9, 24, 2], [1, 5, 2, 6],
[3, 17, 18, 1], [2, 5, 7, 1]];
writeln(prettyPrint(
}</lang>
Output:
|