Message Boards Message Boards


Plot the elliptical orbit from a Lagrangian?

Posted 2 months ago
2 Replies
1 Total Likes

Can anyone help me? I want to make the orbit ellipse. Please help me to fix my code.

lagrangian = 1/2 (x'[t]^2 + y'[t]^2) + 1/Sqrt[x[t]^2 + y[t]^2];
eq = Table[
  D[lagrangian, x1] - D[D[lagrangian, D[x1, t]], t] == 
   0, {x1, {x[t], y[t]}}];
sol = NDSolve[Join[eq, {x[0] == 1, x'[0] == 0, y[0] == 0, y'[0] == 1}], {x[t], 
   y[t]}, {t, 0, 5}];
ParametricPlot[{x[t], y[t]} /. sol[[1]], {t, 0, 5}]

enter image description here

2 Replies

it's easier to trouble shoot code if you look at it one line at a time instead of all at once. also, it's easier for other people to read the code if you use the first icon to paste in your code.

your orbit is circular because your initial velocity is perpendicular to the line from the origin to the starting position.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract