coupled.ode 864 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # This example simulates two similar pendulums, coupled with a horizontal
  2. # spring. The motion is taken to be undamped.
  3. #
  4. # The plot shows the displacement of one of the pendulums, as a function of
  5. # time. It illustrates how energy (e.g. maximum displacement) oscillates
  6. # back and forth between the two.
  7. # You may run this example by doing:
  8. #
  9. # ode < coupled.ode | graph -T X -C
  10. #
  11. # or alternatively, to get a real-time plot,
  12. #
  13. # ode < coupled.ode | graph -T X -C -x 0 50 -y -0.6 0.6
  14. # The equations are:
  15. # m*x1'' = - m*g*x1/l + k(x2 - x1)
  16. # m*x2'' = - m*g*x2/l - k(x2 - x1)
  17. xone' = vxone
  18. xtwo' = vxtwo
  19. vxone' = -g*xone/lone + k/mone * ( xtwo - xone)
  20. vxtwo' = -g*xtwo/ltwo - k/ltwo * ( xtwo - xone)
  21. k = 1
  22. g = 9.8 # acceleration due to gravity
  23. lone = 5
  24. ltwo = 5
  25. mone = 1
  26. mtwo = 1
  27. xone = 0.0
  28. xtwo = 0.3
  29. vxone = 0
  30. vxtwo = 0
  31. print t, xone
  32. step 0,50