Exemple #1
0
        public double DeterminantRecur()
        {
            if (lignes != colonnes)
            {
                throw new Exception("Dimension error");
            }

            if (lignes == 1)
            {
                return(tableau[0, 0]);
            }

            if (lignes == 2)
            {
                return(tableau[0, 0] * tableau[1, 1] - tableau[0, 1] * tableau[1, 0]);
            }

            double deter = 0;
            double signe = 1;

            for (int j = 0; j < colonnes; j++)
            {
                Matrice sousMat = GetDimInf(0, j);
                deter += signe * tableau[0, j] * sousMat.DeterminantRecur();
                signe  = -signe;
            }

            return(deter);
        }
Exemple #2
0
        public Matrice Comatrice()
        {
            if (lignes != colonnes)
            {
                throw new Exception("Dimension error");
            }

            Matrice comat = new Matrice(lignes, colonnes);

            if (lignes == 1)
            {
                comat[0, 0] = tableau[0, 0];
                return(comat);
            }



            double signeL = 1;

            for (int i = 0; i < lignes; i++)
            {
                double signeC = signeL; // changement de signe de ligne ne dépend pas de changemetn de colonne
                for (int j = 0; j < colonnes; j++)
                {
                    Matrice sousMat = GetDimInf(i, j);
                    comat[i, j] = signeC * sousMat.DeterminantRecur();
                    signeC      = -signeC;
                }
                signeL = -signeL;
            }


            return(comat);
        }