je mets mon EDO.cpp et mon EDO.h
.cpp :
Vecteur EDO1Systeme::rk2(double x0, Vecteur y0, double xf)
{
Vecteur y;//vecteur
int D=4;
double x; //temps
y = y0;//position initiale
double h = (xf - x0)/N;//h le pas, en temps. t0=0 ; tf=31 558 144 secondes ; N=30 000
Vecteur k1(D), k2(D);//vecteurs
for (int i = 1 ; i < N+1 ; i++)
{
x = x0 + i*h;
k1 = h * evalyp(x, y);
k2 = h * evalyp(x + h/2, y + k1/2);
y = y + k2;//vecteur P
stocke (i, x, y, evalyp(x, y));
}
cout<<"y= "<<y<<endl;
return y;
}
EDO1Systeme::EDO1Systeme(int Di,int Ni) : D(Di),N(Ni)
{
yf.redim(D);
// On alloue les tableaux servant a stocker x, y, y', z, z' pour chaque point.
xtab=new double [N+1]; // [0..N] => N+1
ytab=new Vecteur [N+1];
yptab=new Vecteur [N+1];
for (int i=0;i<N+1;i++) {
ytab[i].redim(D);
yptab[i].redim(D);
}
}
EDO1Systeme::~EDO1Systeme()
{
// Merci de nettoyer derriere soi...
delete[] xtab;
delete[] ytab;
}
void EDO1Systeme::stocke(int i,double x, Vecteur y, Vecteur yp)
{
xtab[i]=x;
ytab[i]=y;
yptab[i]=yp;
}
void EDO1Systeme::ecrirexyz(const char * nom_fichier)
{
ofstream fichier( nom_fichier );
// On ecrit tout en 5 colonnes dans un fichier
for (int i= 0 ; i < N+1 ; i++)
{
fichier << setw(10) <<"t= "<< setprecision(12) << xtab[i]
<< setw(10) << "Px = "<< setprecision(12) << ytab[i](1)
<< setw(10) << "Py = "<< setprecision(12) << ytab[i](3)
<< setw(10) << "Vx = "<< setprecision(12) << yptab[i](1)
<< setw(10) << "Vy = "<< setprecision(12) << yptab[i](3)
<< setw(10) << "Ax = "<< setprecision(12) << yptab[i](2)
<< setw(10) << "Ay = "<< setprecision(12) << yptab[i](4)<<endl;
}
fichier << endl;
fichier.close();
}
void EDO1Systeme::ecrirexyzROOT(const char * nom_fichier, int G)
{
TCanvas c1("c1","dessin",1000,1000);
//TGraph graphe_new(10000); // crée un graphe de nom graphe_new avec 10000 points
TGraph graphe_SystemeSolaire (10000); // crée un graphe de nom graphe_new avec 10000 points
graphe_SystemeSolaire.SetName("Systeme Solaire"); // nom sans espace (sous lequel il sera sauvé)
graphe_SystemeSolaire.SetTitle("Systeme Solaire"); // donne un titre au graphe graphe_sinus
graphe_SystemeSolaire.SetMarkerColor(2); // donne une couleur (rouge) aux points du graphe
for(int i=0; i<N; i++)
{
graphe_SystemeSolaire.SetPoint(i-1,ytab[i](1),ytab[i](3)); // donne les coordonnées x (abscisse) et (ordonnée) sin(x) au ieme point.
}
graphe_SystemeSolaire.Draw("LP"); //A pour nouveau dessin, L pour avoir une ligne entre les points, P pour voir les points
(graphe_SystemeSolaire.GetXaxis())->SetTitle("X"); // on ajoute l'information sur l'axe X
(graphe_SystemeSolaire.GetYaxis())->SetTitle("Y"); // on ajoute l'information sur l'axe Y
graphe_SystemeSolaire.Write();
c1.SaveAs("Systeme Solaire.png");
}
double EDO2::evalys(double x, Vecteur y)
{
double n=-6.67*pow(10, -11)*1.989*pow(10,30);
double m=sqrt(y(1)*y(1)+y(3)*y(3));
return (n*y(1))/pow(m, 3);
}
double EDO2::evalyss(double x, Vecteur y)
{
double n=-6.67*pow(10, -11)*1.989*pow(10,30);
double m=sqrt(y(1)*y(1)+y(3)*y(3));
return (n*y(3))/pow(m, 3);
}