21
21
M1 = 1.0 # mass of pendulum 1 in kg
22
22
M2 = 1.0 # mass of pendulum 2 in kg
23
23
24
+ # th1 and th2 are the initial angles (degrees)
25
+ # w10 and w20 are the initial angular velocities (degrees per second)
26
+
27
+ # th1(second pendulum), th2 (first pendulum), th1(second pendulum), th2 (second pendulum)
28
+ init_tuple = (120.0 , 105.0 , 120.0000001 , 105.0 )
29
+ #init_tuple = (180.0000001, 180.0, -180.0000001, 180.0)
30
+ #init_tuple = (180.0, 90.0000001, 180.0, 90.0)
31
+ #init_tuple = (80.0000001, 42.0, 80.0, 42.0)
32
+ #init_tuple = (120.0, -90.0, -120.0, 90.0)
33
+
34
+ th1 = init_tuple [0 ]
35
+ w1 = 0.0
36
+ th2 = init_tuple [1 ]
37
+ w2 = 0.0
38
+
39
+ th1_ = init_tuple [2 ]
40
+ w1_ = 0.0
41
+ th2_ = init_tuple [3 ]
42
+ w2_ = 0.0
43
+
44
+ # create a time array sampled at dt second steps
45
+ # duration given in seconds
46
+ duration = 100
47
+ dt = 0.02
48
+ t = np .arange (0 , duration , dt )
49
+
50
+ #defines the number of samples fo which the drawn path should persist (None means forever)
51
+ PATH_RANGE = None
52
+
24
53
25
54
def derivs (state , t ):
26
55
@@ -46,25 +75,6 @@ def derivs(state, t):
46
75
47
76
return dydx
48
77
49
- # create a time array sampled at dt second steps
50
- duration = 200
51
- dt = 0.02
52
- t = np .arange (0 , duration , dt )
53
-
54
- # th1 and th2 are the initial angles (degrees)
55
- # w10 and w20 are the initial angular velocities (degrees per second)
56
- th1 = 80.0000001
57
- w1 = 0.0
58
- th2 = 42.0000000
59
- w2 = 0.0
60
-
61
- th1_ = 80.0000000
62
- w1_ = 0.0
63
- th2_ = 42.0
64
- w2_ = 0.0
65
-
66
- PATH_RANGE = None
67
-
68
78
# initial state
69
79
state = np .radians ([th1 , w1 , th2 , w2 ])
70
80
state_ = np .radians ([th1_ , w1_ , th2_ , w2_ ])
@@ -83,7 +93,7 @@ def derivs(state, t):
83
93
x2_ = L2 * sin (y_ [:, 2 ]) + x1_
84
94
y2_ = - L2 * cos (y_ [:, 2 ]) + y1_
85
95
86
- fig = plt .figure (figsize = ( 11 , 11 ) )
96
+ fig = plt .figure ()
87
97
ax = fig .add_subplot (111 , autoscale_on = False , xlim = (- 2 , 2 ), ylim = (- 2 , 2 ))
88
98
ax .set_aspect ('equal' )
89
99
ax .grid ()
@@ -102,7 +112,7 @@ def derivs(state, t):
102
112
"$\Theta_{12}:=%.7f\degree$ (orange)\n "
103
113
"$\Theta_{22}:=%.7f\degree$ (orange)"
104
114
% (th1 ,th2 ,th1_ ,th2_ ))
105
- init_text = ax .text (0.05 , 0.78 , init_template , bbox = dict (boxstyle = "round" , fc = "white" ),size = 'smaller' ,transform = ax .transAxes )
115
+ init_text = ax .text (0.05 , 0.68 , init_template , bbox = dict (boxstyle = "round" , fc = "white" ),size = 'smaller' ,transform = ax .transAxes )
106
116
107
117
pause = False
108
118
def onClick (event ):
@@ -153,4 +163,4 @@ def animate(i):
153
163
154
164
# saving animation
155
165
# takes a whila and ffmpeg needs to be installed
156
- #ani.save("double_pendulum_4.mp4")
166
+ #ani.save("double_pendulum_4.mp4")
0 commit comments