Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. eq = {x''[t] == -k*(x[t] - r[t]*Cos[theta]),
  2. r''[t] == -k*(r[t] - x[t]*Cos[theta])};
  3.  
  4. theta = Pi/4; k = 1;
  5. ic = {x[0] == 1, r[0] == 0, x'[0] == 0, r'[0] == 0};
  6. sol = NDSolve[{eq, ic}, {x, r}, {t, 0, 20}]
  7.  
  8. lst = Table[
  9. Graphics[{{Line[{{-1, 0}, {1, 0}}],
  10. Line[{{-Cos[theta], -Sin[theta]}, {Cos[theta],
  11. Sin[theta]}}]}, {Green,
  12. Line[{{x[t], 0}, {r[t]*Cos[theta], r[t]*Sin[theta]}} /.
  13. sol]}, {Red, PointSize[.05], Point[{x[t], 0} /. sol],
  14. Point[{r[t]*Cos[theta], r[t]*Sin[theta]} /. sol]}}], {t, 0,
  15. 10, .1}];
  16.  
  17. ListAnimate[lst]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement