ciaonataha
Messages postés6Date d'inscriptionvendredi 16 janvier 2009StatutMembreDernière intervention 4 mars 2009
-
21 janv. 2009 à 13:06
ciaonataha
Messages postés6Date d'inscriptionvendredi 16 janvier 2009StatutMembreDerniè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;
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());
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());
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();
}
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 :";