Message Boards Message Boards

Numerical solution to Euler Lagrange equation

Posted 12 days ago

Hello. I am quite new to wolfram. would anyone mind sharing how to solve the euler lagrange equation (lowest equation), by inputting relevant unknowns from the equations above. Thank you.

enter image description here

POSTED BY: Ee Kin Chan
6 Replies

Here is a way:

r[n_, t_] = \[Zeta][t] UnitVector[3, 3] + 
   Sum[UnitVector[3, 1] l[i] Sin[\[Theta][i, t]] -
     UnitVector[3, 3] l[i] Cos[\[Theta][i, t]], {i, n}];
rdot[n_, t_] = D[r[n, t], t];
tt = 1/2 Sum[m[n] Total[rdot[n, t]^2], {n, nn}];
vv = -g*Sum[
    m[n] Sqrt[Total[r[n, t]^2]] Cos[\[Theta][n, t]], {n, nn}];
ll = tt - vv;
rr = 1/2 cd*Sum[Total[rdot[n, t]^2], {n, nn}];
eqLag[k_] = 
  D[D[ll, D[\[Theta][k, t], t]], t] - 
    D[ll, \[Theta][k, t]] == -D[rr, D[\[Theta][k, t], t]];
Block[{nn = 3, m = Function[1], l = Function[1], 
  cd = 1, \[Zeta] = Function[1], g = 1},
 eqs = Table[eqLag[n], {n, nn}] // Simplify; 
 initialData = 
  Table[D[\[Theta][k, t], {t, order}] == 1, {k, nn}, {order, 0, 
      1}] /. t -> 0 // Flatten;
 sols = NDSolveValue[Flatten@{eqs, initialData}, 
   Table[\[Theta][k, t], {k, nn}],
   {t, 0, 4},
   Method -> {"EquationSimplification" -> "Residual"}]]
POSTED BY: Gianluca Gorni
Posted 10 days ago

Hello. thank you very much for the help. may i know how i could manually enter the initial conditions (1. Angular displacement 2. angular velocity), instead of setting them equal to 1 like you did? thank you very much.

POSTED BY: Ee Kin Chan

Here is a way to type the initial data:

initialData =
 {\[Theta][1, 0] == 1, Derivative[0, 1][\[Theta]][1, 0] == 2,
  \[Theta][2, 0] == -1, Derivative[0, 1][\[Theta]][2, 0] == 4,
  \[Theta][3, 0] == 3, Derivative[0, 1][\[Theta]][3, 0] == 0}
POSTED BY: Gianluca Gorni
Posted 5 days ago

Thank you so much. Your contributions have been pivotal to my project :)

POSTED BY: Ee Kin Chan

This is a difficult task for a beginner. Here is an attempt:

r[n_, t_] = \[Zeta][t] {0, 0, 1} + 
   Sum[{1, 0, 0} l[i] Sin[\[Theta][i, t]] -
     {0, 0, 1} l[i] Cos[\[Theta][i, t]], {i, n}];
rdot[n_, t_] = D[r[n, t], t]
tt = 1/2 Sum[m[n] Total[rdot[n, t]^2], {n, nn}];
vv = -g*Sum[
    m[n] Sqrt[Total[r[n, t]^2]] Cos[\[Theta][n, t]], {n, nn}];
ll = tt - vv;
rr = 1/2 cd*Sum[Total[rdot[n, t]^2], {n, nn}];
eqLag[k_] = D[D[ll, D[\[Theta][k, t], t]], t] -
    D[ll, \[Theta][k, t]] == -D[rr, D[\[Theta][k, t], t]];
eqs = Block[{nn = 2, m = Function[1],
    l = Function[1], cd = 1, \[Zeta] = Function[1], g = 1},
   Table[eqLag[n], {n, nn}]] // Simplify
sols = NDSolveValue[{eqs,
   \[Theta][1, 0] == 1, \[Theta][2, 0] == 1,
   Derivative[0, 1][\[Theta]][1, 0] == 1,
   Derivative[0, 1][\[Theta]][2, 0] == 1},
  {\[Theta][1, t], \[Theta][2, t]}, {t, 0, 4}]
ParametricPlot[sols, {t, 0, 4}]
POSTED BY: Gianluca Gorni
Posted 11 days ago

Oh wow. thank you very much. may i know how i might increase nn to greater than 2. would i need to manually type the NDSolveValue equation to include all the thetas? Or is there a more general way to do it. Thank you.

POSTED BY: Ee Kin Chan
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