public static void ComputeEigenvalues(this SymmetricMatrix2 @this, out double low, out double high) { var halfTrace = @this.Trace() / 2; var disc = BasicMath.Sqrt(halfTrace * halfTrace - @this.Det()); low = halfTrace - disc; high = halfTrace + disc; }
public void Eigenvectors_and_eigenvalues_of_satisfy_defining_equations ([Values(0.577, 0.577, 0.577, 0.577)] double xx, [Values(2.718, 0.577, 0.577, 0.577)] double yy, [Values(3.141, 0, 1e-40, 1e-60)] double xy) { var mat = new SymmetricMatrix2(xx, yy, xy); var loVal = mat.LowEigenvalue(); var loVec = mat.LowEigenvector(); Expect((mat - SymmetricMatrix2.Scalar(loVal)).Det(), Is.EqualTo(0).Within(_tolerance)); Expect(Vector2.Distance(mat * loVec, loVal * loVec), Is.LessThan(_tolerance)); var hiVal = mat.HighEigenvalue(); var hiVec = mat.HighEigenvector(); Expect((mat - SymmetricMatrix2.Scalar(hiVal)).Det(), Is.EqualTo(0).Within(_tolerance)); Expect(Vector2.Distance(mat * hiVec, hiVal * hiVec), Is.LessThan(_tolerance)); Expect(loVal, Is.LessThan(hiVal + _tolerance)); Expect(loVal + hiVal, Is.EqualTo(mat.Trace()).Within(_tolerance)); }
public static double HighEigenvalue(this SymmetricMatrix2 @this) { var halfTrace = @this.Trace() / 2; return(halfTrace + BasicMath.Sqrt(halfTrace * halfTrace - @this.Det())); }