atwoods.ode 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # This example simulates a `swinging Atwood's machine'. An Atwood's
  2. # machine consists of two masses joined by a taut length of cord. The cord
  3. # is suspended from a pulley. The heavier mass (M) would normally win
  4. # against the lighter mass (m), and pull it upward. A `swinging' Atwood's
  5. # machine is an Atwood's machine with an additional degree of freedom: it
  6. # allows the lighter mass to swing back and forth in a plane, at the same
  7. # time as it is being drawn upward.
  8. # Let `a' denote the angle by which the cord extending to the lighter mass
  9. # deviates from the vertical. Let `l' denote the distance along the cord
  10. # between the pulley and the lighter mass. Then the system of differential
  11. # equations below will describe the evolution of the system.
  12. # You may run this example, with output to an X window in real time, by doing
  13. #
  14. # ode < atwoods.ode | graph -T X -x 9 11 -y -1 1 -m 0 -S 1
  15. #
  16. # The plot will trace out `l' and `ldot' (its time derivative). The `-m 0
  17. # -S 1' option requests that successive datapoints not be joined by line
  18. # segments, but rather that marker symbol #1 (a point) be plotted at the
  19. # location of each datapoint.
  20. # You may have some difficulty believing the results of this simulation.
  21. # Allowing the lighter mass to swing, it turns out, may prevent the heavier
  22. # mass from winning against it. The system may oscillate,
  23. # non-periodically.
  24. m = 1 # lighter mass
  25. M = 1.0625 # heavier mass
  26. a = 0.5 # initial angle of cord from vertical, in radians
  27. adot = 0
  28. l = 10 # initial distance along cord from pulley to mass m
  29. ldot = 0
  30. g = 9.8 # acceleration due to gravity
  31. ldot' = ( m * l * adot * adot - M * g + m * g * cos(a) ) / (m + M)
  32. l' = ldot
  33. adot' = (-1/l) * (g * sin(a) + 2 * adot * ldot)
  34. a' = adot
  35. print l, ldot
  36. step 0, 400