LU decomposition: Difference between revisions

Updated D entry
(Updated D entry)
(Updated D entry)
Line 713:
 
/// Creates the pivoting matrix for m.
T[][] pivotize(T)(immutable T[][] m) /*pure*/ nothrow
in {
assert(m.isSquare);
Line 719:
immutable n = m.length;
auto id = iota(n)
.map!((in j) => n.iota.map!(i => cast(T)(i == j)).array)
.array;
 
Line 741:
/// Decomposes a square matrix A by PA=LU and returns L, U and P.
Tuple!(T[][],"L", T[][],"U", const T[][],"P")
lu(T)(immutable T[][] A) /*pure*/ nothrow
in {
assert(A.isSquare);
Line 753:
}
 
constimmutable P = A.pivotize!T;
constimmutable A2 = matrixMul!T(P, A);
 
foreach (immutable j; 0 .. n) {
Line 785:
 
auto f = "[%([%(%.1f, %)],\n %)]]\n\n".replicate(3);
foreach (immutable m; [a, b])
writefln(f, lu(m).tupleof);
}</lang>