|
|
@@ -0,0 +1,56 @@
|
|
|
+addpath("functions");
|
|
|
+clear all; clc; close all;
|
|
|
+
|
|
|
+G = 1; m1 = 1; m2 = 1; m3 = 1;
|
|
|
+initial_conditions = [ ...
|
|
|
+ 1, 0, ... % x1, y1
|
|
|
+ -0.5, sqrt(3)/2, ... % x2, y2
|
|
|
+ -0.5, -sqrt(3)/2, ... % x3, y3
|
|
|
+ 0, -0.5, ... % vx1, vy1
|
|
|
+ sqrt(3)/2, 0.25, ... % vx2, vy2
|
|
|
+ -sqrt(3)/2, 0.25 ... % vx3, vy3
|
|
|
+];
|
|
|
+figure_eight_conditions = [ ...
|
|
|
+ -0.97000436, 0.24308753, ... % x1, y1
|
|
|
+ 0.97000436, -0.24308753, ... % x2, y2
|
|
|
+ 0, 0, ... % x3, y3
|
|
|
+ 0.466203685, 0.43236573, ... % vx1, vy1
|
|
|
+ 0.466203685, 0.43236573, ... % vx2, vy2
|
|
|
+ -0.93240737, -0.86473146 % vx3, vy3
|
|
|
+];
|
|
|
+
|
|
|
+t_span = [0 50];
|
|
|
+f = @(t, Y) threeBodyODE(t, Y, G, m1, m2, m3);
|
|
|
+options = odeset('RelTol', 1e-6, 'AbsTol', 1e-6);
|
|
|
+[t, Y] = ode45(f, t_span, initial_conditions, options);
|
|
|
+
|
|
|
+x1 = Y(:, 1);
|
|
|
+y1 = Y(:, 2);
|
|
|
+x2 = Y(:, 3);
|
|
|
+y2 = Y(:, 4);
|
|
|
+x3 = Y(:, 5);
|
|
|
+y3 = Y(:, 6);
|
|
|
+
|
|
|
+figure;
|
|
|
+xlim([min([x1;x2;x3]), max([x1;x2;x3])]);
|
|
|
+ylim([min([y1;y2;y3]), max([y1;y2;y3])]);
|
|
|
+step = 10;
|
|
|
+
|
|
|
+for i = 1:step:length(t)
|
|
|
+ hold on;
|
|
|
+
|
|
|
+ plot(x1(1:i), y1(1:i), "Color", "r");
|
|
|
+ plot(x2(1:i), y2(1:i), "Color", "b");
|
|
|
+ plot(x3(1:i), y3(1:i), "Color", "g");
|
|
|
+
|
|
|
+ plot(x1(i), y1(i), "ro", "MarkerFaceColor", "r", "MarkerSize", 15);
|
|
|
+ plot(x2(i), y2(i), "bo", "MarkerFaceColor", "b", "MarkerSize", 15);
|
|
|
+ plot(x3(i), y3(i), "go", "MarkerFaceColor", "g", "MarkerSize", 15);
|
|
|
+ drawnow;
|
|
|
+ pause(0.02);
|
|
|
+ hold off;
|
|
|
+
|
|
|
+ if i < length(t) - step
|
|
|
+ cla;
|
|
|
+ end;
|
|
|
+end
|