eigSymmetric

Eigenvalues and eigenvectors of symmetric matrix.

eigSymmetric
(
Flag!"computeVectors" cv = Yes.computeVectors
Iterator
SliceKind kind
)
(
char store
,
Slice!(Iterator, 2, kind) a
)

Return Value

Type: auto

Examples

import mir.ndslice;

import mir.ndslice.slice: sliced;
import mir.ndslice.topology: universal, map;
import mir.ndslice.dynamic: transposed;
import mir.math.common: approxEqual;
import mir.algorithm.iteration: all;

auto a = [
    1.0000, 0.5000, 0.3333, 0.2500,
    0.5000, 1.0000, 0.6667, 0.5000,
    0.3333, 0.6667, 1.0000, 0.7500,
    0.2500, 0.5000, 0.7500, 1.0000].sliced(4, 4);

auto eigr = eigSymmetric('L', a);

alias appr = all!((a, b) => approxEqual(a, b, 1e-3, 1e-3));

assert(appr(eigr.values, [0.2078,0.4078,0.8482,2.5362]));

auto test = [
     0.0693, -0.4422, -0.8105, 0.3778,
    -0.3618,  0.7420, -0.1877, 0.5322,
     0.7694,  0.0486,  0.3010, 0.5614,
    -0.5219, -0.5014,  0.4662, 0.5088].sliced(4, 4).transposed;


foreach (i; 0 .. 4)
    assert(appr(eigr.vectors[i], test[i]) || appr(eigr.vectors[i].map!"-a", test[i]));

Meta