You are on page 1of 12

2

Changes in Energy in a Double Pendulum Can Occur Without Energy Transfer


Anonymous Author
Abstract The law of conservation of mass-energy states that it is impossible to create or destroy energy, that it may only be transferred. The present work1 appears to demonstrate an exception to this law. For example it appears possible to reduce energy in a double pendulum system by adding energy. This is done by incorporating a rotational force that adds negative kinetic energy in the lower pendulum. Although, in principle, energy may be conserved within the pendulums separate frames of reference, the net result of their opposing relative swings is a double pendulum that loses energy, even in the absence of nonconservative forces. An analogous situation appears to permit the creation of energy in the double pendulum as well. I. The Double Pendulum The double pendulum is mirrored on the childs playground in the combination of a swing and child. With proper movement of the legs and body, one can add energy and cause the swing to increase its range/height. Curiously, if the movements are reversed, the opposite occurs and the swing is brought to rest, signicantly faster than if left to friction alone (an exercise for the reader). In this work, we seek to understand where the energy goes. One explanation for this may be that the energy is transferred into the body to which the swing set is connected (i.e., the earth). To eliminate this explanation explicitly, we use a xed upper pivot. In what follows, we show that it is still possible to decrease (and increase) energy in the system without transfer to (or from) an external body. Shown in Figure 1, the point-mass double pendulum is made up of upper and lower pendulums referred to as 1 and 2 respectively. Note that the arm connecting the pivot and pendulum body is rigid and massless. Each pendulum has a mass (m1 , m2 ), an arm length (L1 , L2 ), a swing angle (1 , 2 ), and positional coordinates which refer to the pendulum bodies ((x1 , y1 ), (x2 , y2 )). Following (Neumann, 2012), these positional coordinates are computed from the following equations: x1 = L1 sin 1 y1 = L1 cos 1 x2 = L1 sin 1 + L2 sin 2 y2 = L1 cos 1 L2 cos 2 (1) (2) (3) (4)

where we adopt the convention that counter-clockwise angles are positive and clockwise angles are negative. From these equations the positional velocity (rst derivative) and acceleration (second derivative) can be readily computed. These represent the kinematics of the double pendulum. To model the dynamics of the system, we must incorporate the relevant forces on and between the bodies. These are illustrated in Figure 2 in the form of free body diagrams. In short, gravity works on each body and tensions in the rods connecting the pendulums to their pivots are also included. In addition we allow for a rotational force about the pivot connecting the two pendulums. Such a force simultaneously invokes a tangential force on the lower pendulum and an analogous force on the pivot of the upper pendulum. The force on the upper pendulums pivot is matched by the xed nature of that pivot such that no movement is permitted to occur.

Fig. 1. A point-mass double pendulum system made up of upper and lower pendulums, labeled with positions, lengths (L1 , L2 ), masses (m1 , m2 ), and swing angles (1 , 2 ) of each pendulum. These following equations describe the relevant forces acting on each pendulum body. m1 x1 = T1 sin 1 + T2 sin 2 m1 y1 = T1 cos 1 T2 cos 2 m1 g m2 x2 = T2 sin 2 C sin 1 cos 2 (5) (6) (7)

1 For personal reasons, the author does not intend to continue this research direction. This document has been prepared in the event that another wishes to take up the work.

Fig. 2. Two free body diagrams, one per pendulum, showing all relevant forces. This includes a variable rotational force acting upon the lower pivot that generates a tangential force, FR , on the lower pendulum.

m2 y2 = T2 cos 2 m2 g C sin 1 sin 2

(8)

where g represents the acceleration due to gravity and C is a constant factor indicating the relative strength of the rotational force. The dynamics of the system are ultimately dened by equations for the angular acceleration. Given these and initial values of angular position and velocity, the future angular positions and velocities can be computed. To arrive at the necessary equations, we substitute in the above set of equations values of the second derivatives of x1 , x2 , y1 , and y2 (which can be computed from the kinematic equations). Next, we eliminate the unknown tensions T1 and T2 by solving the above system of equations. The result of this process are the following two equations 1 = g(2m1 + m2 )sin1 m2 gsin(1 22 ) 2sin(1 2 )m2 (2 2L2 + 1 2L1 cos(1 2 )) L1 (2m1 + m2 m2 cos(21 22 ))
2

(9)

2 =

m FR ( m1 + sin(1 2 )2 ) + 2sin(1 2 )(1 2L1 (m1 + m2 ) + g(m1 + m2 )cos1 + 2 2L2 m2 cos(1 2 ))

L2 (2m1 + m2 m2 cos(21 22 )) II. Rate of Energy Change

(10)

Now that the dynamics of the double pendulum system have been established, the energy of the system in any given state can be computed. In this mechanical system, the energy is dened as the sum of the potential and kinetic energies of each pendulum or, E = P E1 + KE1 + P E2 + KE2 which becomes, (11)

E = ((L1 L1 cos 1 )(m1 + m2 )g + (L2 L2 cos 2 )m2 g) + (0.5m1 (1 L1 )2 + 0.5m2 ((L1 1 (t) sin 1 + L2 2 (t) sin 2 )2 + (L1 1 (t) cos 1 + L2 2 (t) cos 2 )2 )) (12)

Finally, we may compute the change in energy as its derivative with respect to time. The law of conservation of energy says that, in the absence of nonconservative forces, the mechanical energy will not change. Thus the derivative will have a value of zero when no rotational force is active (i.e., FR = 0). As potential energy is reduced, kinetic energy is increased and vice versa. The derivative of the energy in our double pendulum system with the rotational force included is E = FR (L1 1 cos(1 2 ) + L2 2 ) t (13)

This rate of change in energy allows the possibility of increasing or decreasing energy in the mechanical system by applying the appropriate directional force (indicated by FR ). Figure 3 shows a simulation of the double pendulum using Eulers method (t = 0.00001) with rotational force values: FR = C(L1 1 cos(1 2 ) + L2 2 ), so that the energy will always fall down the gradient FR = C(L1 1 cos(1 2 ) + L2 2 ), so that the energy will always climb up the gradient FR = 0, as a control to conrm there is no change in energy when no rotational force is applied. where C = 0.2, L1 = L2 = 1.0, 1 = 2 = 0.1, and 1 = 2 = 0.0. Other pendulum system values are m1 = m2 = 1.0 and g = 9.8.

III. Discussion The simulation demonstrates that by incorporating a rotational force, the total energy in the double pendulum system can be made to increase or decrease. The law of conservation of energy would say that in the increasing case, the rotational force adds energy to the pendulum system, while in the decreasing case, the rotational force merely acts like a spring which can exert a force while accepting energy from a system. Since the rotational force only performs work by denition when it pushes in the current direction of rotation, a decline in the double pendulums energy is expected to occur only when the rotational force opposes the current direction of rotation. To test this, a second simulation was performed and is shown in Figure 4. Given that the rotational direction is dened by the sign of 1 2 , the new simulation of the decreasing energy case shows the system when the rotational force is only activated when it would push in the current direction of rotation. This simulation demonstrates that rotational forces that actually perform work in the double pendulum can also decrease the systems energy. An additional curious nding was made. For the increasing energy case, the second simulation only activates the rotational force when it opposes the current direction of rotation. If it is said that such an oppositional force makes its generative mechanism a recipient of energy, we are left to conclude that receiving energy from the double pendulum under certain circumstances causes energy in the system to grow. This is a very untenable conclusion, but the simulation oers some insight as to why this may be so. In the early milliseconds of the simulation, the rotational force opposes the rotational motion, yet this appears to help propel the lower pendulum to the left, increasing its kinetic energy, and thus total energy in the system. IV. Conclusion and Future Work The hypothesis put forward here is that a rotational force at the lower pivot of a double pendulum system makes it possible to both cancel and create energy. Such a hypothesis poses an exception to the law of conservation of energy, which is in need of test. A simple experiment to test the hypothesis of energy creation might involve adding a torsion spring to the lower pendulums pivot and only allowing the pendulum to bend in one direction. Then in an initial descent, the pendulum would bend, storing energy in the spring while simultaneously raising the lower pendulums speed above an experimental control (i.e., no spring). As the lower pendulum begins to unbend, the torsion springs energy is transferred into the pendulum system, further increasing the total energy in the double pendulum. When the lower pendulums angle nallycatches up to the upper pendulum, the double pendulum becomes rigid and takes the form of a single pendulum until it swings back to its initial (or higher) position. Initial simulations (program code provided in the supplementary materials) suggest it is possible to quadruple system energy within a single swing of the double pendulum.

Fig. 3. Simulations of the double pendulum with rotational force (FR ) incorporated. The blue dashed line represents the case of constant reduction of energy in the system. The dotted green line represents the case of a constant increase of energy in the system. The solid red line is represents the control case, where there is no rotational force. (FR = 0).

Fig. 4. Simulations of the double pendulum with rotational force (FR ) incorporated only under special circumstances. The blue dashed line represents the case of reduction of energy in the system only activating the rotational force when it encourages the rotation in its current direction. The dotted green line represents the case of an increase of energy in the system only when the rotational force opposes the current direction of rotation. The solid red line is represents the control case, where there is no rotational force. (FR = 0). References

Neumann, E. (2012, December). Myphysicslab http://www.myphysicslab.com/dbl pendulum.html

double

pendulum.

Retrieved

from

V. Supplementary Materials: Python Program Code For convenience, below is a listing of code from three Python programs. The rst demonstrates conrmation of the derivative of energy. The second program is capable of generating the gures in the preceding text. The nal program simulates the double pendulums ability to create energy, showing how the right proportions of the pendulum masses and arm lengths can as much as quadruple the energy in the simulated system in a single swing. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # c o d i n g : u t f 8 DoublePendulumMath . py @author : Anonymous P l e a s e f e e l f r e e t o u s e and a b u s e t h i s code a t your own r i s k . from sympy import from sympy import l a t e x , s y m p i f y from sympy . abc import x from p y l a b import p l o t , f i g u r e , s u b p l o t , x l a b e l , y l a b e l import math x1 y1 x2 y2 x1t y1t x2t y2t x1tt y1tt x2tt y2tt = = = = = = = = = = = = L1 s i n ( th1 ( t ) ) ; L1 c o s ( th1 ( t ) ) ; L1 s i n ( th1 ( t ) ) + L2 s i n ( th2 ( t ) ) ; L1 c o s ( th1 ( t ) ) L2 c o s ( th2 ( t ) ) ; diff diff diff diff ( x1 , ( y1 , ( x2 , ( y2 , t t t t ,1) ,1) ,1) ,1) ; ; ; ; ; ; ; ; ( ) + ) (T1 s i n ( th1 ( t ) ) + T2 s i n ( th2 ( t ) ) ) ) ) , ( ) + ) ( T1 c o s ( th1 ( t ) ) T2 c o s ( th2 ( t ) ) m1 g ) ) ) , equations for the case of r o t a t i o n at the lower p i v o t ( ) + ) (T2 s i n ( th2 ( t ) ) FR c o s ( th2 ( t ) ) ) ) ) , ( ) + ) ( T2 c o s ( th2 ( t ) ) m2 g FR s i n ( th2 ( t ) ) ) ) ) e q u a t i o n s f o r t h e c a s e o f NO r o t a t i o n a t t h e l o w e r p i v o t ( ) + ) (T2 s i n ( t h 2 ( t ) ) ) ) ) , ( ) + ) (T2 c o s ( t h 2 ( t ) ) m2 g ) ) )

diff diff diff diff

( x1 , ( y1 , ( x2 , ( y2 ,

t t t t

,2) ,2) ,2) ,2)

equations = [ Eq ( S ( m1 ( + x 1 t t . str Eq ( S ( m1 ( + y 1 t t . str # These two l i n e s a r e t h e Eq ( S ( m2 ( + x 2 t t . str Eq ( S ( m2 ( + y 2 t t . str # These two l i n e s a r e t h e # Eq ( S ( m2( + x 2 t t . str # Eq ( S ( m2( + y 2 t t . str ] T2 = s o l v e ( e q u a t i o n s [ 2 ] , T2 = T2 . pop ( ) ;

T2 ) ;

48 e q u a t i o n s f o r t h e c a s e o f NO r o t a t i o n a t t h e l o w e r p i v o t 49 ( ) + ) (T2 s i n ( t h 2 ( t ) ) ) ) ) , #doesn t change 50 ( ) + ) (( + T2 . str ( ) + ) c o s ( t h 2 ( t ) ) m2 g ) ) ) 51 52 53 T1 = s o l v e ( e q u a t i o n s [ 0 ] , T1 ) ; 54 T1 = T1 . pop ( ) ; 55 56 e q u a t i o n s = [ 57 Eq ( S ( m1 ( + x 1 t t . str ( ) + ) (T1 s i n ( th1 ( t ) ) + ( +T2 . str ( )+ ) s i n ( th2 ( t ) ) ) ) ) , # doesn t change 58 Eq ( S ( m1 ( + y 1 t t . str ( ) + ) ( ( +T1 . str ( )+ ) c o s ( th1 ( t ) ) ( +T2 . str ( )+ ) c o s ( th2 ( t ) ) m1 g ) ) ) , 59 # These two l i n e s a r e t h e e q u a t i o n s f o r t h e c a s e o f r o t a t i o n a t t h e l o w e r p i v o t 60 Eq ( S ( m2 ( + x 2 t t . str ( ) + ) (T2 s i n ( th2 ( t ) ) FR c o s ( th2 ( t ) ) ) ) ) , #doesn t change 61 Eq ( S ( m2 ( + y 2 t t . str ( ) + ) ( ( + T2 . str ( ) + ) c o s ( th2 ( t ) ) m2 g FR s i n ( th2 ( t ) ) ) ) ) #doesn t change 62 # These two l i n e s a r e t h e e q u a t i o n s f o r t h e c a s e o f NO r o t a t i o n a t t h e l o w e r p i v o t 63 # Eq ( S ( m2( + x 2 t t . str ( ) + ) (T2 s i n ( t h 2 ( t ) ) ) ) ) , #doesn t change 64 # Eq ( S ( m2( + y 2 t t . str ( ) + ) (( + T2 . str ( ) + ) c o s ( t h 2 ( t ) ) m2 g ) ) ) #doesn t change 65 ]

equations = [ Eq ( S ( m1 ( + x 1 t t . str , Eq ( S ( m1 ( + y 1 t t . str g ) ) ) , # These two l i n e s a r e t h e Eq ( S ( m2 ( + x 2 t t . str Eq ( S ( m2 ( + y 2 t t . str ))) )) # These two l i n e s a r e t h e # Eq ( S ( m2( + x 2 t t . str # Eq ( S ( m2( + y 2 t t . str ]

( ) + ) (T1 s i n ( th1 ( t ) ) + ( + T2 . ( ) + ) ( T1 c o s ( th1 ( t ) ) ( + T2 .

str str

( ) + ) s i n ( th2 ( t ) ) ) ) ) ( ) + ) c o s ( th2 ( t ) ) m1

equations for the case of r o t a t i o n at the lower p i v o t ( ) + ) (T2 s i n ( th2 ( t ) ) FR c o s ( th2 ( t ) ) ) ) ) , #doesn t change ( ) + ) ( ( + T2 . str ( ) + ) c o s ( th2 ( t ) ) m2 g FR s i n ( th2 ( t

t h 2 t t = s o l v e ( Eq ( S ( ( + t h 1 t t a . str () + ) ( + th1ttb . str ( ) + ) ) ) , D e r i v a t i v e ( th2 ( t) , t , t) ) 74 t h 2 t t = t h 2 t t . pop ( ) ; 75 76 t h 2 t t a = s o l v e ( e q u a t i o n s [ 1 ] , D e r i v a t i v e ( th2 ( t ) , t , t ) ) 77 t h 2 t t b = s o l v e ( e q u a t i o n s [ 3 ] , D e r i v a t i v e ( th2 ( t ) , t , t ) ) 78 t h 2 t t a = t h 2 t t a . pop ( ) ; 79 t h 2 t t b = t h 2 t t b . pop ( ) ; 80 81 t h 1 t t = s o l v e ( Eq ( S ( ( + t h 2 t t a . str () + ) ( + th2ttb . str ( ) + ) ) ) , D e r i v a t i v e ( th1 ( t) , t , t) ) 82 t h 1 t t = t h 1 t t . pop ( ) ; 83 84 # We can n u m e r i c a l l y c h e c k t h a t t h e o u t p u t i s t h e same as t h e r e s u l t a t t a i n e d from 85 # a n o t h e r s o u r c e . F i r s t , s e t t h e e q u a t i o n s a b o v e t o f o r t h e c a s e w i t h NO r o t a t i o n a l 86 # f o r c e a t t h e l o w e r p i v o t . ( h t t p : / /www. m y p h y s i c s l a b . com/ d b l p e n d u l u m . html ) 87 t h 1 t t s t r = t h 1 t t . str () ; 88 #p r i n t t h 1 t t s t r 89 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( g , 9 . 8 ) ; 90 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( L1 , 1 . 0 ) ; 91 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( L2 , 1 . 0 ) ; 92 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( m1 , 1 . 0 ) ; 93 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( m2 , 1 . 0 ) ; 94 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , 0 . 0 ) ; 95 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , 0 . 0 ) ; 96 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( th1 ( t ) , 0 . 2 5 2 math . p i ) ; 97 t h 1 t t s t r = t h 1 t t s t r . r e p l a c e ( th2 ( t ) , 0 . 2 5 math . p i ) ; 98 #p r i n t e v a l ( t h 1 t t s t r ) # uncomment t h i s l i n e i f you want t o do t h e c h e c k 99 100 # t h e f o r m a l r e s u l t ( h t t p : / /www. m y p h y s i c s l a b . com/ d b l p e n d u l u m . html ) 101 t h 1 t t F s t r = ( g ( 2 m1 + m2) s i n 1 m2 g s i n ( th1 ( t ) 2 th2 ( t ) ) 2 s i n ( th1 ( t ) th2 ( t ) ) m2 ( ( D e r i v a t i v e ( th2 ( t ) , t ) 2 ) L2 + ( D e r i v a t i v e ( th1 ( t ) , t ) 2 ) L1 c o s ( th1 ( t ) th2 ( t ) ) ) ) / ( L1 ( 2 m1 + m2 m2 c o s ( 2 th1 ( t ) 2 th2 ( t ) ) ) ) 102 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( g , 9 . 8 ) ; 103 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( L1 , 1 . 0 ) ; 104 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( L2 , 1 . 0 ) ; 105 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( m1 , 1 . 0 ) ; 106 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( m2 , 1 . 0 ) ; 107 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , 0 . 0 ) ; 108 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , 0 . 0 ) ; 109 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( th1 ( t ) , 0 . 2 5 2 math . p i ) ; 110 t h 1 t t F s t r = t h 1 t t s t r . r e p l a c e ( th2 ( t ) , 0 . 2 5 math . p i ) ; 111 #p r i n t e v a l ( t h 1 t t F s t r ) # uncomment t h i s l i n e i f you want t o do t h e c h e c k 112 113 # Repeat n u m e r i c a l comparison f o r t h e l o w e r p i v o t a n g u l a r a c c e l e r a t i o n 114 t h 2 t t s t r = t h 2 t t . str () ; 115 #p r i n t t h 2 t t s t r 116 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( g , 9 . 8 ) ; 117 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( L1 , 1 . 0 ) ; 118 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( L2 , 1 . 0 ) ; 119 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( m1 , 1 . 0 ) ; 120 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( m2 , 1 . 0 ) ; 121 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , 0 . 0 ) ; 122 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , 0 . 0 ) ; 123 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( th1 ( t ) , 0 . 2 5 2 math . p i ) ; 124 t h 2 t t s t r = t h 2 t t s t r . r e p l a c e ( th2 ( t ) , 0 . 2 5 math . p i ) ; 125 #p r i n t e v a l ( t h 2 t t s t r ) # uncomment t h i s l i n e i f you want t o do t h e c h e c k 126 127 # t h e f o r m a l r e s u l t ( h t t p : / /www. m y p h y s i c s l a b . com/ d b l p e n d u l u m . html ) 128 t h 2 t t F s t r = ( 2 s i n ( th1 ( t ) th2 ( t ) ) ( ( D e r i v a t i v e ( th1 ( t ) , t ) 2 ) L1 (m1 + m2) + g (m1 + m2) c o s ( th1 ( t ) ) + ( D e r i v a t i v e ( th2 ( t ) , t ) 2 ) L2m2 c o s ( th1 ( t ) th2 ( t ) ) ) ) / ( L2 ( 2 m1 + m2 m2 c o s ( 2 th1 ( t ) 2 th2 ( t ) ) ) ) 129 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( g , 9 . 8 ) ; 130 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( L1 , 1 . 0 ) ; 131 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( L2 , 1 . 0 ) ; 132 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( m1 , 1 . 0 ) ; 133 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( m2 , 1 . 0 ) ; 134 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , 0 . 0 ) ; 135 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , 0 . 0 ) ; 136 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( th1 ( t ) , 0 . 2 5 2 math . p i ) ; 137 t h 2 t t F s t r = t h 2 t t s t r . r e p l a c e ( th2 ( t ) , 0 . 2 5 math . p i ) ;

66 67 68 69 70 71 72 73

# e q u a t i o n s [ 1 ] and [ 3 ] a r e t h e two e q u a t i o n s t h a t must be used t o compute t h 1 t t and t h 2 t t t h 1 t t a = s o l v e ( e q u a t i o n s [ 1 ] , D e r i v a t i v e ( th1 ( t ) , t , t ) ) t h 1 t t b = s o l v e ( e q u a t i o n s [ 3 ] , D e r i v a t i v e ( th1 ( t ) , t , t ) ) t h 1 t t a = t h 1 t t a . pop ( ) ; t h 1 t t b = t h 1 t t b . pop ( ) ;

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 1 2 3 4 5 6 7 8 9 10

#p r i n t e v a l ( t h 2 t t F s t r ) # Determine t h e e q u a t i o n s f o r Energy and comput i t s d e r i v a t i v e t o show t h e # i n s t a n t a n e o u s change i n e n e r g y . PE = ( ( L1L1 c o s ( th1 ( t ) ) ) (m1 + m2) g + ( L2 L2 c o s ( th2 ( t ) ) ) m2 g ) V2Squared = x 2 t x 2 t + y 2 t y 2 t KE = ( 0 . 5 m1 ( D e r i v a t i v e ( th1 ( t ) , t ) L1 ) 2 + 0 . 5 m2 ( + V2Squared . str () + ) ) Energy = PE + + + KE; dEnergydt = d i f f ( Energy , t , 1 ) d i f f s t r = dEnergydt . str () ; # O u t p u t i n g e q u a t i o n s i n machine ( p y t ho n ) r e a d a b l e form th1tts = th1tt . str () ; t h 1 t t s = t h 1 t t s . r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , t h 1 t ) ; t h 1 t t s = t h 1 t t s . r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , t h 2 t ) ; t h 1 t t s = t h 1 t t s . r e p l a c e ( th1 ( t ) , th1 ) ; t h 1 t t s = t h 1 t t s . r e p l a c e ( th2 ( t ) , th2 ) ; th2tts th2tts th2tts th2tts th2tts diffstr diffstr diffstr diffstr diffstr diffstr = = = = = = = = = = = th2tt . th2tts th2tts th2tts th2tts . . . . str () ; r e p l a c e ( D e r i v a t i v e ( th1 ( t ) , t ) , t h 1 t ) ; r e p l a c e ( D e r i v a t i v e ( th2 ( t ) , t ) , t h 2 t ) ; r e p l a c e ( th1 ( t ) , th1 ) ; r e p l a c e ( th2 ( t ) , th2 ) ; . . . . . . replace ( replace ( replace ( replace ( replace ( replace ( . . . . . . D e r i v a t i v e ( th1 ( t ) D e r i v a t i v e ( th2 ( t ) D e r i v a t i v e ( th1 ( t ) D e r i v a t i v e ( th2 ( t ) th1 ( t ) , th1 ) ; th2 ( t ) , th2 ) ; , , , , t, t, t) t) t) t) , , , ( , ( th1t th2t +t h 1 t t . +t h 2 t t . ); ); str str ( )+ ) ) ; ( )+ ) ) ;

diffstr diffstr diffstr diffstr diffstr diffstr = = = = = = =

energystr energystr energystr energystr energystr energystr energystr print print print print print print print print # # # #

Energy ; energystr energystr energystr energystr energystr energystr

replace ( replace ( replace ( replace ( replace ( replace (

D e r i v a t i v e ( th1 ( t ) D e r i v a t i v e ( th2 ( t ) D e r i v a t i v e ( th1 ( t ) D e r i v a t i v e ( th2 ( t ) th1 ( t ) , th1 ) ; th2 ( t ) , th2 ) ;

, , , ,

t, t, t) t)

t) t) , ,

, ( , ( th1t th2t

+t h 1 t t . +t h 2 t t . ); );

str str

( )+ ) ) ; ( )+ ) ) ;

th1tts th2tts energystr diffstr

Second D e r i v a t i v e o f Upper P i v o t Angle Second D e r i v a t i v e o f Lower P i v o t Angle Energy i n t h e Double Pendulum System D e r i v a t i v e o f t h e Energy i n t h e System

Do a n u m e r i c a l comparison showing t h a t t h e d e r i v a t i v e o f t h e e n e r g y i s e q u a l t o : dE = FR ( L1 D e r i v a t i v e ( t h 1 ( t ) , t ) c o s ( t h 1 ( t )t h 2 ( t ) ) + L2 D e r i v a t i v e ( t h 2 ( t ) , t ) ) Play w i t h t h e v a l u e s o f v a r i a b l e s t o c o n f i r m t h i s . ( S i m p l i f i c a t i o n i s a b i t d i f f i c u l t t o do , a l t h o u g h p e r h a p s Maple or Mathematica would be a b l e t o a s s i s t h e r e )

#d i f f s t r = d i f f s t r . r e p l a c e ( L1 , 1 . 0 ) ; #d i f f s t r = d i f f s t r . r e p l a c e ( L2 , 1 . 0 ) ; print Comparing t h e D e r i v a t i v e o f Energy and i t s Compact Form N u m e r i c a l l y dE = FR ( L1 t h 1 t c o s ( th1th2 ) + L2 t h 2 t ) ; FR = 1 . 0 ; g = 9 . 8 ; L1 = 1 . 0 ; L2 = 1 . 0 m1 = 1 . 0 ; m2 = 1 . 0 ; th1t = 0 . 5 ; th2t = 0 . 5 ; th1 = 0 . 2 math . p i ; th2 = 0 . 2 5 math . p i ; print Energy D e r i v a t i v e : , eval ( d i f f s t r ) ; print Compact Form : , e v a l (dE) ; # c o d i n g : u t f 8 DoublePendulumSimulate . py @author : Anonymous P l e a s e f e e l f r e e t o u s e and a b u s e t h i s code a t your own r i s k . from numpy import from p y l a b import p l o t , f i g u r e , s u b p l o t , x l a b e l , y l a b e l from math import

10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

g = 9.8; L1 = 1 . 0 ; L2 = 1 . 0 ; m1 = 1 . 0 ; m2 = 1 . 0 ; dt = 0 . 0 0 0 0 1 ; ftime = 60; l i n e s t y l e = [ , : , ] C = a r r a y ( [ 0 . 2 , 0.2 , 0 ] ) ; f o r i t e r C in [ 0 , 1 , 2 ] : d i f f a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th1a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th2a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) FRa = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th1t = 0; th2t = 0; th1 = 0 . 1 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 th2 = 0 . 1 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 th1a [ 0 ] = th1 ; th2a [ 0 ] = th2 ; FR = C [ i t e r C ] ( L1 t h 1 t c o s ( th1th2 ) + L2 t h 2 t ) ; FRa [ 0 ] = FR ; f o r t s t e p in r a n g e ( 1 , i n t ( f t i m e / dt ) , 1 ) : t h 1 t t a = (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ; t h 2 t t a = (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m22 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m2 2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m22 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m22 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ; th1 += t h 1 t dt + 0 . 5 t h 1 t t a dt 2 th2 += t h 2 t dt + 0 . 5 t h 2 t t a dt 2 ; t h 1 t += t h 1 t t a dt ; t h 2 t += t h 2 t t a dt ; FR = C [ i t e r C ] ( L1 t h 1 t c o s ( th1th2 ) + L2 t h 2 t ) ; #C s i g n ( t h 1 t ) ; # i f abs ( th1th2 ) > math . p i 0 . 5 : print ahhhh ! FRWork = s i g n (FR ( t h 1 t t h 2 t ) ) # These two l i n e s show o n l y a l l o w work t o be done when i t e i t h e r a p p e a r s # t o c r e a t e or c a n c e l e n e r g y i f s i g n (FRWork) != s i g n (C [ i t e r C ] ) and t s t e p > 1 : FR = 0 ; FRWork = 0 d i f f = 1 . 0 L1 2m1 t h 1 t ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + L1 g (m1 + m2) s i n ( th1 ) t h 1 t + L2 g m2 s i n ( th2 ) t h 2 t + 0 . 5 m2 ( ( L1 s i n ( th1 ) t h 1 t + L2 s i n ( th2 ) t h 2 t ) ( 2 L1 s i n ( th1 ) ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1 m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2

11

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 1 2 3 4 5 6 7 8

c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + 2L1 c o s ( th1 ) t h 1 t 2 + 2L2 s i n ( th2 ) ( (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m22 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2 m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m22 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1 m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m22 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + 2L2 c o s ( th2 ) t h 2 t 2 ) + ( L1 c o s ( th1 ) t h 1 t + L2 c o s ( th2 ) t h 2 t ) ( 2L1 s i n ( th1 ) t h 1 t 2 + 2L1 c o s ( th1 ) ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1 m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) 2L2 s i n ( th2 ) t h 2 t 2 + 2L2 c o s ( th2 ) ( (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m2 2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m2 2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m2 2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2 m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) ) ) ; e n e r g y = ( ( L1L1 c o s ( th1 ) ) (m1 + m2) g + ( L2 L2 c o s ( th2 ) ) m2 g ) + ( 0 . 5 m1 ( t h 1 t L1 ) 2 + 0 . 5 m2 ( ( L1 s i n ( th1 ) t h 1 t + L2 s i n ( th2 ) t h 2 t ) 2 + ( L1 c o s ( th1 ) t h 1 t + L2 c o s ( th2 ) t h 2 t ) 2 ) ) ; th1a [ 0 ] [ t s t e p ] = th1 th2a [ 0 ] [ t s t e p ] = th2 FRa [ 0 ] [ t s t e p ] = FR d i f f a [ 0 ] [ t s t e p ] = energy ; print t s t e p dt , t h 1 t , t h 2 t , th1 , th2 , d i f f , energy , FRWork #t h 1 t t , t h 2 t t , figure (4) ; subplot (5 ,1 ,1) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , th1a . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $ \ Theta 1$ ( Deg . ) ) subplot (5 ,1 ,2) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , th2a . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $ \ Theta 2$ ( Deg . ) ) subplot (5 ,1 ,3) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , ( th1a th2a ) . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ]) y l a b e l ( $ \ Theta 1 \ Theta 2$ ( Deg . ) ) subplot (5 ,1 ,4) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , FRa . t r a n s p o s e ( ) , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $F R$ ) subplot (5 ,1 ,5) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , d i f f a . t r a n s p o s e ( ) , l i n e s t y l e [ i t e r C ] ) y l a b e l ( Energy ) x l a b e l ( Time ) DoublePendulumCreate . py @author : Anonymous P l e a s e f e e l f r e e t o u s e and a b u s e t h i s code a t your own r i s k . from numpy import from p y l a b import p l o t , f i g u r e , s u b p l o t , x l a b e l , y l a b e l from math import

12

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

36

37 38 39 40 41 42 43 44 45 46 47 48 49

bSpringActive = False ; g = 9.8; L = 0.5; L1 = L 0 . 2 5 ; L2 = L 1 . 7 5 ; m = 1.0; m1 = m 1 . 4 ; m2 = m 0 . 6 ; dt = 0 . 0 0 0 0 1 ; ftime = 0.6 l i n e s t y l e = [ , : , ] C = 100 a r r a y ( [ 0 . 2 , 0 . 2 , 0 ] ) ; f o r i t e r C in [ 1 ] : d i f f a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th1a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th2a = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) FRa = z e r o s ( [ 1 , i n t ( f t i m e / dt ) ] ) ; th1t = 0; th2t = 0; th1 = 0 . 1 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 th2 = 0 . 1 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 th1a [ 0 ] = th1 ; th2a [ 0 ] = th2 ; FR = C [ i t e r C ] ( L1 t h 1 t c o s ( th1th2 ) + L2 t h 2 t ) ; FRa [ 0 ] = FR ; f o r t s t e p in r a n g e ( 1 , i n t ( f t i m e / dt ) , 1 ) : t h 1 t t a = (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ; t h 2 t t a = (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m22 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m2 2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m22 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m22 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ; th1 += t h 1 t dt + 0 . 5 t h 1 t t a dt 2 th2 += t h 2 t dt + 0 . 5 t h 2 t t a dt 2 ; t h 1 t += t h 1 t t a dt ; t h 2 t += t h 2 t t a dt ; #FR = C[ i t e r C ] ( L1 t h 1 t c o s ( th1t h 2 ) + L2 t h 2 t ) ; #C s i g n ( t h 1 t ) ; # i f abs ( th1th2 ) > math . p i 0 . 5 : print ahhhh ! i f ( th1th2 ) < 0 : FR = C [ i t e r C ] ( 0 ( th1th2 ) ) ; else : FR = 0 ; d i f f = 1 . 0 L1 2m1 t h 1 t ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + L1 g (m1 + m2) s i n ( th1 ) t h 1 t + L2 g m2 s i n ( th2 ) t h 2 t + 0 . 5 m2 ( ( L1 s i n ( th1 ) t h 1 t + L2 s i n ( th2 ) t h 2 t ) ( 2 L1 s i n ( th1 ) ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s (

13

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1 m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + 2L1 c o s ( th1 ) t h 1 t 2 + 2L2 s i n ( th2 ) ( (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m22 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2 m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m22 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1 m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m22 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) + 2L2 c o s ( th2 ) t h 2 t 2 ) + ( L1 c o s ( th1 ) t h 1 t + L2 c o s ( th2 ) t h 2 t ) ( 2L1 s i n ( th1 ) t h 1 t 2 + 2L1 c o s ( th1 ) ( (L1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 1 t 2 L1m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 1 t 2 + L1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 1 t 2 L1m2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L2m2 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th2 ) t h 2 t 2 + L2m2 s i n ( th1 ) c o s ( th2 ) 3 t h 2 t 2 L2m2 s i n ( th2 ) 3 c o s ( th1 ) t h 2 t 2 L2m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + g m1 s i n ( th1 ) s i n ( th2 ) 2 + g m1 s i n ( th1 ) c o s ( th2 ) 2 + g m2 s i n ( th1 ) c o s ( th2 ) 2 g m2 s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) ) / ( L1m1 s i n ( th1 ) 2 s i n ( th2 ) 2 + L1m1 s i n ( th1 ) 2 c o s ( th2 ) 2 + L1m1 s i n ( th2 ) 2 c o s ( th1 ) 2 + L1m1 c o s ( th1 ) 2 c o s ( th2 ) 2 + L1 m2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L1m2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) 2L2 s i n ( th2 ) t h 2 t 2 + 2L2 c o s ( th2 ) ( (FRm1 s i n ( th1 ) 2 s i n ( th2 ) 2 + FRm1 s i n ( th1 ) 2 c o s ( th2 ) 2 + FRm1 s i n ( th2 ) 2 c o s ( th1 ) 2 + FRm1 c o s ( th1 ) 2 c o s ( th2 ) 2 + FRm2 s i n ( th1 ) 2 c o s ( th2 ) 2 2FRm2 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + FRm2 s i n ( th2 ) 2 c o s ( th1 ) 2 L1m1m2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m1m2 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m1m2 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L1m2 2 s i n ( th1 ) 3 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th1 ) t h 1 t 2 L1m22 s i n ( th1 ) c o s ( th1 ) 2 c o s ( th2 ) t h 1 t 2 + L1m22 s i n ( th2 ) c o s ( th1 ) 3 t h 1 t 2 L2m22 s i n ( th1 ) 2 s i n ( th2 ) c o s ( th2 ) t h 2 t 2 + L2m22 s i n ( th1 ) s i n ( th2 ) 2 c o s ( th1 ) t h 2 t 2 L2m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) 2 t h 2 t 2 + L2m2 2 s i n ( th2 ) c o s ( th1 ) 2 c o s ( th2 ) t h 2 t 2 g m1m2 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m1m2 s i n ( th2 ) c o s ( th1 ) 2 g m22 s i n ( th1 ) c o s ( th1 ) c o s ( th2 ) + g m22 s i n ( th2 ) c o s ( th1 ) 2 ) / ( L2m1m2 s i n ( th1 ) 2 s i n ( th2 ) 2 + L2m1m2 s i n ( th1 ) 2 c o s ( th2 ) 2 + L2m1m2 s i n ( th2 ) 2 c o s ( th1 ) 2 + L2m1m2 c o s ( th1 ) 2 c o s ( th2 ) 2 + L2m2 2 s i n ( th1 ) 2 c o s ( th2 ) 2 2L2m22 s i n ( th1 ) s i n ( th2 ) c o s ( th1 ) c o s ( th2 ) + L2 m22 s i n ( th2 ) 2 c o s ( th1 ) 2 ) ) ) ) ; e n e r g y = ( ( L1L1 c o s ( th1 ) ) (m1 + m2) g + ( L2 L2 c o s ( th2 ) ) m2 g ) + ( 0 . 5 m1 ( t h 1 t L1 ) 2 + 0 . 5 m2 ( ( L1 s i n ( th1 ) t h 1 t + L2 s i n ( th2 ) t h 2 t ) 2 + ( L1 c o s ( th1 ) t h 1 t + L2 c o s ( th2 ) t h 2 t ) 2 ) ) ; th1a [ 0 ] [ t s t e p ] = th1 th2a [ 0 ] [ t s t e p ] = th2 FRa [ 0 ] [ t s t e p ] = FR d i f f a [ 0 ] [ t s t e p ] = energy ; print t s t e p dt , t h 1 t , t h 2 t , th1 , th2 , d i f f , energy , FR #t h 1 t t , t h 2 t t , figure (4) ; subplot (5 ,1 ,1) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , th1a . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $ \ Theta 1$ ( Deg . ) ) subplot (5 ,1 ,2) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , th2a . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $ \ Theta 2$ ( Deg . ) ) subplot (5 ,1 ,3) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , ( th1a th2a ) . t r a n s p o s e ( ) 1 8 0 . 0 / math . pi , l i n e s t y l e [ i t e r C ]) y l a b e l ( $ \ Theta 1 \ Theta 2$ ( Deg . ) ) subplot (5 ,1 ,4) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , FRa . t r a n s p o s e ( ) , l i n e s t y l e [ i t e r C ] ) y l a b e l ( $F R$ ) subplot (5 ,1 ,5) p l o t ( a r a n g e ( 0 , i n t ( f t i m e / dt ) , 1 ) dt , d i f f a . t r a n s p o s e ( ) , l i n e s t y l e [ i t e r C ] ) y l a b e l ( Energy ) x l a b e l ( Time )

You might also like