1919G = 9.8 # acceleration due to gravity, in m/s^2
2020L1 = 1.0 # length of pendulum 1 in m
2121L2 = 1.0 # length of pendulum 2 in m
22+ L = L1 + L2 # maximal length of the combined pendulum
2223M1 = 1.0 # mass of pendulum 1 in kg
2324M2 = 1.0 # mass of pendulum 2 in kg
24- t_stop = 50 # how many seconds to simulate
25+ t_stop = 5 # how many seconds to simulate
2526history_len = 500 # how many trajectory points to display
2627
2728
@@ -73,9 +74,7 @@ def derivs(state, t):
7374y2 = - L2 * cos (y [:, 2 ]) + y1
7475
7576fig = plt .figure (figsize = (5 , 4 ))
76- ax = fig .add_subplot (autoscale_on = False ,
77- xlim = (- (L1 + L2 ), (L1 + L2 )),
78- ylim = (- (L1 + L2 ), 1. ))
77+ ax = fig .add_subplot (autoscale_on = False , xlim = (- L , L ), ylim = (- L , 1. ))
7978ax .set_aspect ('equal' )
8079ax .grid ()
8180
@@ -90,6 +89,10 @@ def animate(i):
9089 thisx = [0 , x1 [i ], x2 [i ]]
9190 thisy = [0 , y1 [i ], y2 [i ]]
9291
92+ if i == 0 :
93+ history_x .clear ()
94+ history_y .clear ()
95+
9396 history_x .appendleft (thisx [2 ])
9497 history_y .appendleft (thisy [2 ])
9598
0 commit comments