Message Boards Message Boards

Create a two body problem animation?

Posted 5 years ago

I am trying to animate the restricted three body problem in Mathematica (general case, not circular RTBP). But before, I need to solve differential equations of the two-body problem. I am facing some code errors with animation. Please, help me to fix this problem. Thanks a lot.

    f = 6.6743*10^(-11);

    m1 = 7.34767309*10^(22);
    m2 = 5.97219*10^(24);

    e = 0.0549006; a = 384748;
    p = a*(1 - e^2);
    c = Sqrt[ f*(m1 + m2)*p];


    eq1 = {x''[t] == - ((
    f*(m1 + m2) *x[t])/(x[t]^2 + y[t]^2 + z[t]^2)^3),
    y''[t] == -((
    f*(m1 + m2) *y[t])/(x[t]^2 + y[t]^2 + z[t]^2)^3),
    z''[t] == -((f*(m1 + m2) *z[t])/(x[t]^2 + y[t]^2 + z[t]^2)^3)};
    rul1 = {Subscript[r, j_] -> Sqrt[
    Subscript[x, j][t]^2 + Subscript[y, j][t]^2 + 
    Subscript[z, j][t]^2]};
    initial = {x[0] == 271811883, x'[0] == 0,
       y[0] == 271811883, y'[0] == 0,
       z[0] == 0, z'[0] == 0};

    sol = NDSolve[{eq1, initial}, {x[t], y[t], z[t]}, {t, 0, 50}];
obj[t1_] := 
  ParametricPlot[[{x[t], y[t], z[t]} /. sol], {t, 0, 50}, 
   AxesLabel -> {"x", "y", "z"}];
Manipulate[obj[t1], {t1, 0, 50}];
POSTED BY: Torebek Zhumabek
2 Replies

You have too many square brackets and ParameterPlot is 2D ParameterPlot3D is 3D so you would need that for 3 coordinates. Also t1 is never used anywhere inside of obj[]. It would look something like

ParametricPlot3D[{x[t], y[t], z[t]} /. sol, {t, 0, 50}, 
  AxesLabel -> {"x", "y", "z"}];

Also note that with your initial conditions and parameters the masses do not move so there is nothing to plot but a point.

I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer

Torebek,

Your syntax is wrong on NDSolve:

sol = NDSolve[Join[eq1, initial], {x, y, z}, {t, 0, 50}]

but you will have numerical issues. I'm guessing that it is due to the numbers you specified. (your initial conditions seem small compared to your masses.)

In version 12 there is a command that will do it for you. See NBodySimulation. You can verify against that or use it directly.

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract