Guest User

Untitled

a guest
Apr 22nd, 2019
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ClearAll["Global`*"]
  2.  
  3. x[t_] := {{s[t] Cos[u[t]] + b/2 Sin[u[t]]}, {-s[t] Sin[u[t]] + b/2 Cos[u[t]]}}
  4.  
  5. T[t_] = Simplify[1/2 (m) Flatten[x'[t]].Flatten[x'[t]]] + 1/2 (1/12 m (l^2 + b^2) + m s[t]^2) u'[t]^2;
  6. V[t_] := m g (-s[t] Sin[u[t]] + b/2 Cos[u[t]])
  7.  
  8. L[t_] = Simplify[T[t] - V[t]];
  9.  
  10. << VariationalMethods`
  11.  
  12. eoms[t_] := Simplify[VariationalD[L[t], s[t], t]]
  13.  
  14. eomu[t_] := Simplify[VariationalD[L[t], u[t], t]]
  15.  
  16. solution = Block[{m = 0.1, l = 0.1, g = 9.81, b = 0.02},
  17. NDSolve[{eoms[t] == 0, eomu[t] == 0, u[0] == 0.0, s[0] == 0.01,
  18. s'[0] == 0.3, u'[0] == 0.1}, {u, s}, {t, 0, 10}]]
  19.  
  20. f[t_] = D[x[t][[1, 1]], {t, 2}] /. solution;
  21. Block[{m = 0.1, l = 0.1, g = 9.81, b = 0.02},
  22. Plot[f[t], {t, 0, 10}, AxesLabel -> {t, "ddot x"}, PlotRange -> All]]
RAW Paste Data