2
$\begingroup$

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

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

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]

Changes made:

  • 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.

$\endgroup$
2
  • $\begingroup$ Thanks a lot Sir, God Bless You. $\endgroup$
    – Alrubaie
    Commented Mar 11, 2019 at 15:02
  • $\begingroup$ You're welcome. $\endgroup$ Commented Mar 11, 2019 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.