solarsystemanalysis.m 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. addpath("functions");
  2. clear all; clc; close all;
  3. G = 6.674e-11; m1 = 5.972e24; m2 = 1.989e30;
  4. initial_conditions = [1.496e11; 0; 0; 0; 0; 29780*1.2; 0; 0];
  5. t_span = [0 365.25*24*3600*10];
  6. f = @(t, Y) twoBodyODE(t, Y, G, m1, m2, 2, 1e21);
  7. options = odeset('RelTol', 1e-6, 'AbsTol', 1e-6);
  8. [t, Y] = ode45(f, t_span, initial_conditions, options);
  9. x1 = Y(:, 1);
  10. y1 = Y(:, 2);
  11. x2 = Y(:, 3);
  12. y2 = Y(:, 4);
  13. figure;
  14. xlim([min([x1;x2;y1;y2]), max([x1;x2;y1;y2])]);
  15. ylim([min([x1;x2;y1;y2]), max([x1;x2;y1;y2])]);
  16. step = 3;
  17. for i = 1:step:length(t)
  18. hold on;
  19. plot(x1(1:i), y1(1:i), "Color", "b");
  20. plot(x2(1:i), y2(1:i), "Color", "y");
  21. plot(x1(i), y1(i), "bo", "MarkerFaceColor", "b", "MarkerSize", 10);
  22. plot(x2(i), y2(i), "yo", "MarkerFaceColor", "y", "MarkerSize", 50);
  23. drawnow;
  24. pause(0.01);
  25. hold off;
  26. if i <= length(t) - step
  27. cla;
  28. end;
  29. end