1
$\begingroup$

I'm trying to make an animation showing the path of the moon orbiting around the earth, but I'm having some trouble plotting it. For some reason, Mathematica doesn't give me any error messages but after running the animation it doesn't show anything. I'm trying to get a similar animation to this: enter image description here

Here is what I got so far:

m1 = 100/q;
m2 = 1/q;
eqn = {x2''[t] == 
   q*m2*(x1[t] - x2[t])/((x2[t] - x1[t])^2 + (y2[t] - y1[t])^2)^(3/2),
   y2''[t] == 
   q*m2*(y1[t] - y2[t])/((x2[t] - x1[t])^2 + (y2[t] - y1[t])^2)^(3/2),
   x1''[t] == 
   q*m2*(x2[t] - x1[t])/((x2[t] - x1[t])^2 + (y2[t] - y1[t])^2)^(3/2),
   y1''[t] == 
   q*m2*(y2[t] - y1[t])/((x2[t] - x1[t])^2 + (y2[t] - y1[t])^2)^(3/2)}

Testek = NDSolve[{eqn, x1'[0] == 0, x1[0] == 0, y1'[0] == 0, 
   y1[0] == 0, x2'[0] == 0, x2[0] == 100, y2'[0] == 1, 
   y2[0] == 0}, {x1, y1, x2, y2}, {t, 0, 200}]

Animate[ParametricPlot[
   Evaluate[{x1[t], y1[t], x2[t], y2[t]} /. Testek], {t, 0, 200}, 
   PlotRange -> All], {t, 0, 200}];
$\endgroup$
3
  • 4
    $\begingroup$ First, remove the semicolon ; in the last line because semicolon is used to hide the ouput. Secondly, you cannot have t be used twice in the last line; change the first {t, 0, 200} to {t, 0, tfin} and the second one to {tfin, 0, 200}. Thirdly, you should put another list around the coordinates in the last line: {{x1[t], y1[t]}, {x2[t], y2[t]}}. Fourthly, your differential equations are probably wrong because the solution is not periodic. $\endgroup$
    – Domen
    Commented Dec 29, 2021 at 19:01
  • 3
    $\begingroup$ Addendum to the fourth problem: Change m2 to m1 in the first two DEs. Your result should then look like this. $\endgroup$
    – Domen
    Commented Dec 29, 2021 at 19:14
  • $\begingroup$ Yes!Thank you so much for the help! $\endgroup$
    – Birgitt
    Commented Dec 29, 2021 at 19:23

0

Browse other questions tagged or ask your own question.