j'ai un code qui inverse une matrice et je veux l'appliquer sur plusieurs matrices
je n'arrive pas à mettre à l'entrée de la fonction des matrices, je ne sais pas si il faut mettre des pointeurs doubles que je ne maitrise pas, si vous pouvez me faire un exemple avec la fonction : int MethodeGauss() et le probleme c'est que je dois récupérer la matrice de sortie de cette fonction
je vous remercie bcp pour votre aide
#include <stdio.h>
#include <stdlib.h>
#define t 3
float matId[t][t];
float mat1[t][t] = {{-3,5,6},{-1,2,2},{1,-1,-1}};
float NewMat[t][2*t];
void afficherMatrice()
{
int i,j;
for (i=0;i<t;i++)
{
for (j=0;j<t;j++)
{
printf("%f ",mat1[i][j]);
}
printf("\n" );
}
}
void afficherMatriceIdentite()
{
int i,j;
for (i=0;i<t;i++)
{
for (j=0;j<t;j++)
{
printf("%f ",matId[i][j]);
}
printf("\n" );
}
}
void afficherMatriceInverse()
{
int i,j;
float elem;
for (i=0;i<t;i++)
{
for (j=t;j<2*t;j++)
{
printf("%f ",NewMat[i][j]);
}
printf("\n" );
}
}
void creerMatriceId()
{
int i,j;
for (i=0;i<t;i++)
{
for (j=0;j<t;j++)
{
if (i==j)
{
matId[i][j] = 1;
}
else
{
matId[i][j] = 0;
}
}
}
}
void definirNouvelleMatrice()
{
int i,j;
i=j=0;
for (i=0;i<t;i++)
{
for (j=0;j<2*t;j++)
{
if (j<t)
{
NewMat[i][j] = mat1[i][j];
}
else
{
NewMat[i][j] = matId[i][j-t];
}
}
}
}
int MethodeGauss()
{
int inversible = 1;
int k,i,colonne,colonnebis;
float var,var1;
k=0;
while((inversible == 1)&&(k<t))
{
if (NewMat[k][k] != 0)
{
var = NewMat[k][k];
for (colonne=0;colonne<2*t;colonne++)
{
NewMat[k][colonne] = NewMat[k][colonne]/var; //Normalisation de la ligne contenant l'élément diagonal
}
for (i=0;i<t;i++)
{
if (i != k)
{
var1=NewMat[i][k];
for (colonnebis=0;colonnebis<2*t;colonnebis++)
{
NewMat[i][colonnebis] = NewMat[i][colonnebis] - NewMat[k][colonnebis]*var1;
}
}
}
k++;
}
else
{
inversible = 0;
}
}
return inversible;
}
void modifierMatrice()
{
creerMatriceId();
definirNouvelleMatrice();
}
int main ()
{
printf("debut\n" );
afficherMatrice();
modifierMatrice();
if (MethodeGauss() == 1)
{
printf("Matrice inverse\n" );
afficherMatriceInverse();
}
else
{
printf("La matrice n'est pas inversible\n" );
}
printf("tout c'est bien termine\n" );
system("PAUSE");
return 0;
}