1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| main()
{
float **K, *q, *f;
int nnoeuds;//lu ds le fichier d'entree
//Allocation de memoire
FILE * fp;
fp=fopen("erreur.txt","w");
K = (float **)calloc ( nnode , sizeof(float*) );
if( K == NULL )
{
fprintf(fp,"Allocation de K impossible");
exit(EXIT_FAILURE);
}
for(int j=0 ;j<nnode; j++ )
{
K[j] =(float *)calloc(nnode, sizeof(float));
if( K[j] == NULL )
{
fprintf(fp,"Allocation de a impossible");
exit(EXIT_FAILURE);
}
}
q =(float *)calloc(nnode, sizeof(float));
if( q == NULL )
{
fprintf(fp,"Allocation de q impossible");
exit(EXIT_FAILURE);
}
f =(float *)calloc(nnode, sizeof(float));
if( f == NULL )
{
fprintf(fp,"Allocation de f impossible");
exit(EXIT_FAILURE);
}
//creation de la matrice de rigidite et du vecteur chargement
matrig(K);
vectfor(f);
//Resolution de K*Q=F
gauss(K, q, f, nnoeuds);
return 0;
}
void gauss(float **a,float *x,float *b,int n)
{
float p,s;
int i,j,k;
for(k=0;k<n-1;k++)
{
if (a[k][k]==0)
{
printf("\n\n * Un pivot nul ! => methode de Gauss non applicable\n\n");
break;
}
for(i=k+1;i<n;i++) //triangularisation de la matrice
{
p=a[i][k]/a[k][k];
for (j=k;j<n;j++) a[i][j]=a[i][j]-p*a[k][j];
b[i]=b[i]-p*b[k];
}
}
for(i=n-1;i>=0;i--) //Résolution du systeme
{
s=0;
for(j=i+1;j<n;j++)s=s+a[i][j]*x[j];
x[i]=(b[i]-s)/a[i][i];
}
} |
Partager