det

Matrix determinant.

det
(
SliceKind kind
Iterator
)
(
Slice!(kind, [2], Iterator) a
)

Examples

// Check for zero-determinant shortcut.
auto ssing = [4, 2, 2, 1].sliced(2, 2);
auto ssingd = det(ssing);
assert (det(ssing) == 0);
assert (detSymmetric(ssing) == 0);
assert (detSymmetric(ssing, 'L') == 0);

//import std.stdio;


// General dense matrix.
int dn = 101;
auto d = uninitSlice!double(dn, dn);
foreach (k; 0 .. dn)
foreach (l; 0 .. dn)
    d[k,l] = 0.5 * (k == l ? (k + 1) * (k + 1) + 1 : 2 * (k + 1) * (l + 1));

auto dd = det(d);
import std.math: approxEqual;
assert (approxEqual(dd, 3.539152633479803e289, double.epsilon.sqrt));

// Symmetric packed matrix
auto spa = [ 1.0, -2, 3, 4, 5, -6, -7, -8, -9, 10].sliced.stairs!"+"(4);
auto sp = [spa.length, spa.length].uninitSlice!double;
import mir.ndslice.algorithm: each;
sp.stairs!"+".each!"a[] = b"(spa);
assert (sp.detSymmetric('L').approxEqual(5874.0, double.epsilon.sqrt));
assert (sp.universal.transposed.detSymmetric('U').approxEqual(5874.0, double.epsilon.sqrt));

Meta