Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*For example:*) L = [Theta][t]^2 + 2 Sin[[Theta]'[t]]
- D[L, [Theta]'[t] ]
- D[L, [Theta][t]]
- Needs["VariationalMethods`"]
- ClearAll[Global];
- variables = {Subscript[[Theta], 1][t], Subscript[[Theta], 2][t]};
- Subscript[r, 1] =
- Subscript[l,
- 1] {Sin[Subscript[[Theta], 1][t]], -Cos[
- Subscript[[Theta], 1][t]]};
- Subscript[r, 2] =
- Subscript[r, 1] +
- Subscript[l,
- 2] {Sin[Subscript[[Theta], 2][t]], -Cos[
- Subscript[[Theta], 2][t]]};
- lagrangian =
- Subscript[m, 1]/2 D[Subscript[r, 1], t].D[Subscript[r, 1], t] +
- Subscript[m, 2]/2 D[Subscript[r, 2], t].D[Subscript[r, 2], t] -
- g {0, 1}.(Subscript[m, 1] Subscript[r, 1] +
- Subscript[m, 2] Subscript[r, 2])
- eqs = EulerEquations[lagrangian, variables, t];
- initial = {Subscript[[Theta], 1][0] == Pi/2,
- Subscript[[Theta], 2][0] == Pi/2, Subscript[[Theta], 1]'[0] == 0,
- Subscript[[Theta], 2]'[0] == 0};
- Subscript[l, 1] = 1;
- Subscript[l, 2] = 1;
- Subscript[m, 1] = 1;
- Subscript[m, 2] = 1;
- g = 9.81;
- tMax = 20;
- sol = First[
- NDSolve[Join[eqs, initial],
- Head /@ variables,
- {t, 0, tMax}]
- ];
- D[lagrangian, [Theta]'[t]/.sol]
- D[lagrangian, [Theta][t]/.sol]
- D[lagrangian, [Theta]'[t]]
- D[lagrangian, [Theta][t]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement