Beispiel #1
0
        public _nMatrix ReturnInverseOfUpperTriangularMatrix(_nMatrix UpperTriangularMatrix)
        {
            var dimN = UpperTriangularMatrix.n;
            var D    = ReturnDiagonalInverseMatrix(UpperTriangularMatrix);
            var copy = CreateCopy(UpperTriangularMatrix);

            copy.ReplaceDiagonalEntriesWithZero(copy);
            copy = D.MultiplyByAnotherMatrix(copy);
            var identityClass = new nIdentityMatrix();
            var identity      = identityClass.ReturnNIdentityMatrix(dimN);

            var temp = copy.MultiplyByScalar(-1);

            for (int i = 2; i < dimN; i++)
            {
                AddNextPowerTermToMatrixSeries(copy, ref temp, i);
            }

            var inverse = identity.AddAnotherMatrix(temp);

            var copyPlus1 = identity.AddAnotherMatrix(copy);
            var Test      = inverse.MultiplyByAnotherMatrix(copyPlus1);

            //var realTest = D.ReturnDiagonalInverseMatrix(D).MultiplyByAnotherMatrix(D).MultiplyByAnotherMatrix(Test);
            return(inverse);
        }
Beispiel #2
0
        public _nMatrix ReturnDiagonalInverseMatrix(_nMatrix matrix)
        {
            int dim = matrix.n;
            var identityMatrixClass = new nIdentityMatrix();
            var inverseMatrix       = identityMatrixClass.ReturnNIdentityMatrix(dim);

            for (int i = 0; i < dim; i++)
            {
                inverseMatrix.SetValueAt(i + 1, i + 1, (1 / matrix.rows[i].vector[i]));
            }

            return(inverseMatrix);
        }