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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 | % Distance Terre-Soleil = 151e6 km
% Vitesse de la Terre = 107217 km/h
% Vitesse de jupiter = 47006 km/h
% Masse du Soleil = 1.989e30 kg
% Masse de la Terre = 5.972e24 kg
% Masse de la Lune = 0.0123 mT
% Distance T-L = 0.00257 u.a.
% Vitesse de la lune = 3679.2 km/h + vT = 110896.2 km/h = 1.0343 vT
temps=10000001
pas=1e-5
X=zeros(2,2,3);
V=zeros(2,2,3);
XS=zeros(2,2);
VS=zeros(2,2);
% Adimensionnement des paramètres
d_ST=1 ; % Distance adim
mS=1 ; % Masse adim
mT=5.972e24/1.989e30; % masse Terre adim
vT=1 ; % Vitesse adim
G=6.67e-11*1.989e30/(150e9 * (29783)^2) ;%G*mS/d_ST*vT² constante de gravitation adim
% Conditions initiales
X(:,1,1)=[d_ST ; 0] ;
V(:,1,1)=[0 ; vT ] ;
mA= mT ;
X(:,1,2)=[(1+0.00257)*d_ST ; 0] ;
V(:,1,2)=[0 ; 1.0343*vT] ;
mB= 0.0123*mT ;
X(:,1,3)=[5.3*d_ST ; 0] ;
V(:,1,3)=[0 ; 0.4384*vT ] ;
mC= 313*mT ;
XS(:,1)=[0 ; 0] ;
VS(:,1)=[0 ; 0.01*vT] ;
mS= mS ;
dSA=((X(1,1,1)-XS(1,1))^2+(X(2,1,1)-XS(2,1))^2)^(1/2);
dSB=((X(1,1,2)-XS(1,1))^2+(X(2,1,2)-XS(2,1))^2)^(1/2);
dSC=((X(1,1,3)-XS(1,1))^2+(X(2,1,3)-XS(2,1))^2)^(1/2);
dAB=((X(1,1,1)-X(1,1,2))^2+(X(2,1,1)-X(2,1,2))^2)^(1/2);
dAC=((X(1,1,1)-X(1,1,3))^2+(X(2,1,1)-X(2,1,3))^2)^(1/2);
dBC=((X(1,1,2)-X(1,1,3))^2+(X(2,1,2)-X(2,1,3))^2)^(1/2);
tic
fdata=fopen('3planetes.dat', 'w+')
fprintf(fdata, '%f ', X(:,1,:)); % 6 colonnes
fprintf(fdata, '%f ', XS(:,1)); % 2 colonnes
fprintf(fdata, '%f ', dSA); % 1 colonnes
fprintf(fdata, '%f ', dSB); % 1 colonnes
fprintf(fdata, '%f ', dSC); % 1 colonnes
fprintf(fdata, '%f ', dAB); % 1 colonnes
fprintf(fdata, '%f ', dAC); % 1 colonnes
fprintf(fdata, '%f ', dBC); % 1 colonnes
fprintf(fdata, '\n');
for t=2:temps
%% Déplacement de A
V(:,2,1)=V(:,1,1) - G * pas * ( mS*(X(:,1,1)-XS(:,1))/(dSA)^3 + mB*(X(:,1,1)-X(:,1,2))/(dAB)^3 + mC*(X(:,1,1)-X(:,1,3))/(dAC)^3 ) ;
X(:,2,1)=X(:,1,1) + V(:,1,1)*pas;
%% Déplacement de B
V(:,2,2)=V(:,1,2) - G * pas * ( mS*(X(:,1,2)-XS(:,1))/(dSB)^3 + mA*(X(:,1,2)-X(:,1,1))/(dAB)^3 + mC*(X(:,1,2)-X(:,1,3))/(dBC)^3 ) ;
X(:,2,2)=X(:,1,2) + V(:,1,2)*pas;
%% Déplacement de C
V(:,2,3)=V(:,1,3) - G * pas * ( mS*(X(:,1,3)-XS(:,1))/(dSC)^3 + mA*(X(:,1,3)-X(:,1,1))/(dAC)^3 + mB*(X(:,1,3)-X(:,1,2))/(dBC)^3 ) ;
X(:,2,3)=X(:,1,3) + V(:,1,3)*pas;
%% Déplacement de S
VS(:,2)=VS(:,1) - G * pas * ( mA*(XS(:,1)-X(:,1,1))/(dSA)^3 + mB*(XS(:,1)-X(:,1,2))/(dSB)^3 + mC*(XS(:,1)-X(:,1,3))/(dSC)^3 ) ;
XS(:,2)=XS(:,1) + VS(:,1)*pas;
%% Distance entre les astres
dSA=((X(1,2,1)-XS(1,2))^2+(X(2,2,1)-XS(2,2))^2)^(1/2);
dSB=((X(1,2,2)-XS(1,2))^2+(X(2,2,2)-XS(2,2))^2)^(1/2);
dSC=((X(1,2,3)-XS(1,2))^2+(X(2,2,3)-XS(2,2))^2)^(1/2);
dAB=((X(1,2,1)-X(1,2,2))^2+(X(2,2,1)-X(2,2,2))^2)^(1/2);
dAC=((X(1,2,1)-X(1,2,3))^2+(X(2,2,1)-X(2,2,3))^2)^(1/2);
dBC=((X(1,2,2)-X(1,2,3))^2+(X(2,2,2)-X(2,2,3))^2)^(1/2);
%% Ecriture tous les 500 pas de temps uniquement
if mod(t, 500)==1
fprintf(fdata, '%f ', X(:,2,:));
fprintf(fdata, '%f ', XS(:,2));
fprintf(fdata, '%f ', dSA);
fprintf(fdata, '%f ', dSB);
fprintf(fdata, '%f ', dSC);
fprintf(fdata, '%f ', dAB);
fprintf(fdata, '%f ', dAC);
fprintf(fdata, '%f ', dBC);
fprintf(fdata, '\n');
end
% Décalage des posisitions des matrices. (n devient n-1)
X(:,1,:)=X(:,2,:);
V(:,1,:)=V(:,2,:);
XS(:,1)=XS(:,2);
VS(:,1)=VS(:,2);
end
fclose(fdata)
toc
|