|
|
@@ -0,0 +1,34 @@
|
|
|
+addpath("functions");
|
|
|
+clear all; clc; close all;
|
|
|
+
|
|
|
+G = 6.674e-11; m1 = 5.972e24; m2 = 1.989e30;
|
|
|
+initial_conditions = [1.496e11; 0; 0; 0; 0; 29780; 0; 0];
|
|
|
+t_span = [0 365.25*24*3600*3];
|
|
|
+f = @(t, Y) twoBodyODE(t, Y, G, m1, m2);
|
|
|
+[t, Y] = ode45(f, t_span, initial_conditions);
|
|
|
+
|
|
|
+x1 = Y(:, 1);
|
|
|
+y1 = Y(:, 2);
|
|
|
+x2 = Y(:, 3);
|
|
|
+y2 = Y(:, 4);
|
|
|
+
|
|
|
+figure;
|
|
|
+xlim([min([x1;x2]), max([x1;x2])]);
|
|
|
+ylim([min([y1;y2]), max([y1;y2])]);
|
|
|
+
|
|
|
+for i = 1:length(t)
|
|
|
+ hold on;
|
|
|
+
|
|
|
+ plot(x1(1:i), y1(1:i), "Color", "b");
|
|
|
+ plot(x2(1:i), y2(1:i), "Color", "y");
|
|
|
+
|
|
|
+ plot(x1(i), y1(i), "bo", "MarkerFaceColor", "b", "MarkerSize", 10);
|
|
|
+ plot(x2(i), y2(i), "yo", "MarkerFaceColor", "y", "MarkerSize", 50);
|
|
|
+ drawnow;
|
|
|
+ pause(0.01);
|
|
|
+ hold off;
|
|
|
+
|
|
|
+ if i < length(t)
|
|
|
+ cla;
|
|
|
+ end;
|
|
|
+end
|