コード例 #1
0
        /// <summary>
        /// The method works by using Gaussian elimination to covert the matrix A to a upper triangular matrix, U, and computes the
        /// determinant as the product_i(U_ii) * (-1)^c, where c is the number of row exchange operations that coverts A to U
        /// </summary>
        /// <param name="A">The matrix for which to calculate determinant</param>
        /// <returns>The determinant of A</returns>
        public static double GetDeterminant(IMatrix A)
        {
            int colCount = A.ColCount;
            int rowCount = A.RowCount;

            Debug.Assert(colCount == rowCount);

            double det = 1;

            int     rowExchangeOpCount = 0;
            IMatrix C = GaussianElimination.GetEchelonForm(A, out rowExchangeOpCount);

            foreach (int c in C.ColKeys)
            {
                det *= C[c, c];
            }

            return(det * (rowExchangeOpCount % 2 == 0 ? 1 : -1));
        }
コード例 #2
0
        public RowSpace(IMatrix A)
        {
            int numRowExOperations = 0;

            mEchelonA = GaussianElimination.GetEchelonForm(A, out mM, out numRowExOperations);
        }