Example #1
0
        public void QRAlgorithmComputeEigenvaluesTest()
        {
            for (Int32 matrixIndex = 0; matrixIndex < this.matrices.Length; matrixIndex++)
            {
                Double[] result = QRAlgorithm.ComputeEigenvalues(this.matrices[matrixIndex]).ToArray();

                result.ShouldBe(this.expectedEigenvalues[matrixIndex], 0.001);
            }
        }
Example #2
0
        public void QRAlgorithmComputeEigenvectorsTest()
        {
            for (Int32 matrixIndex = 0; matrixIndex < this.matrices.Length; matrixIndex++)
            {
                Vector[] result = QRAlgorithm.ComputeEigenvectors(this.matrices[matrixIndex]).ToArray();

                for (Int32 vectorIndex = 0; vectorIndex < result.Length; vectorIndex++)
                {
                    for (Int32 coordinateIndex = 0; coordinateIndex < result[vectorIndex].Size; coordinateIndex++)
                    {
                        result[vectorIndex][coordinateIndex].ShouldBe(this.expectedEigenvectors[matrixIndex][vectorIndex][coordinateIndex], 0.001);
                    }
                }
            }
        }
Example #3
0
        public void TestMatrixInverse()
        {
            IMatrix Ainv = QRAlgorithm.InvertSymmetricMatrix(A);
            IMatrix Ipi  = A.Multiply(Ainv);

            for (int row = 0; row < 2; ++row)
            {
                Console.WriteLine(Ipi[row]);
            }

            Assert.Equal(A.Identity(3), Ipi);

            Ipi = Ainv.Multiply(A);

            Assert.Equal(A.Identity(3), Ipi);
        }
Example #4
0
        /// <summary>
        /// реализация QR-декомпозиции
        /// </summary>
        /// <param name="A - исходная матрица"></param>
        /// <param name="Method - метод QR-декомпозиции"></param>
        public QRDecomposition(Matrix A, QRAlgorithm Method)
        {
            R = new Matrix(A.Row, A.Column);
            Q = new Matrix(A.Row, A.Column);
            //начальная инициализация матрицы ортогональных преобразований
            for (int i = 0; i < A.Row; i++)
            {
                Q.Elem[i][i] = 1.0;
            }

            switch (Method)
            {
            case QRAlgorithm.Classic_Gram_Schmidt:
            {
                GramSchmidt.Classic(A, Q, R);
                break;
            }

            case QRAlgorithm.Modified_Gram_Schmidt:
            {
                GramSchmidt.Modified(A, Q, R);
                break;
            }

            case QRAlgorithm.Givens:
            {
                Givens.Orthogon(A, Q, R);
                break;
            }

            case QRAlgorithm.Householder:
            {
                Householder.Orthogon(A, Q, R);
                break;
            }
            }
        }
Example #5
0
        public void TestQRAlgorithm()
        {
            IMatrix T, U;

            QRAlgorithm.Factorize(A, out T, out U, 20);
        }