Determines the eigenvalues and eigenvectors of a real square matrix.

In the mathematical discipline of linear algebra, eigendecomposition or sometimes spectral decomposition is the factorization of a matrix into a canonical form, whereby the matrix is represented in terms of its eigenvalues and eigenvectors.

If A is symmetric, then A = V * D * V' and A = V * V' where the eigenvalue matrix D is diagonal and the eigenvector matrix V is orthogonal. If A is not symmetric, the eigenvalue matrix D is block diagonal with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda + i*mu, in 2-by-2 blocks, [lambda, mu; -mu, lambda]. The columns of V represent the eigenvectors in the sense that A * V = V * D. The matrix V may be badly conditioned, or even singular, so the validity of the equation A = V * D * inverse(V) depends upon the condition of V.

Inheritance: ICloneable
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            var clone = new JaggedEigenvalueDecomposition();

            clone.d         = (Double[])d.Clone();
            clone.e         = (Double[])e.Clone();
            clone.H         = H.MemberwiseClone();
            clone.n         = n;
            clone.ort       = (Double[])ort;
            clone.symmetric = symmetric;
            clone.V         = V.MemberwiseClone();
            return(clone);
        }
        public void InverseTestNaN()
        {
            int n = 5;

            var I = Matrix.Identity(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[][] value = Matrix.JaggedMagic(n);

                    value[i][j] = double.NaN;

                    var target = new JaggedEigenvalueDecomposition(value);
                }
            }
        }
        public void EigenvalueDecompositionConstructorTest()
        {
            // Symmetric test
            double[][] A =
            {
                new double[] { 4, 2 },
                new double[] { 2, 4 }
            };

            var target = new JaggedEigenvalueDecomposition(A);

            var D = target.DiagonalMatrix;
            var Q = target.Eigenvectors;

            double[][] expectedD =
            { 
                new double[] { 2, 0 },
                new double[] { 0, 6 }
            };

            double[][] expectedQ = 
            {
               new double[] {  0.7071, 0.7071 },
               new double[] { -0.7071, 0.7071 }
            };


            Assert.IsTrue(Matrix.IsEqual(expectedD, D, 0.00001));
            Assert.IsTrue(Matrix.IsEqual(expectedQ, Q, 0.0001));


            // Decomposition identity
            var actualA = Matrix.Multiply(Matrix.Multiply(Q, D), Q.Inverse());

            Assert.IsTrue(Matrix.IsEqual(expectedD, D, 0.00001));
            Assert.IsTrue(Matrix.IsEqual(A, actualA, 0.0001));
            Assert.IsTrue(Matrix.IsEqual(A, target.Reverse(), 0.0001));
        }
        public void EigenvalueDecompositionConstructorTest2()
        {
            // Asymmetric test
            double[][] A =
            {
                new double[] {  5, 2, 1 },
                new double[] {  1, 4, 1 },
                new double[] { -1, 2, 3 }
            };

            var target = new JaggedEigenvalueDecomposition(A);
            var D = target.DiagonalMatrix;
            var Q = target.Eigenvectors;

            double[][] expectedD =
            { 
                new double[] { 6, 0, 0 },
                new double[] { 0, 4, 0 },
                new double[] { 0, 0, 2 }
            };

            // Decomposition identity
            var actualA = Matrix.Multiply(Matrix.Multiply(Q, D), Q.Inverse());

            Assert.IsTrue(Matrix.IsEqual(expectedD, D, 1e-5));
            Assert.IsTrue(Matrix.IsEqual(A, actualA, 1e-5));
            Assert.IsTrue(Matrix.IsEqual(A, target.Reverse(), 1e-5));
        }
 /// <summary>
 ///   Creates a new object that is a copy of the current instance.
 /// </summary>
 /// <returns>
 ///   A new object that is a copy of this instance.
 /// </returns>
 public object Clone()
 {
     var clone = new JaggedEigenvalueDecomposition();
     clone.d = (Double[])d.Clone();
     clone.e = (Double[])e.Clone();
     clone.H = H.MemberwiseClone();
     clone.n = n;
     clone.ort = (Double[])ort;
     clone.symmetric = symmetric;
     clone.V = V.MemberwiseClone();
     return clone;
 }