-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
82 lines (77 loc) · 2.13 KB
/
main.cpp
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
#include "projet.h"
int main(){
int n, m;
cout<<"Entrer n et m pour définir le maillage de la matrice du Laplacien 2D."<<endl;
cin>>n>>m;
n = n*m;
n = sqrt ( n );
vector< vector < double > > A (n*n,vector < double > (n*n));
A=matrice_laplacien(n);
cout<<""<<endl;
cout<<"La matrice du Laplacien 2D :"<<endl;
for(int i=0;i<n*n;i++){
for(int j=0;j<n*n;j++){
cout<< A[i][j] <<" ";
}cout<<endl;
}
//Cholesky :
cout<< setw(15)<<""<<endl;
cout<< setw(20) << " "
<< setw(15) << "Exécution de l'algorithme de Cholesky :" <<endl;
if (symetrique(A)==0){
cout<<"La matrice A n'est pas symétrique : Cholesky ne peut pas être appliqué."<<endl;
}
else {
cout<<"La matrice A symetrique : on peut appliquer Cholesky."<<endl;
cholesky(A);
}
//Relaxation
cout<< setw(15)<<""<<endl;
cout<< setw(20)<< ""
<< setw(15)<<"Execution de la relaxation :"<<endl;
vector<double> B(n*n);
int j;
for (int i=0;i<n*n;i++){
if( (i-n) > 0 ){
j = i - n ;
B[i] = ( i*i + j*j ) * sin(i*j);
}
else{
j=0;
B[i] = ( i*i + j*j ) * sin(i*j);;
}
}
cout << "Vecteur B : ";
for (int i=0;i<n*n;i++){
cout<< B[i]<<" ";
}cout<<" "<<endl;
Relaxation_methode_creux(A,B);
//A = LU :
cout<< setw(15)<<""<<endl;
cout<< setw(20)<< ""
<< setw(15)<<"Execution de A = L * U :"<<endl;
vector<vector<double>>L(n*n,vector<double>(n*n));
vector<vector<double>>U(n*n,vector<double>(n*n,0));//U=0;
for(int i=0;i<n*n;i++){
L[i][i]=1; //L = Id(n)
}
clock_t debut, fin ;
debut = clock();
decomp_lu(A,L,U); //décomposition L U :
vector<double> x(n*n,0); //initialisation vecteur solution
re_sys_lu(A,B,x); //résolution du système Ax=b grâce à decomp_lu:
//temps CPU :
fin = clock();
double temps;
temps = ((double)fin-debut) / CLOCKS_PER_SEC;
cout<<"Temps CPU A = L * U: "<<temps<<endl;
//JACOBI :
cout<< setw(15)<<""<<endl;
cout<< setw(20)<< ""
<< setw(15)<<"Execution de JACOBI :"<<endl;
debut=clock();
Jacobi (A,B);
fin = clock();
temps = ((double)fin-debut) / CLOCKS_PER_SEC;
cout<<"Temps CPU Jacobi : "<<temps<<endl;
}