Beispiel #1
0
        /// <summary>
        /// Testa a deomposição sequencial relativa à matriz.
        /// </summary>
        /// <param name="target">O algoritmo.</param>
        /// <param name="matrix">A matriz.</param>
        private void TestDecomposition(
            ATriangDiagSymmMatrixDecomp <Fraction <int> > target,
            ISquareMathMatrix <Fraction <int> > matrix)
        {
            // Execução do algoritmo.
            var decomposition = target.Run(
                matrix);

            // Calcula o valor esperado.
            var matrixFactory       = new ArrayMathMatrixFactory <Fraction <int> >();
            var matrixMultiplicaton = new MatrixMultiplicationOperation <Fraction <int> >(
                matrixFactory,
                target.Field,
                target.Field);
            var actual = new TransposeMatrix <Fraction <int> >(decomposition.UpperTriangularMatrix)
                         as IMatrix <Fraction <int> >;

            actual = matrixMultiplicaton.Multiply(actual, decomposition.DiagonalMatrix);
            actual = matrixMultiplicaton.Multiply(actual, decomposition.UpperTriangularMatrix);

            // Valida as asserções.
            Assert.AreEqual(matrix.GetLength(0), actual.GetLength(0));
            Assert.AreEqual(matrix.GetLength(1), actual.GetLength(1));
            for (int i = 0; i < actual.GetLength(0); ++i)
            {
                for (int j = 0; j < actual.GetLength(1); ++j)
                {
                    Assert.AreEqual(matrix[i, j], actual[i, j]);
                }
            }
        }
        public void Run_TriangDiagSymmDecompNoInverse()
        {
            // Definição dos domínios e fábricas.
            var integerDomain = new IntegerDomain();
            var fractionField = new FractionField <int>(integerDomain);

            // Definição dos algoritmos.
            var target       = new TriangDiagSymmDecompInverseAlg <Fraction <int> >();
            var triangDecomp = new ParallelTriangDiagSymmMatrixDecomp <Fraction <int> >(fractionField);

            var arraySquareMatrixFactory = new ArraySquareMatrixFactory <Fraction <int> >();
            var arrayMatrixFactory       = new ArrayMathMatrixFactory <Fraction <int> >();

            // A matriz
            var matrix = this.GetSingularMatrix(integerDomain);

            // Cálculos
            var triangDiagDecomp = triangDecomp.Run(
                matrix);
            var inverseMatrix = target.Run(
                triangDiagDecomp,
                arraySquareMatrixFactory,
                fractionField);

            // Verificação dos valores.
            var expected = ArrayMathMatrix <Fraction <int> > .GetIdentity(3, fractionField);

            var matrixMultiplication = new MatrixMultiplicationOperation <Fraction <int> >(
                arrayMatrixFactory,
                fractionField,
                fractionField);
            var actual = matrixMultiplication.Multiply(inverseMatrix, matrix);

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    Assert.AreEqual(expected[i, j], actual[i, j]);
                }
            }
        }