コード例 #1
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode d'obtebtention de la mineure
        public Matrice Mineure(int i, int j)
        {
            Matrice mineure    = new Matrice(new double[this.GetLength(0) - 1, this.GetLength(1) - 1]);
            Matrice mineureTmp = new Matrice(new double[this.GetLength(0), this.GetLength(1)]);

            for (int k = 0; k < this.GetLength(0); k++)
            {
                for (int l = 0; l < this.GetLength(1); l++)
                {
                    mineureTmp[k, l] = this[k, l];
                    if (l > j && k > i)
                    {
                        mineureTmp[k - 1, l - 1] = this[k, l];
                    }
                    else if (l > j)
                    {
                        mineureTmp[k, l - 1] = this[k, l];
                    }
                    else if (k > i)
                    {
                        mineureTmp[k - 1, l] = this[k, l];
                    }
                }
            }
            for (int k = 0; k < mineure.GetLength(0); k++)
            {
                for (int l = 0; l < mineure.GetLength(1); l++)
                {
                    mineure[k, l] = mineureTmp[k, l];
                }
            }
            //Console.WriteLine(mineure.AfficheMatrice());
            return(mineure);
        }
コード例 #2
0
        //Méthode de Cramer
        public Matrice TrouverXParCramer()
        {
            if (_matriceCarree.Determinant != 0)
            {
                int     n  = _matriceCarree.GetLength(0);
                Matrice X  = new Matrice((new double[n, 1]));
                Matrice AN = new Matrice(new double[n, n]);

                for (int i = 0; i < n; i++)
                {
                    AN = _matriceCarree.CopierMatrice();
                    for (int j = 0; j < n; j++)
                    {
                        AN[j, i] = _matrice1N[j, 0];
                    }
                    X[i, 0] = AN.Determinant / _matriceCarree.Determinant;
                }
                return(X);
            }

            else
            {
                Console.WriteLine("Déterminant de la matrice = 0, donc impossible d'utiliser la méthode de Cramer");
                return(new Matrice(new double[0, 0]));
            }
        }
コード例 #3
0
ファイル: Systeme.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //Méthode de Cramer
        public Matrice TrouverXParCramer()
        {
            if (_matriceCarree.Determinant != 0)
            {
                int n = _matriceCarree.GetLength(0);
                Matrice X = new Matrice((new double[n, 1]));
                Matrice AN = new Matrice(new double[n, n]);

                for (int i = 0; i < n; i++)
                {
                    AN = _matriceCarree.CopierMatrice();
                    for (int j = 0; j < n; j++)
                    {
                        AN[j, i] = _matrice1N[j, 0];
                    }
                    X[i, 0] = AN.Determinant / _matriceCarree.Determinant;
                }
                return X;
            }
            else
            {
                Exception e = new Exception("La matrice a un déterminant de 0");
                throw e;
            }
        }
コード例 #4
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode du produit matriciel multiple
        public Matrice FaireProduitMatriciel(out int operations, params Matrice[] matrices)
        {
            operations = 0;
            Matrice temp = this;

            for (int i = 0; i < matrices.Length; i++)
            {
                operations += temp.GetLength(0) * temp.GetLength(1) * matrices[i].GetLength(1);
                temp        = temp.FaireProduitMatriciel(matrices[i]);
            }
            return(temp);
        }
コード例 #5
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode du produit matriciel en commencant par la fin
        public Matrice FaireProduitMatricielParFin(out int operations, params Matrice[] matrices)
        {
            operations = 0;
            Matrice matriceA = this;
            Matrice temp     = this;

            for (int i = matrices.Length - 1; i == 1; i--)
            {
                operations += matrices[i - 1].GetLength(0) * matrices[i - 1].GetLength(1) * matrices[i].GetLength(1);
                temp        = matrices[i - 1].FaireProduitMatriciel(matrices[i]);
            }
            operations += matriceA.GetLength(0) * matriceA.GetLength(1) * temp.GetLength(1);
            temp        = matriceA.FaireProduitMatriciel(temp);
            return(temp);
        }
コード例 #6
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode du produit matriciel
        public Matrice FaireProduitMatriciel(Matrice matrice)
        {
            //si le nombre de colonnes de A est égal au nombre de lignes de B
            VerifierColonneAcommeLigneB(matrice);
            //if (VerifierColonneAcommeLigneB(matrice))
            //{

            var n = _matrice.GetLength(0);
            var p = matrice.GetLength(1);

            Matrice produitMatriciel = new Matrice(new double[n, p]);

            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < p; j++)
                {
                    produitMatriciel[i, j] = 0;
                    for (var z = 0; z < n; z++)
                    {
                        produitMatriciel[i, j] += _matrice[i, z] * matrice[z, j];
                    }
                }
            }
            // Console.WriteLine(produitMatriciel.AfficheMatrice());
            return(produitMatriciel);
            //}
            //else
            //{
            //    Console.WriteLine("Format de matrice incorrect");
            //    return new Matrice(new double[0, 0]);
            //}
        }
コード例 #7
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode d'addition de matrice
        public Matrice Additionner(Matrice matrice)
        {
            //if (VerifierFormatMatrice(matrice) == true)
            VerifierFormatMatrice(matrice);
            //{
            var addition = new Matrice(new double[_matrice.GetLength(0), _matrice.GetLength(1)]);

            for (var i = 0; i < matrice.GetLength(0); i++)
            {
                for (var j = 0; j < matrice.GetLength(1); j++)
                {
                    addition[i, j] = this[i, j] + matrice[i, j];
                }
            }

            return(addition);
        }
コード例 #8
0
 //constructeur
 public Systeme(Matrice matriceCarree, Matrice matrice1N)
 {
     if (matriceCarree.EstCarree && matrice1N.GetLength(1) == 1 && matriceCarree.GetLength(0) == matrice1N.GetLength(0))
     {
         _matriceCarree = matriceCarree;
         _matrice1N     = matrice1N;
     }
     else
     {
         Console.WriteLine("Format de matrice incorrect");
     }
 }
コード例 #9
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
 //méthode vérification prérequis multiplication
 public bool VerifierColonneAcommeLigneB(Matrice matrice)
 {
     if (_matrice.GetLength(1) == matrice.GetLength(0))
     {
         return(true);
     }
     else
     {
         Exception e = new Exception("Format de matrice incompatible pour multiplication");
         throw e;
     }
 }
コード例 #10
0
ファイル: Systeme.cs プロジェクト: AdamLemire/PIF1006_Devoir1
 //constructeur
 public Systeme(Matrice matriceCarree, Matrice matrice1N)
 {
     if (matriceCarree.EstCarree && matrice1N.GetLength(1) == 1 && matriceCarree.GetLength(0) == matrice1N.GetLength(0))
     {
         _matriceCarree = matriceCarree;
         _matrice1N = matrice1N;
     }
     else
     {
         Exception e = new Exception("Format de matrice incorrect pour créer un système d'équation");
         throw e;
     }
 }
コード例 #11
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode de vérification même format de matrice
        public bool VerifierFormatMatrice(Matrice matrice)
        {
            if (_matrice.GetLength(0) == matrice.GetLength(0) && _matrice.GetLength(1) == matrice.GetLength(1))
            {
                return(true);
            }

            else
            {
                Exception e = new Exception("Format de matrice incorrect");
                throw e;
            }
        }
コード例 #12
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode d'addition de matrice
        public Matrice Additionner(Matrice matrice)
        {
            //if (VerifierFormatMatrice(matrice) == true)
            VerifierFormatMatrice(matrice);
            //{
            var addition = new Matrice(new double[_matrice.GetLength(0), _matrice.GetLength(1)]);

            for (var i = 0; i < matrice.GetLength(0); i++)
            {
                for (var j = 0; j < matrice.GetLength(1); j++)
                {
                    addition[i, j] = this[i, j] + matrice[i, j];
                }
            }

            return(addition);
            //}
            //else
            //{
            //    Console.WriteLine("Format de matrice incorrect");
            //    return new Matrice(new double[0, 0]);
            //}
        }
コード例 #13
0
ファイル: Matrice.cs プロジェクト: AdamLemire/PIF1006_Devoir1
        //méthode du produit matriciel
        public Matrice FaireProduitMatriciel(Matrice matrice)
        {
            //si le nombre de colonnes de A est égal au nombre de lignes de B
            VerifierColonneAcommeLigneB(matrice);

            int n = _matrice.GetLength(0);
            int p = matrice.GetLength(1);
            int q = matrice.GetLength(0);

            Matrice produitMatriciel = new Matrice(new double[n, p]);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < p; j++)
                {
                    produitMatriciel[i, j] = 0;
                    for (int z = 0; z < q; z++)
                    {
                        produitMatriciel[i, j] += _matrice[i, z] * matrice[z, j];
                    }
                }
            }
            return(produitMatriciel);
        }