# Trying to plot the trajectory of a particle using its Lagrangian; the plot is wrong [closed]

I'm trying to plot the trajectory of a particle given its potential energy (by finding its Euler Lagrange equation, etc., etc.). Here's the code:

r[t_] := {x[t], y[t]};
V := -4 \[Pi]^2 m/(Sqrt[r[t].r[t]]^(1 + \[Epsilon]));
T := 1/2 m r'[t].r'[t];
lag = T - V

SetAttributes[{\[Epsilon], m}, Constant]

EL[q_] := D[lag, q] - Dt[ D[lag, D[q, t]], t ] == 0
ellist = {EL[x[t]], EL[y[t]]}
iclist1 = {x[0] == x0, y[0] == y0}
iclist2 = {x'[0] == v0x, y'[0] == v0y}
eqnlist = Join[ellist, iclist1, iclist2]

m = 1;
x0 = 1;
y0 = 0;
v0x = -\[Pi];
v0y = 2 \[Pi];
\[Epsilon] = 0;

tmin = 0;
tmax = 100;
range = {{-30, 30}, {-30, 30}};
soln = NDSolve[eqnlist, {x, y}, {t, tmin, tmax},
MaxSteps -> Infinity][[1]]

traj := ParametricPlot[(r[t]) /. soln, {t, tmin, tmax},
PlotStyle -> {Red}, PlotRange -> range];
points[t_] := Graphics[{Blue, PointSize[0.03], Point[(r[t]) /. soln]}];
pix[t_] := Show[traj, points[t]]

Animate[pix[t], {t, tmin, tmax, tmax/100}, DisplayAllSteps -> True]


There aren't any errors showing up, but the plot is clearly wrong. Any ideas? I've been trying to figure out why it isn't working for ages, but nothing has fixed the problem.

(ignore the epsilon, I need to figure out the epsilon = 0 case first before switching its value up)

thanks so much!

-

## closed as off-topic by Kuba, Jens, m_goldberg, Yves Klett, rasherJun 8 at 21:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Jens, m_goldberg, Yves Klett, rasher
If this question can be reworded to fit the rules in the help center, please edit the question.

I'm not sure. The plot clearly isn't right though, it isn't an accurate trajectory despite all the physics being correct. –  user14834 Jun 8 at 11:30
Try using traj = ... instead of traj := ... –  Simon Woods Jun 8 at 11:32
that worked. thank you so much! –  user14834 Jun 8 at 13:44
In case you didn't know, the Euler-Lagrange equations can also be derived automatically by Mathematica with the VariationalMethods package, see Animation of double pendulum. –  Jens Jun 8 at 16:52