Class matrice

Résolu
ciaonataha Messages postés 6 Date d'inscription vendredi 16 janvier 2009 Statut Membre Dernière intervention 4 mars 2009 - 21 janv. 2009 à 13:06
ciaonataha Messages postés 6 Date d'inscription vendredi 16 janvier 2009 Statut Membre Dernière intervention 4 mars 2009 - 22 janv. 2009 à 17:02
J'ai ecrit le programme classe matrice...
mais j'ai les error comme:
"matrice.cpp:269: error: no match for 'operator=' in 'b = matrice::Mat_decomposer(a, 0, c)'
matrice.cpp:7: note: candidates are: matrice& matrice::operator=(const matrice&)
"
Comment je peux redresser une situation!!
Merci beaucoup!

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include
using namespace std;

class matrice {
private:
int m,n;
double **M;

public:
matrice(unsigned int,unsigned int);
int getcols() const;           //nbre de colonneslignes;
int getlignes() const;     //nbre de lignes;
void lire();
void ecrire();
void ecrire_inverse();
void setlignescols();
void Mat_transposer(matrice T);
void Mat_addition(matrice a1,matrice a2);
void Mat_produir(matrice a1,matrice a2);
void allouerMatrice(int l, int c);
void libererMatrice();
void Mat_identiter(int n);
void Mat_nulle(int n);
void Mat_multiplication_scalaire(matrice a, double k);
void Mat_decomposer(matrice a,int ib,int jb);
double Mat_determinant(matrice a);
void Mat_remplirMatrice(matrice a);
void Mat_coMat(matrice a);
void Mat_invMat(matrice a);
int Mat_moindreCarre(matrice a,matrice *u,matrice b);
};

matrice::matrice(unsigned int line=0,unsigned int col=0)
{
 n=line;
 m=col;
}

int matrice::getlignes()const
{
 return n;
}

int matrice::getcols()const
{
 return m;
}

void matrice::lire()
 {/*scanf la matrice M*/
  for(int i=0;i < getlignes();i++)
   {
     for(int j=0;j < getcols();j++)
      {
    printf("\n Matrice %dx%d :\n",i,j);
    scanf(" %lf",&M[i][j]);
      }
   }
 }

void matrice::ecrire()
 {/*affiche la matrice M*/
 printf("\n Matrice %dx%d :\n",getlignes(),getcols());
 for(int i=0; i < getlignes();i++)
  {
    for(int j=0;j < getcols();j++)
     {
       printf("%f\t",M[i][j]);
     }
   printf("\n");
  }
 }

void matrice::ecrire_inverse()
 {/*affiche la matrice d'inverse de M */
 printf("\n Matrice d'inverse %dx%d :\n",getlignes(),getcols());
 for (int j=0; j < getlignes(); j++)
  {
   for(int i=0; i< getcols(); i++)
    {
      printf("%f\t",M[i][j]);
    }
  printf("\n");
  }
 }

void matrice::allouerMatrice(int l, int c)
 {/*allouer une matrice de l lignes et c colonnes*/
  matrice a;
  a.n=l; a.m=c;
    a.M=(double**)malloc(l*sizeof(double*));
      for(int i=0;i<l;i++)
        {
      a.M[i]=(double *)malloc(c*sizeof(double ));
    }
 }

void matrice::libererMatrice()
 {/*liberer l'espace memoire occuper par la matrice*/
   
   for(int i=0; i<getlignes() ; i++) free(M[i]);
 }

void matrice::Mat_remplirMatrice(matrice a)
 {/*remplie la matrice a par saisie au clavier*/
   int i,j;
   printf("\nRemplissage de matrice %dx%d\n",a.getlignes(),a.getcols());
    
    for(i=0; ia.getlignes()-2)
                  {
                   y=0;
                   x++;
                  }
              }
         }
  b.libererMatrice();
 }

double matrice::Mat_determinant(matrice a)
 {/*renvoie le determinant de la matrice a*/
   double det=0.0;
   int signe=1;
   int c;
   matrice b(a.getlignes()-1,a.getcols()-1);
   b.allouerMatrice(a.getlignes()-1,a.getcols()-1);

   if (a.getlignes()==1)
    {
      return a.M[0][0];
    }
   for (c=0; c < a.getlignes();c++)
    {
    b=Mat_decomposer(a,0,c);
          det+=signe*a.M[0][c]*Mat_determinant(b);
              signe*=(-1);
    }
   return det;
  b.libererMatrice();
 }

void matrice::Mat_coMat(matrice a)
 {/* Fonction qui calcule la CoMatrice d'une matrice donné,pour l'utiliser dans le calcule de l'inverce */
   matrice b(a.getlignes(),a.getcols());
   matrice s(a.getlignes()-1,a.getcols()-1);
   s.allouerMatrice(a.getlignes()-1,a.getcols()-1);
   b.allouerMatrice(a.getlignes(),a.getcols());

   for(int i=0;is=Mat_decomposer(a,i,j);
           b.M[i][j]=Mat_determinant(s);
     }
    s.libererMatrice();            
    }
 }

void matrice::Mat_invMat(matrice a)
 {/* Fonction qui calcule l'inverce d'une matrice donné, et retourne NULL si la matrice est non inversible ( det == 0 ) */
    double det=Mat_determinant(a);
    matrice coA, t_coA,inv_A;
    
    if(det==0) printf("La matrice est non inversible");
          /* calculer la comatrice de la matrice */
      coA=Mat_coMat(a);
              /* calculer la comatrice transposer */
          t_coA=Mat_transposer(coA);
                   /* calculer la matrice inverse*/
               inv_A=Mat_multiplication_scalaire(t_coA,1/det);
    coA.libererMatrice();
    t_coA.libererMatrice();
    inv_A.libererMatrice();
}

int matrice::Mat_moindreCarre(matrice a,matrice *u,matrice b)
{/*resoudre A.U=B par la méthode de moindre carré
    renvoie 1 si le calcul est possible, 0 sinon*/
    matrice At,AtA,AtA_inv,AtA_inv_At;
    At=Mat_transposer(a);
    AtA=Mat_produir(At,a);
    AtA_inv=Mat_invMat(AtA);
    if(AtA_inv==0)printf("La matrice est non inversible");
    AtA_inv_At=Mat_produir(AtA_inv,At);
    *u=Mat_produir(AtA_inv_At,b);
    At.libererMatrice();
    AtA.libererMatrice();
    AtA_inv.libererMatrice();
    AtA_inv_At.libererMatrice();
    return 1;
}

int main() {

matrice a(3,3),b(3,3),s(3,3),t(3,3),p(3,3);
char choix;
cout<<"entrer les elements de la premiere matrice :";cout<<endl;
a.lire();
a.ecrire();
cout<<"entrer les elements de la seconde matrice";cout<<endl;
b.lire();
b.ecrire();cout<<"entrez votre choix : addition 1 ,transposee 2 multiplication = 3 : "; cin>>choix; cout <<endl;

if(choix=='1'){
cout<<"somme des deux matrices precedentes: "<<endl<<endl;
s.Mat_addition(a,b);
}
else
{
    if(choix=='2'){
cout<<"la transposee de la première matrice est:"<<endl<<endl;
t.Mat_transposer(a);
    }
else
{
    if(choix=='3'){
cout<<"produit des matrices" <<endl<<endl;
p.Mat_produir(a,b);
    }
else
{
cout<<"vous avez choisie une operation non definie :";

}

}
}
}

3 réponses

coucou747 Messages postés 12303 Date d'inscription mardi 10 février 2004 Statut Membre Dernière intervention 30 juillet 2012 44
22 janv. 2009 à 00:47
salut

le probleme vient du fait qu'il te manque un constructeur de copies

matrice(matrice m);
3
ciaonataha Messages postés 6 Date d'inscription vendredi 16 janvier 2009 Statut Membre Dernière intervention 4 mars 2009
22 janv. 2009 à 16:26
Merci..
Mais ca ne marche pas..
Peut-etre je dois utiliser operatere==
???
0
ciaonataha Messages postés 6 Date d'inscription vendredi 16 janvier 2009 Statut Membre Dernière intervention 4 mars 2009
22 janv. 2009 à 17:02
Pardon...
operator==
0
Rejoignez-nous