Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. (*For example:*) L = [Theta][t]^2 + 2 Sin[[Theta]'[t]]
  2. D[L, [Theta]'[t] ]
  3. D[L, [Theta][t]]
  4.  
  5. Needs["VariationalMethods`"]
  6. ClearAll[Global];
  7. variables = {Subscript[[Theta], 1][t], Subscript[[Theta], 2][t]};
  8. Subscript[r, 1] =
  9. Subscript[l,
  10. 1] {Sin[Subscript[[Theta], 1][t]], -Cos[
  11. Subscript[[Theta], 1][t]]};
  12. Subscript[r, 2] =
  13. Subscript[r, 1] +
  14. Subscript[l,
  15. 2] {Sin[Subscript[[Theta], 2][t]], -Cos[
  16. Subscript[[Theta], 2][t]]};
  17.  
  18. lagrangian =
  19. Subscript[m, 1]/2 D[Subscript[r, 1], t].D[Subscript[r, 1], t] +
  20. Subscript[m, 2]/2 D[Subscript[r, 2], t].D[Subscript[r, 2], t] -
  21. g {0, 1}.(Subscript[m, 1] Subscript[r, 1] +
  22. Subscript[m, 2] Subscript[r, 2])
  23. eqs = EulerEquations[lagrangian, variables, t];
  24.  
  25. initial = {Subscript[[Theta], 1][0] == Pi/2,
  26. Subscript[[Theta], 2][0] == Pi/2, Subscript[[Theta], 1]'[0] == 0,
  27. Subscript[[Theta], 2]'[0] == 0};
  28.  
  29. Subscript[l, 1] = 1;
  30. Subscript[l, 2] = 1;
  31. Subscript[m, 1] = 1;
  32. Subscript[m, 2] = 1;
  33. g = 9.81;
  34. tMax = 20;
  35.  
  36. sol = First[
  37. NDSolve[Join[eqs, initial],
  38. Head /@ variables,
  39. {t, 0, tMax}]
  40. ];
  41.  
  42. D[lagrangian, [Theta]'[t]/.sol]
  43. D[lagrangian, [Theta][t]/.sol]
  44. D[lagrangian, [Theta]'[t]]
  45. D[lagrangian, [Theta][t]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement