eigen

Undocumented in source. Be warned that the author may not have intended to support it.
  1. EigenResult!(realType!T) eigen(Slice!(const(T)*, 2, kind) a)
  2. EigenResult!(realType!T) eigen(Slice!(RCI!T, 2, kind) a)
    EigenResult!(realType!T)
    eigen
    (
    T
    SliceKind kind
    )
    (
    auto ref Slice!(RCI!T, 2, kind) a
    )

Examples

import mir.blas;
import mir.complex;
import mir.ndslice;
import mir.math;

auto data = 
    [[ 0, 1],
     [-1, 0]].fuse.as!double.rcslice;
auto eigenvalues = [Complex!double(0, 1), Complex!double(0, -1)].sliced;
auto eigenvectors =
    [[Complex!double(0, -1), Complex!double(1, 0)],
     [Complex!double(0, 1), Complex!double(1, 0)]].fuse;

auto res = data.eigen;

assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
    assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));
import mir.complex;
import mir.ndslice;
import mir.math;
import mir.blas;

auto data =
    [[0, 1, 0],
     [0, 0, 1],
     [1, 0, 0]].fuse.as!double.rcslice;
auto c = 3.0.sqrt;
auto eigenvalues = [Complex!double(-1, c) / 2, Complex!double(-1, - c) / 2, Complex!double(1, 0)];

auto eigenvectors =
    [[Complex!double(-1, +c), Complex!double(-1, -c) , Complex!double(2, 0)],
     [Complex!double(-1, -c), Complex!double(-1, +c) , Complex!double(2, 0)],
     [Complex!double(1, 0), Complex!double(1, 0), Complex!double(1, 0)]].fuse;

auto res = data.eigen;

assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
    assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));

auto cdata = data.lightScope.as!(Complex!double).rcslice;
res = cdata.eigen;

assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
    assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));

Meta