-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "FOM.h" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <iostream> | ||
#include <Eigen> | ||
|
||
using Eigen::MatrixXd; | ||
|
||
|
||
using namespace Eigen; | ||
using namespace std; | ||
|
||
//constructeur | ||
FOM::FOM(MatrixXd A,VectorXd b) : A_(A),b_(b) | ||
{ | ||
} | ||
//Méthode de arnoldi | ||
void FOM::Arnoldi(VectorXd u, MatrixXd v, MatrixXd H) | ||
{ | ||
int m=u.size(); | ||
VectorXd v1(m),w(m); | ||
v1=u/(u.norm()); | ||
double h; | ||
|
||
for (int j=0; j<m; j++) | ||
{ | ||
w=A_*v1; | ||
for (int k=0; k<m; k++) | ||
{ | ||
v(j,k)=v1[k]; | ||
} | ||
for (int i=0; i<j; i++) | ||
{ | ||
h=w.dot(v1); | ||
H(i,j)=h; | ||
w=w-h*v1; | ||
} | ||
H(j,j)=w.norm(); | ||
} | ||
|
||
} | ||
|
||
//gradient à pas optimal | ||
VectorXd FOM::Solve()const | ||
{ | ||
|
||
MatrixXd A=A_; | ||
int n = A.rows(); | ||
VectorXd x(n); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
x[i]=0.; | ||
|
||
} | ||
|
||
VectorXd r(n),b(b_); | ||
//cout<<b<<endl; | ||
r = b -A*x; | ||
VectorXd rSuivant(n); | ||
VectorXd xSuivant(n); | ||
int j = 0; | ||
double beta=r.norm(); | ||
int nb_iterat_=0; | ||
while (beta > pow(10,-10)) | ||
{ | ||
beta=r.norm(); | ||
nb_iterat_=nb_iterat_ +1; | ||
j++; | ||
} | ||
cout<<"le nombre d'itération : "<<nb_iterat_<<endl; | ||
cout<<"----------------Gradient à pas optimal------------------------"<<endl; | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef FOM_H | ||
#define FOM_H | ||
|
||
#include "Dense" | ||
#include <fstream> | ||
|
||
class FOM | ||
{ | ||
private: | ||
|
||
Eigen::MatrixXd A_; | ||
Eigen::VectorXd b_; | ||
|
||
|
||
public: | ||
FOM(Eigen::MatrixXd ,Eigen::VectorXd) ;//: A_(A), b_(b) { }; | ||
void Arnoldi(Eigen::VectorXd,Eigen::MatrixXd,Eigen::MatrixXd); //A devient Hm | ||
Eigen::VectorXd Solve()const; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "GradConj.h" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <iostream> | ||
#include <Eigen> | ||
|
||
using Eigen::MatrixXd; | ||
|
||
|
||
using namespace Eigen; | ||
using namespace std; | ||
|
||
//constructeur | ||
GradConj::GradConj(MatrixXd A,VectorXd b) : A_(A),b_(b) | ||
{ | ||
} | ||
|
||
|
||
//gradient conjugué | ||
VectorXd GradConj::Solve()const | ||
{ | ||
|
||
MatrixXd A=A_; | ||
int n = A.rows(); | ||
VectorXd x(n); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
x[i]=0.; | ||
|
||
} | ||
|
||
VectorXd r(n),b(b_),p(n); | ||
//cout<<b<<endl; | ||
r = b -A*x; | ||
p= r ; // calcul du residu | ||
double alpha; | ||
double gamma; | ||
VectorXd rSuivant(n); | ||
VectorXd xSuivant(n); | ||
VectorXd z(n); | ||
int j = 0; | ||
double beta=r.norm(); | ||
int nb_iterat_=0; | ||
while (beta > pow(10,-10)) | ||
{ | ||
z=A*p; | ||
alpha= (r.dot(r) ) / (z.dot(p)) ; | ||
xSuivant= x + alpha*p; | ||
rSuivant=r-alpha*z; | ||
gamma= (rSuivant.dot(rSuivant))/(r.dot(r)); | ||
p= rSuivant+ gamma*p; | ||
x=xSuivant ; | ||
//cout<<x<<endl; | ||
//cout<<"----------------------------------------"<<endl; | ||
r=rSuivant; | ||
beta=r.norm(); | ||
nb_iterat_=nb_iterat_ +1; | ||
j++; | ||
} | ||
cout<<nb_iterat_<<endl; | ||
cout<<"----------------Gradient conjugué------------------------"<<endl; | ||
return x; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
#ifndef GRADCONJ_H | ||
#define GRADCONJ_H | ||
|
||
#include "Dense" | ||
#include <fstream> | ||
|
||
class GradConj | ||
{ | ||
private: | ||
|
||
Eigen::MatrixXd A_; | ||
Eigen::VectorXd b_; | ||
|
||
|
||
public: | ||
GradConj(Eigen::MatrixXd ,Eigen::VectorXd) ;//: A_(A), b_(b) { }; | ||
Eigen::VectorXd Solve()const; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Gradpo.h" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <iostream> | ||
#include <Eigen> | ||
|
||
using Eigen::MatrixXd; | ||
|
||
|
||
using namespace Eigen; | ||
using namespace std; | ||
|
||
//constructeur | ||
Gradpo::Gradpo(MatrixXd A,VectorXd b) : A_(A),b_(b) | ||
{ | ||
} | ||
|
||
|
||
//gradient à pas optimal | ||
VectorXd Gradpo::Solve()const | ||
{ | ||
|
||
MatrixXd A=A_; | ||
int n = A.rows(); | ||
VectorXd x(n); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
x[i]=0.; | ||
|
||
} | ||
|
||
VectorXd r(n),b(b_); | ||
//cout<<b<<endl; | ||
r = b -A*x; | ||
double alpha; | ||
VectorXd rSuivant(n); | ||
VectorXd xSuivant(n); | ||
VectorXd z(n); | ||
int j = 0; | ||
double beta=r.norm(); | ||
int nb_iterat_=0; | ||
while (beta > pow(10,-10)) | ||
{ | ||
z=A*r; | ||
alpha= (r.dot(r) ) / (z.dot(r)) ; | ||
xSuivant= x + alpha*r; | ||
rSuivant=r-alpha*z; | ||
x=xSuivant ; | ||
//cout<<x<<endl; | ||
//cout<<"----------------------------------------"<<endl; | ||
r=rSuivant; | ||
beta=r.norm(); | ||
nb_iterat_=nb_iterat_ +1; | ||
j++; | ||
} | ||
cout<<"le nombre d'itération : "<<nb_iterat_<<endl; | ||
cout<<"----------------Gradient à pas optimal------------------------"<<endl; | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef GRADPO_H | ||
#define GRADPO_H | ||
|
||
#include "Dense" | ||
#include <fstream> | ||
|
||
class Gradpo | ||
{ | ||
private: | ||
|
||
Eigen::MatrixXd A_; | ||
Eigen::VectorXd b_; | ||
|
||
|
||
public: | ||
Gradpo(Eigen::MatrixXd ,Eigen::VectorXd) ;//: A_(A), b_(b) { }; | ||
Eigen::VectorXd Solve()const; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Compilateur utilisé | ||
CC=g++ | ||
|
||
# Options en mode optimisé - La variable DEBUG est définie comme fausse | ||
OPTIM_FLAG = -O3 -DNDEBUG -I /home/abdel_dakri/work/c++/eigen-3.3.8/Eigen/ -std=c++11 | ||
# Options en mode debug - La variable est DEBUG est définie comme vraie | ||
DEBUG_FLAG = -g -DDEBUG -I /home/abdel_dakri/work/c++/eigen-3.3.8/Eigen/ -std=c++11 | ||
|
||
# On choisit comment on compile | ||
CXX_FLAGS = $(DEBUG_FLAG) | ||
|
||
# Le nom de l'exécutable | ||
PROG = run | ||
|
||
# Les fichiers source à compiler | ||
SRC = main.cpp GradConj.cpp Gradpo.cpp Residumin.cpp FOM.cpp SDP.cpp | ||
|
||
# La commande complète : compile seulement si un fichier a été modifié | ||
$(PROG) : $(SRC) | ||
$(CC) $(SRC) $(CXX_FLAGS) -o $(PROG) | ||
# Évite de devoir connaitre le nom de l'exécutable | ||
all : $(PROG) | ||
|
||
# Supprime l'exécutable, les fichiers binaires (.o) et les fichiers | ||
# temporaires de sauvegarde (~) | ||
clean : | ||
rm -f *.o *~ $(PROG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# Solveur-lin-aire | ||
Gradient conjugué | ||
Gradient à pas optimal | ||
Résidu minimum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Residumin.h" | ||
#include <iostream> | ||
#include <math.h> | ||
#include <iostream> | ||
#include <Eigen> | ||
|
||
using Eigen::MatrixXd; | ||
|
||
|
||
using namespace Eigen; | ||
using namespace std; | ||
|
||
//constructeur | ||
Residumin::Residumin(MatrixXd A,VectorXd b) : A_(A),b_(b) | ||
{ | ||
} | ||
|
||
|
||
//Residu minimum | ||
VectorXd Residumin::Solve()const | ||
{ | ||
//init | ||
MatrixXd A=A_; | ||
int n = A.rows(); | ||
VectorXd x(n); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
x[i]=0.; | ||
|
||
} | ||
|
||
VectorXd r(n),b(b_); | ||
//cout<<b<<endl; | ||
r = b -A*x; | ||
double alpha; | ||
VectorXd rSuivant(n); | ||
VectorXd xSuivant(n); | ||
VectorXd z(n); | ||
int j = 0; | ||
double beta=r.norm(); | ||
int nb_iterat_=0; | ||
while (beta > pow(10,-10)) | ||
{ | ||
z=A*r; | ||
alpha= (r.dot(z) ) / (z.dot(z)) ; | ||
xSuivant= x + alpha*r; | ||
rSuivant=r-alpha*z; | ||
x=xSuivant ; | ||
//cout<<x<<endl; | ||
//cout<<"----------------------------------------"<<endl; | ||
r=rSuivant; | ||
beta=r.norm(); | ||
nb_iterat_=nb_iterat_ +1; | ||
j++; | ||
} | ||
cout<<"le nombre d'itération : "<<nb_iterat_<<endl; | ||
cout<<"----------------Résidu minimum------------------------"<<endl; | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef Residumin_H | ||
#define Residumin_H | ||
|
||
#include "Dense" | ||
#include <fstream> | ||
|
||
class Residumin | ||
{ | ||
private: | ||
|
||
Eigen::MatrixXd A_; | ||
Eigen::VectorXd b_; | ||
|
||
|
||
public: | ||
Residumin(Eigen::MatrixXd ,Eigen::VectorXd) ;//: A_(A), b_(b) { }; | ||
Eigen::VectorXd Solve()const; | ||
}; | ||
#endif |
Oops, something went wrong.