Пример #1
0
        public Matrix invert()
        {
            Matrix mat  = clone();
            Matrix edin = Matrix.GetE2Matrix(row);

            double N1 = 0, NInf = 0;
            Matrix inv = clone();


            for (int i = 0; i < row; i++)
            {
                double colsum = 0, rowsum = 0;
                for (int j = 0; j < col; j++)
                {
                    rowsum += Math.Abs(inv.matrix[i, j]);
                    colsum += Math.Abs(inv.matrix[j, i]);
                }
                N1   = Math.Max(colsum, N1);
                NInf = Math.Max(rowsum, NInf);
            }

            inv = inv.transpose();
            inv = inv.productNumber(1 / (N1 * NInf));

            while (Math.Abs((mat * inv).getGaussDet() - 1) >= EPS)
            {
                Matrix prev = inv.clone();
                inv = mat * prev;
                inv = inv.productNumber(-1);
                inv = inv + edin;
                inv = prev * inv;
            }

            return(inv);
        }