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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| #include <cstdlib>
#include <iostream>
using namespace std;
void AfficherMatrice(float **M, int n){ //affiche une matrice de taille n*n
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
cout<< M[i][j] << "\t" ;
}
cout<< endl;
}
}
void AfficherVecteur (float *y, int n){ //affiche un vecteur de taille n
for (int i=0; i<n; i++){
cout<< y[i] << "\t";
}
cout<<endl;
}
void MTI(float **M, int n){ // matrice triangulaire inférieure
for(int i=0; i<n; i++){
for (int j=0; j<=i; j++){
cout<<M[i][j]<< "\t";
}
cout<<endl;
}
}
float Somme(float **M, float *x, int i, int j){ // M.x
float S=0;
for (i=1; i<j;i++){
S+=M[j][i]*x[i];
}
}
void SystMatTI (float **M, float *b, float *x, int n){ //trouver x tel que Mx=b avec M tiangulaire inférieure
x[1]=b[1]/M[1][1];
for (int j=2; j<=n; j++){
x[j]=(b[j]- Somme(M,x,1,j-1))/M[j][j];
}
}
int main(int argc, char *argv[])
{
int n;
cout << "entrer la valeur de n" <<endl;
cin>>n;
float **A=NULL;
A= new float*[n];
for (int i=0; i<n; i++){
A[i]= new float[i+1];
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
cout<< "Entrer A" <<i+1<<","<<j+1<<endl;
cin>> A[i][j];
}
}
AfficherMatrice(A,n);
cout<<endl;
MTI(A,n);
float *x;
x=new float [n];
float *b=NULL;
b= new float [n];
for (int i=0; i<n; i++){
cout<< "Entrer b" <<i+1<< endl;
cin>>b[i];
}
AfficherVecteur(b,n);
cout<<endl;
SystMatTI(A,b,x,n);
cout<<endl;
for (int i=0; i<n; i++){
delete []A[i];
}
delete []A;
delete []b;
delete []x;
x=NULL;
system("PAUSE");
return EXIT_SUCCESS;
} |
Partager