# Solve Euler Lagrange equation of motion DSolve

I'm trying to find Euler Lagrange equation of motion. then DSolve the equation for list of variable x1,x2,x3,x4

Here is my code:

Clear["Global*"]
Needs["VariationalMethods"]
n = 3;
ue[x_, t_, k_, n_] := (1/2)*Sum[Subscript[k, j]*(Subscript[x, j - 1][t] - Subscript[x, j][t])^2, {j, 1, n + 1}];
te[x_, t_, n_] := (1/2)*m*Sum[Derivative[1][Subscript[x, j]][t]^2, {j, 1, n}];
lg[x_, t_, k_, n_] := te[x, t, n] - ue[x, t, k, n];

Expand[EulerEquations[lg[x, t, k, n], Subscript[x, j][t], t]]
DSolve[%, Subscript[x, j][t], x]


Here is picture of my code

Corrected and runnable code:

Clear["Global*"]
Needs["VariationalMethods"]
n = 3;
ue[x_, t_, k_, n_] := (1/2)* Sum[k[j]*(x[j][t] - x[Mod[j + 1, n, 1]][t])^2, {j, 1, n}];
te[x_, t_, n_] := (1/2)*m*Sum[Derivative[1][x[j]][t]^2, {j, 1, n}];
lg[x_, t_, k_, n_] := te[x, t, n] - ue[x, t, k, n];
eq = Expand[
EulerEquations[lg[x, t, k, n], Table[x[j][t], {j, 1, n}], t]
];
DSolve[eq, Table[x[j][t], {j, 1, n}], t]


• Although it was not the source of the problem, I removed Subscript: It is nasty to read in input form and it does not do what you expect.
• You have to take care that your indices do not run out of bounds; this is why I shortened the sum and why I use Mod in the definition of ue.
• You have to submit all unknown functions as second argument to EulerEquations which is what I used Table for.
• The above holds true also dor DSolve. Moreover, the third argument of DSolve has to be from the domain of the differential equations; in this case, it has to be t, not x.