Fonction en c

Résolu
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013 - 15 mai 2011 à 00:10
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013 - 16 mai 2011 à 03:00
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;

}

6 réponses

znb Messages postés 4 Date d'inscription mercredi 16 février 2011 Statut Membre Dernière intervention 15 mai 2011
15 mai 2011 à 00:38
pour que ca soit applicable a des matrices de tailless diferentes, faut utiliser un pointeur sur un tableau 2 dimension .
3
cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 2
15 mai 2011 à 20:23
salut,


Il faut allouer de la memoire pour la matrice a1, ensuite tu pourras travailler dessus.

a1 = malloc(sizeof(float*)*i)
for (i 0; i < ?; i++) a1[i] malloc(sizeof(float)*j));

@++
3
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013
15 mai 2011 à 22:31
j'ai ces erreurs :

multiple definition of `main'
first defined here
ld returned 1 exit status
C:\Documents and Settings\brice\Bureau\test c\Makefile.win [Build Error] [Proje.exe] Error 1
3
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013
15 mai 2011 à 15:47
pourai-je avoir un exemple?

float **a1; (ou float *a1; je sai pas)
float a2[3][3]={{1,2,3},{4,5,6},{7,8,9}};

je dois faire quoi pour stocker les elements de a2 dans a1.
si je fais a1=a2;
ou
for(i..
for(j..
a1[i][j]=a2[i][j];
ca ne marche pas (erreurs de segmentation)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013
15 mai 2011 à 22:29
merci bien ca marche!!

je peux savoir pkoi ce prog ne marche pas

#include <stdio.h>
#include <stdlib.h>

int i, j;
static void vlaPrint(int taille1, int taille2, int table[taille1][taille2])
{
// Ecriture du tableau sur stdout
for ( i=0; i< taille1; i++)
{
for ( j=0; j< taille2; j++)
{
(void)printf("table[%d][%d] = %d\n", i, j, table[i][j]);
}
}
}

int main() {

int mat[2][2]={{1,2},{3,4}};
vlaPrint(2, 2,mat);

system("PAUSE");
return 0;
}
0
cs_badsha Messages postés 64 Date d'inscription vendredi 6 mai 2011 Statut Membre Dernière intervention 8 mai 2013
16 mai 2011 à 03:00
c bon le code marche c juste le logiciel qui merdai
0
Rejoignez-nous