Vous êtes sur la page 1sur 17

.

PHYS 2030 Final Project: Study of trajectories of two double pendulums under external random forcing
Rizki Syarif
Department of Physics, Brown University, Providence, Rhode Island, 02912, USA (Dated: December 17, 2013) We present a report on the study of the behaviour of double pendulums under the inuence of an external stochastic force. Specically we investigate the role of noise and dissipation on the convergence of the trajectories of two chaotic systems and on its transition from chaotic to nonchaotic behaviour, similar to what have been studied by reference [1] and [2]. We use double pendulums as our chaotic system and use a model for stochastic forcing as used by reference [3]. Also, we perform our calculations using the fourth-order Runge-Kutta method.

1.

INTRODUCTION

Chaotic behaviour can present itself through simple systems such as a double pendulum. This is the conguration where one pendulum is connected to the end of another pendulum. Motivated by references [1] and [2], we investigate the behaviour of chaotic double pendulums that are driven by an external stochastic force or noise. We also investigate possible synchronisation or convergence of trajectory between two identical double pendulums under the same noise. Ref [1] and Ref [4] claim to have observed a transition from chaos to non chaos due to stochastic forcing. Whereas, Ref [2] refutes these claims by arguing that the stochastic force does not play part in the transition rather it is dissipation that causes the transition. However, Ref [2] claims that under noise, two identical chaotic system will converge more quickly than without forcing given that the system has dissipation. In this report we will investigate the above issues using the double pendulum system (which has not been studied neither by Ref [1], [4] nor Ref [2]). We explore its chaotic and non chaotic behaviour, and later investigate the eect of noise and dissipation to the system, and how these contribute to the convergence of trajectories and to the transition from chaotic to non chaotic behaviour. The report is organised as follows. First we discuss chaos in double pendulums, modelling and the equations of motion. Then we elaborate on the methods of calculations we use to measure chaos and convergence. Following that we briey do a test calculation to check for the initial conditions that will lead to chaotic behaviour. Then we discuss results followed by conclusions and discussion.

At certain initial conditions the double pendulum may exhibit chaotic behaviour. Typically, at large angle initial conditions a double pendulum will exhibit chaotic behaviour and at small angle initial conditions it exhibits approximately linear dynamical motion which is non chaotic and stable. We will discuss more about the initial conditions at later section. The double pendulum that is considered in this report consists of two equal masses attached to two equal length massless rod (see Figure 1).

FIG. 1: Double pendulum, with equal length massless rod, with two equal masses.

2.1.

Modelling double pendulum

To model the double pendulum, we begin with dening the following: x1 y1 x2 y2 = = = = l sin 1 l cos 1 l sin 1 + l sin 2 l cos 1 l cos 2 (1) (2) (3) (4)

2.

CHAOS AND THE DOUBLE PENDULUM

Chaos can be characterised as apparent random behavior and extreme sensitivity to initial conditions despite the system being deterministic [5]. This is due the nonlinear nature of the dynamics.

where x1 , y1 are the coordinates for the mass on the upper rod, x1 , y1 for the other mass, and the origin lies on the pivot of the upper rod. The kinetic energy and

2 the potential energy: T = 1 1 2 2 m(x 2 1 ) + m(x 2 2 ) 1+y 2+y 2 2 2 + 1 2 + 1 1 cos (1 2 )) = ml2 ( 1 2 2 (5) (6) H pi H p i = + Fext Fdis qi q i = (12) (13)

and U = mgy1 mgy2 = mgl(2 cos 1 + cos2 ) (7) (8)

We rescale such that m, l, g are no longer appear in L our equations1 . Then we further dene qi = i , pi = q i , where i = 1, 2 and L = T U is the lagrangian. The hamiltonian, H = pi q i L, of the system is:
2 1 p2 1 2p2 cos (q1 q2 ) 2 cos q1 cos q2 + 3 (9) 2 1 + sin (q1 q2 )2

where i = 1, 2, Fext is the noise as described by Eq. 10 and the last term Eq. 13 is the dissipation term. We will consider two cases. One where the dissipation is proportional to the conjugate momentum, ie. Fdis = p, and second where it is proportional to the rate of change of the angles, ie. Fdis = q , and is the dissipation coecient.
3. METHODS OF CALCULATION 3.1. Numerical Method

H=

where we added an arbitrary constant to shift our zero energy point for ease of calculation.
2.2. Modeling external stochastic force

To model the force function or noise, we adopt a model from Ref. [3]. The function is written as the following recursion relation Fn+1 = Rn Fn +
2 )F n+1 (1 Rn

(10)

where R is the coecient dened by Rn = 1 1+


t 2 t 2

We implement the fourth-order Runge-Kutta numerical method3 for integrating the equations motion in Eq. 12-13 to obtain the trajectories of the double pendulum. Also, we use a time step size t = 0.01 and we choose our decay time constant for the noise force = 0.1 for all of our proceeding calculations 4 . We check that this numerical method setting gives us the correct physics, ie. we check for reasonableness of trajectories and for energy conservation. First, we set the initial angles of the pendulum to be close to zero and set the initial conjugate momentum such that the energy is 1 unit. Then set the initial angles and initial conjugate momentums such that energy is 6 units.

(11)

where n is the number of time steps, is the decay time is a randomly constant of F , t is the step size, and F generated number from a gaussian centered at zero and a standard deviation of . The decay time determines the timescale at which the random (noise) force varies. To achieve the desired eect, we will set such that noise varies in timescales much larger than the time step size t, but smaller than the typical period of our pendulum (which is in the order of a few time units 2 ).
2.3. Equations of motion

FIG. 2: Trajectory of double pendulum with energy set to 1 unit.

Using the hamiltonian in Eq. 9, incorporating noise and dissipation, we write our equations motions as,

We calculate trajectories and energies of the double pendulums in the absence of noise and dissipation. Figure 2 and Figure 4 show the trajectory of the double

3 1

This can be done by rescaling our coordinates. But we can also set l = g and m = g1 2 See Figure 2.

This method reproduces the taylor expansion of a function up to fourth order. The local truncation of this method is to order of ve [6]. This avoids instability of simulation since typical period of pendulum is in the order of 1. So we have t < < Tperiod .

FIG. 3: The energy vs time of double pendulum with energy set to 1 unit.

FIG. 5: The energy vs time of double pendulum calculated with energy set to 6 units.

pendulums for energy=1 and energy=6 respectively, and the plots show expected trajectories. More importantly, Figure 3 and Figure 5 show the energy changes in the order of 107 energy units for the low energy pendulum, and 105 energy units for the high energy pendulum, in 100 time units. These tests conrm that our numerical method is producing the correct physics and that the numerical errors are suciently small.

growth of separation with respect to the initial condix tion diference, ie. x0 , is exponential then the system is chaotic [7]. Numerically it is convenient to use the following to calculate the exponent given the number of time steps t n= t. 1 = n t
n

i=1

xi+1 x i

(15)

In our case, the vector x has components q1 , p1 , q2 , p2 .


3.3. Distance calculation of two double pendulums

FIG. 4: Trajectory of double pendulum with energy set to 6 units.

To investigate convergence of trajectories or synchronisation between two double pendulum, we calculate the distance in phase space between two chaotic double pendulums. More specically, we calculate norm of x(q1 , p1 , q2 , p2 ). We restrict the maximum separation distance to be radians for the angles. To emphasise dierences between distances we calculate the square of the norm. (See Figure 6 for a schematic diagram of the two double pendulums).

3.2.

Measuring chaos

The way we measure chaos is by calculating what is called the Lyapunov exponent. Chaos can be dened by this exponent. If we have two initial conditions, and they dier by x0 then a chaotic system will have this separation grow exponentially in time, ie x = x0 et (14)
FIG. 6: Schematic diagram of two pendulums under noise

where is the Lyapunov exponent. So for our double pendulum, given two initial conditions and their separation, if the Lyapunov exponent is positive or if the

4
4. INITIAL CONDITIONS LEADING TO CHAOS

We perform numerical calculations to show that the initial conditions we use in this investigation do produce chaotic behaviour. We contrast it to the low angle low energy initial condition where the behaviour is non chaotic. For the (large angle large energy) initial condition that we expect to produce chaotic behaviour, we generate random numbers between and radians for the angles of both the lower and upper pendulum and we choose a value of energy of 6 units, where an energy of 0 represents the pendulum at rest lying straight down, and an energy of 6 units represents the pendulum at rest at the highest position, i.e. both rod positioned straight up. This initial energy will determine the initial conjugate momentum of the lower pendulum. For the non chaotic or low angle initial condition we choose an angle of 0.01 radians for both the lower and upper pendulum and we choose the initial energy to be 0.05. For this calculation5 , we set noise and dissipation to be zero. To measure the sensitivity to initial conditions, we calculate the trajectory of initial conditions that dier only by 0.000001 for the angle of the lower pendulum6 . Figure 7 shows the sensitivity of initial conditions for both the large angle and the low angle. We can see in Figure 7 (top plot) that the growth is exponential for the large angle initial condition as shown by the positive (approximately) linear increase in the semilog plot for t < 60. Whereas the growth is on average zero for the low angle initial condition. The bottom plot in Figure 7 shows the Lyapunov exponent as calculated using Eq. 15. It shows as a function of time. Consistently, it shows that the large angle initial condition has positive exponent and the low angle has eectively zero or close to zero exponent. We use the same parameters to generate our random initial conditions to produce our chaotic double pendulum in our investigation.

x FIG. 7: Top: Growth of over time in semilog plot bex0 tween two trajectories with a dierence of 0.000001 initial position. Green line is the one with a large angle large energy initial condition, and blue is the one with small angle low energy initial condition. Bottom: The Lyapunov exponent as a function of time.

of noise, we keep the dissipation term to be zero. We contrast this calculation with trajectories without noise using the same initial conditions to see the eect of noise on our trajectory. We observe that having the external force does not seem to cause any convergence of trajectory. Looking at Figure 8, there is no clear indication that noise alters the trajectories in a way such that the two double pendulums become synchronised or converging to a single trajectory.

5. 5.1.

RESULTS

Trajectories with noise only

To see the eect of stochastic force, we calculate the trajectories of two double pendulums with randomly generated initial conditions with initial energy of 6 units and set the standard deviation of gaussian that generates F in Eq.10 to be 0.01, ie. = 0.01. To see only the eect
FIG. 8: Distance (squared) semilog plot between two double pendulums. The blue line represents the distance between two double pendulum under the same noise, and the green line is the distance between two double pendulums without noise.

5 6

See Appendix B - Figure 25) for the initial conditions in cartesian coordinates We therefore calculate 4 trajectories, 2 that have large angles that dier by 0.000001 in q2 and another 2 that have low angles that is also dier by 0.000001 in q2 .

To look at the sensitivity to initial conditions, we plot-

5 ted the growth dierence of trajectory with respect to x a slightly dierent initial condition ( x0 ) and also the Lyapunov exponent for both double pendulums. We calculate once with noise and once without noise (see Figure 9). the system (see Figure 11). We observe that this noise, in this time scale, does not cause the energy to diverge signincantly.

x FIG. 9: Top: Growth of over time in semilog plot of four x0 double pendulums. Blue and green represents the growth double pendulums under noise, red and cyan line represents the growth for double pendulums without noise. Bottom: The Lyapunov exponents as a function of time.

FIG. 11: Energy plotted versus time of four double pendulums. Blue and green are for (double) pendulums with noise, and red and cyan are for the ones without noise. In this plot red and cyan looks to be one line, since without noise energy is conserved.

x We see in Figure 9 that x0 grows at a higher rate with noise than without noise. We also observe that noise causes the double pendulums to have higher value for Lyapunov exponent any given time. From these observations, it seems that noise (Figure 10) has caused the system to be more chaotic.

5.2.

Trajectories with noise and dissipation

randomly generFIG. 10: Noise produced using Eq. 10 with F ated from a gaussian centred at zero and a standard deviation ( ) of 0.01. This produces a mean force amplitude of 0.008.

As stability and consistency check, we also plotted the energy to see how noise has aected the total energy of

In this section, we analyse the eect noise with the addition of dissipation to the double pendulums. We perform the same calculations as in the previous section. However this time we keep set dissipation coecient to be constant at 0.05. First we consider the dissipation term being proportional to the conjugate momentum, ie. Fdis = p. We calculate the square of the distance over time between two double pendulums starting from dierent initial conditions. We do two calculations, one with noise and the other without noise (see Figure 12). We observe no clear indication of convergence due to noise. It is clear that dissipation is at least the major factor that causes the trajectories to converge as shown by Figure 12 where the distances tends towards zero. We also observe that the eect of noise with the presence of dissipation causes the system to become slightly more chaotic in the beginning as shown by the growth x of x0 in time (see Figure 13). At t = 20 to t = 40 the system transitions to non chaotic regime, and at t > 40 the pendulums become stable and non chaotic shown by the negative growth of the initial condition separation. The energies of the pendulums decrease over time as expected because of the presence of dissipation (see Figure 14). There is little eect on how energy changes due to noise. We repeat all the above calculations using a slightly dierent dissipation term in the equation of motion. We

FIG. 12: Square of the distance between two double pendulums under noise ( = 0.01) with dissipation ( = 0.05) up to t=100 (10000 iterations).

FIG. 14: Energy plot of the two double pendulums. Blue and green represents the energies of the double pendulum under noise. Red and cyan represents the pendulums without noise. The plot shows energy lost due dissipation.

x FIG. 13: Top: Growth of over time in semilog plot of x0 four double pendulums with dissipation proportional to the conjugate momentum. Blue and green represents the growth double pendulums under noise, red and cyan line represents the growth for double pendulums without noise. Bottom: The Lyapunov exponents as a function of time.

FIG. 15: Square of the distance between two double pendulums under noise ( = 0.01) with dissipation ( = 0.05) up to t=100 (10000 iterations).

5.3.

Mean Square Distance

consider a dissipation term that is proportional to the rate of change of the angles, ie. q i . We obtain dierent results for the distance calculation and the initial condition sensitivity calculation. In this conguration, the plot (Figure 15) seems to show that the pendulums under noise converges more quickly than the ones without noise. However, it is still not evident whether or not noise is the cause of this, or whether this is just random uke. We will explore this more in Section 5.3. It is also not evident that noise has any aect on the transition from chaos to non chaos (see Figure 16).

To get a better measure of the eect of noise to the trajectories, we produce 100 double pendulum pairs. Each with randomly generated initial conditions and then we calculate the mean of the square of the distances at each time step and plot them over time. We calculate with different values for the standard deviation ( ) of the gaus in Eq. 10. sian that generates F Similar to previous section, rst we calculate using the dissipation term p (see Figure 17) and the we calculate once more using q (see Figure 18). Both Figure 17 and Figure 18 show that for dierent noise amplitudes the convergence is slower or about as fast as without noise.

7 0 when is increased to values of = 0.01, = 0.1, = 1.0.

6.

CONCLUSION AND DISCUSSION

We investigate the behaviour of double pendulums exposed to an external stochastic forcing. Using the fourth order Runge-Kutta numerical method, we calculate the growth of the dierence of two trajectories with respect

x FIG. 16: Top: Growth of over time in semilog plot of four x0 double pendulums with dissipation proportional to the rate of change of the angle. Blue and green represents the growth double pendulums under noise, red and cyan line represents the growth for double pendulums without noise. Bottom: The Lyapunov exponents as a function of time.

FIG. 18: Mean square distance of 100 pairs of double pendulums where the noise is proportional to the rate of change of the angles. Dierent colors represent dierent values used in the calculation (for noise).

FIG. 17: Mean square distance of 100 pairs of double pendulums where the noise is proportional to the conjugate momentum. Dierent colors represent dierent values used in the calculation (for noise).

Also, in both Figures 17 and Figure 18, there are no clear indications that convergence is any faster than =

to the dierence of two initial conditions and we also look at the Lyapunov exponents. Then we calculated the square of the distance in phase space of trajectories of two doubles pendulums with initial conditions that are randomly generated and with exposure to noise and dissipation. Furthermore we calculated the mean of the square of distances of 100 pairs of double pendulums. There seems to be no indication of transition from chaos to non chaos due to noise where dissipation is not present. When dissipation is present, and when the dissipation is either proportional to the conjugate momentum or to the rate of change of the angles, we observe no clear evidence that noise may speed up convergence of trajectories. We were not able to reproduce the ndings both by Ref. [1] and Ref. [2] using the double pendulum.

[1] S. Fahy and D. R. Hamann, Transition from chaotic to nonchaotic behavior in randomly driven systems, Phys. Rev. Lett. 69, 761 (1992), URL http://link.aps.org/ doi/10.1103/PhysRevLett.69.761. [2] G. Malescio, Noise and synchronization in chaotic systems, Phys. Rev. E 53, 6551 (1996), URL http://link. aps.org/doi/10.1103/PhysRevE.53.6551.

[3] D. K. Lilly, Numerical Simulation of Two-Dimensional Turbulence, Physics of Fluids (1958-1988) 12, II (1969), URL http://scitation.aip.org/content/aip/ journal/pof1/12/12/10.1063/1.1692444. [4] A. Maritan and J. R. Banavar, Chaos, noise, and synchronization, Phys. Rev. Lett. 72, 1451 (1994), URL http: //link.aps.org/doi/10.1103/PhysRevLett.72.1451.

8
[5] A. L. Fetter and J. D. Walecka, Nonlinear Mechanics A Supplement to Theoretical Mechanics of Particles and Continua (Dover Publications, 2006), 1st ed. [6] W. Press, B. Flannery, S. Teukolsky, and W. Vetterling, Numerical Recipes in C: The Art of Scientic Computing (Cambridge University Press, 1992), 2nd ed., ISBN 0521431085. [7] T. Shinbrot, C. Grebogi, J. Wisdom, and J. A. Yorke, Chaos in a double pendulum, American Journal of Physics 60, 491 (1992), URL http://scitation.aip.org/content/aapt/journal/ ajp/60/6/10.1119/1.16860.

Acknowledgments

I would like to thank Professor Marston for his advice and suggestions regarding this project.

9
Appendix A: Extra plots produced for one typical run - with noise ( = 0.05) and damping ( = 0.05)

FIG. 19: Trajectory of double pendulum 1. = 0.05 and = 0.05. Fdis = q

FIG. 20: Trajectory of double pendulum 2. = 0.05 and = 0.05. For Fdis = q

FIG. 21: Damping over time. Left is for pendulum 1, and on the right is for pendulum 2. = 0.05 and = 0.05. For Fdis = q

10

FIG. 22: Trajectory of double pendulum 1. = 0.05 and = 0.05. For Fdis = p

FIG. 23: Trajectory of double pendulum 2. = 0.05 and = 0.05. For Fdis = p

FIG. 24: Damping over time. Left is for pendulum 1, and on the right is for pendulum 2. = 0.05 and = 0.05. For Fdis = p

11
Appendix B: Example initial conditions. Low angle and large angle comparison.

FIG. 25: Initial Condition of two double pendulums. Red represents the large angle initial condition, blue for the small angle. The squares represents the upper pendulum mass, and triangle is where the lower mass is positioned.

Appendix C: Python code


import math from numpy import * from pylab import * from scipy.integrate import odeint import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import random class DoublePendulum_RK4 (object): dt = 0.01 tmin = 0.0 t0 = 0.0 def __init__(self, E, q1, q2, p1, tmax, number): self.tmax = tmax p2 = self.p2(E, q1, q2, p1) self.phaseSpace = array([q1, p1, q2, p2]) self.number = number def p2(self, E, q1, q2, p1): b = -p1 * cos(q1 - q2) c = 0.5 * p1**2 - (E + 2.0 * cos(q1) + cos(q2) - 3.0) * (1.0 + sin(q1 - q2)**2) det = sqrt(b**2 - 4.0 * c) return (-b + det)/2.0 def trajectory(self,noise,damp): [self.t,self.phaseSpace] = self.RK4(self.derivative,self.tmin,self.tmax,self.phaseSpace,self.t0,self.dt,noise, damp)

####################################################### # RHS of the ODE to be solved def derivative(self, t, phaseSpace, noise, damp): #print "phaseSpace =",phaseSpace q1 = phaseSpace[0] p1 = phaseSpace[1] q2 = phaseSpace[2] p2 = phaseSpace[3]
denom = 1.0 / (1.0 + sin(q1 - q2)**2) numer = p1**2 + 2.0 * p2**2 - 2.0 * p1 * p2 * cos(q1 - q2) q1dot p1dot q2dot p2dot = = = = (p1 - p2 * cos(q1 - q2)) * denom -2.0 * sin(q1) - p1 * p2 * sin(q1 - q2) * denom + numer * sin(q1 - q2) * cos(q1 - q2) * denom**2 + noise - damp * q1dot (2.0 * p2 - p1 * cos(q1 - q2)) * denom -sin(q2) - p1 * p2 * sin(q2 - q1) * denom + numer * sin(q2 - q1) * cos(q1 - q2) * denom**2 + noise - damp * q2dot

return array([q1dot, p1dot, q2dot, p2dot])

############################################################# # The RK4 routine - (modified from www.rosettacode.org) # # INPUT ARGUMENTS # derivative function object providing the RHS of the 1st order ODE # tmin, tmax the domain of the solution # phasespace, t0 initial values # dt time step over which the solution is sought # noise external random force # damp damping force/friction # # OUTPUT # ti the list of points where the equation has been solved # yi the values of the solution found ############################################################ def RK4(self, derivative,tmin,tmax,phaseSpace,t0,dt,noise, damp):
yi=[phaseSpace] ti=[t0] nmax=int( (tmax-tmin)/dt +1) print "nmax = ", nmax count = 0 for n in range(1,nmax,1): tn=ti[n-1] yn=yi[n-1] Fn = noise[n-1] dy1=dt*derivative( tn, yn, Fn, damp ) dy2=dt*derivative( tn+dt/2.0, yn+dy1/2.0, Fn, damp) dy3=dt*derivative( tn+dt/2.0, yn+dy2/2.0, Fn, damp) dy4=dt*derivative( tn+dt, yn+dy3, Fn, damp) value = yn+(1.0/6.0)*(dy1+2.0*dy2+2.0*dy3+dy4) yi.append( value.tolist() ) ti.append(tn+dt) count = count + 1 if count%5000 == 0: print "count = ", count," no.",self.number yi.remove(yi[0]) yi.insert(0,phaseSpace.tolist()) yi = array(yi) 1

yi = reshape(yi,(len(yi),4)) print "loop count =", count #print "yi = ", yi print "length of yi", len(yi) return [ti,yi]

#######################################################
def Hamiltonian(self): q1 p1 q2 p2 = = = = self.phaseSpace[:, self.phaseSpace[:, self.phaseSpace[:, self.phaseSpace[:, 0] 1] 2] 3]

return 0.5 * (p1**2 + 2.0 * p2**2 - 2.0 * p1 * p2 * cos(q1 - q2)) / (1.0 + sin(q1 - q2)**2) + 3.0 - 2.0 * cos(q1) - cos(q2) def dist(self, phaseSpace2, fig = False, noise = True): d = abs(self.phaseSpace - phaseSpace2) d_BC = [] d_BC_norm_sq = [] for i in xrange(len(d)):

#maximum separation 2pi rad xtra1 = int(d[i,0]/(2*pi))*2*pi xtra2 = int(d[i,2]/(2*pi))*2*pi


d0 = d[i,0] - xtra1 d2 = d[i,2] - xtra2

# take acute angle if d0 > pi : d0 = abs(d0-(2*pi)) if d2 > pi : d2 = abs(d2-(2*pi))


d_BC.append([d0,d[i,1],d2,d[i,3]]) d_BC_norm_sq.append(norm(d_BC[i])**2) d[i,0] = d0 d[i,2] = d2 if fig == True : figure(81) if noise == True: semilogy(self.t, d_BC_norm_sq, label='with noise') if noise == False: semilogy(self.t, d_BC_norm_sq, label='without noise') xlabel("time") ylabel("Distance squared (Phasespace)") legend() print " " print "Mean distance =",mean(d_BC) print "Mean squared =",mean(d_BC_norm_sq) return d_BC_norm_sq def plotScale(self): q1 = arange(0.0, 3.14, 0.1) q2 = arange(0.0, 3.14, 0.1) x1 y1 x2 y2 = = = = sin(q1) -cos(q1) sin(q1) + sin(q2) -cos(q1) - cos(q2)

figure(61) plot(0,0,'ko', label='pivot') plot(x1,y1, 'bs', label='upper pendulum') plot(x2,y2, 'b^', label='lower pendulum') xlabel("X") ylabel("Y") axis([-2,2,-2,2]) legend() def plotIC(self, fig = False): x1 y1 x2 y2 = = = = sin(self.phaseSpace[0,0]) -cos(self.phaseSpace[0,0]) sin(self.phaseSpace[0,0]) + sin(self.phaseSpace[0,2]) -cos(self.phaseSpace[0,0]) - cos(self.phaseSpace[0,2])

if fig == True: figure(51) if self.number == 1: plot(0,0,'ko', label='pivot') plot(x1,y1, 'bs', label='upper plot(x2,y2, 'b^', label='lower if self.number == 2: plot(x1,y1, 'rs', label='upper plot(x2,y2, 'r^', label='lower

pendulum 1') pendulum 1') pendulum 2') pendulum 2') 2

xlabel("X") ylabel("Y") axis([-2,2,-2,2]) #legend() return [x1,y1,x2,y2] def plotPS(self): figure(1) if self.number == 1:plot(self.phaseSpace[:, 0], self.phaseSpace[:, 1], label = "pendulum 1") if self.number == 2:plot(self.phaseSpace[:, 0], self.phaseSpace[:, 1], label = "pendulum 2") title("trajectory") xlabel("q1") ylabel("p1") legend() def plot3Dtraj(self,num): fig = plt.figure(num) x1 = sin(self.phaseSpace[:,0]) y1 = -cos(self.phaseSpace[:,0]) x2 = sin(self.phaseSpace[:,0]) + sin(self.phaseSpace[:,2]) y2 = -cos(self.phaseSpace[:,0]) - cos(self.phaseSpace[:,2]) ax = fig.gca(projection='3d') ax.plot( self.t, x1, y1, label='upper pedulum') ax.plot( self.t, x2, y2, label='lower pendulum') ax.set_xlabel('Time') ax.set_ylabel('X') ax.set_zlabel('Y') ax.legend() def plotEnergy(self): figure(2) energyArray = self.Hamiltonian() if self.number ==1 : plot(self.t, energyArray, label = "pendulum 1") if self.number ==2 : plot(self.t, energyArray, label = "pendulum 2") xlabel("time") ylabel("energy") legend() def plotNoise(self,Fnoise): figure(4) plot(self.t, Fnoise, "r") title("Noise vs time") xlabel("time") ylabel("noise") def plotDamp(self, damp): damp_p1 = damp*self.phaseSpace[:,1] damp_p2 = damp*self.phaseSpace[:,3] num = self.number figure(40) subplot(1,2,num) plot(self.t, damp_p1, label='upper pendulum') xlabel("time") ylabel("damping") plot(self.t, damp_p2, label='lower pendulum') xlabel("time") ylabel("damping") legend()

#print " " #print "mean damp on upper pendulump(",self.number,") =", mean(damp_p1) #print "mean damp on lower pendulump(",self.number,") =", mean(damp_p2)
def poincare(self,num): q1 p1 q2 p2 = = = = self.phaseSpace[:, self.phaseSpace[:, self.phaseSpace[:, self.phaseSpace[:, 0] 1] 2] 3]

xList = [] yList = [] for i in range(len(q1)-1): if (p2[i] > 0.0): if (sin(q2[i])/sin(q2[i+1]) < 0.0): xList.append(q1[i]) yList.append(p1[i]) figure(num) if self.number ==1: scatter(xList, yList, s=1.0, marker='x', color = 'blue', alpha=1.0) if self.number ==2: scatter(xList, yList, s=1.0, marker='x', color = 'red', alpha=1.0) title("Poincare section") xlabel("q1") ylabel("p1") 3

def Lyapunov(self,phaseSpace_prime,fig=False): delta_pS = self.phaseSpace-phaseSpace_prime ndelta_pS = [] for i in xrange(len(delta_pS)): ndelta_pS.append(norm(delta_pS[i])) ndelta_pS = array(ndelta_pS) sumLog = [0.] ratio = [] lambd = [0.0] for i in xrange(len(ndelta_pS)-1): ratio.append(abs(ndelta_pS[i+1]/ndelta_pS[i])) sumLog.append(sumLog[i] + log(ratio[i])) lambd.append(1./(self.dt*i+1) * sumLog[i+1]) if fig == True: print " " print "Mean Lyapunov exponent p(",self.number,") = ", lambd[-1] figure(6) subplot(2,1,1) if self.number ==1 : semilogy(self.t, ndelta_pS, "-", label = 'pendulum 1') if self.number ==2 : semilogy(self.t, ndelta_pS, "-", label = 'pendulum 2') title("") ylabel("delta x / delta x0") subplot(2,1,2) if self.number ==1 : plot(self.t, lambd, label = 'pendulum 1') if self.number ==2 : plot(self.t, lambd, label = 'pendulum 2') ylabel('lambda') xlabel('time') legend() self.log_ndelta_pS = log(ndelta_pS) return lambd def show(self): show() BIGloop = 1 IC1 = [] IC2 = [] Lyap = [] Lyap2 = [] SqDist = [] BIGloopcount = 0 for i in xrange(BIGloop): tmax = 100

"""Create Random initial condition""" #Random p p_q1 = random.uniform(-pi, pi) p_q2 = random.uniform(-pi, pi) p_q2_prime = p_q2 + 0.000001 #Random p2 p2_q1 = random.uniform(-pi, pi) p2_q2 = random.uniform(-pi, pi) p2_q2_prime = p2_q2 + 0.000001 """Create Common Noise"""
def noise(noise_switch): tau = 0.1 #noise time decay constant R = (1 - (p.dt / (2. * tau) ) ) / (1 + ( p.dt / (2. * tau) ) ) #force function coefficient mu, sigma = 0., 0.05 # mean and standard deviation nmax=int( (p.tmax-p.tmin)/p.dt +1) count = 0 F = 0 #initial random force Fnoise = [F] for n in range(1,nmax,1): Fr = np.random.normal(mu, sigma) Fn = R*F + sqrt(1- R**2) * Fr if noise_switch == True : F = Fn Fnoise.append(F) Fnoise = array(Fnoise) print " " print "mean Fnoise =", mean(abs(Fnoise)) return Fnoise 4

"""Loop choice: once with noise or once without noise, or both"""


switch = [True] #switch = [False] #switch = [True,False] for i in switch:

"""Create Instances"""
p = DoublePendulum_RK4(E=6, q1=p_q1, q2=p_q2, p1=0.0, tmax = tmax, number = 1) p_prime = DoublePendulum_RK4(E=6, q1=p_q1, q2=p_q2_prime, p1=0.0, tmax = tmax, number = 1)

#NonChaotic p #p = DoublePendulum_RK4(E=0.05, q1=0.01, q2=-0.010000, p1=0.0, tmax = tmax, number = 1) #p_prime = DoublePendulum_RK4(E=0.05, q1=0.01, q2=-0.010001, p1=0.0, tmax = tmax, number = 1)
p2 = DoublePendulum_RK4(E=6, q1=p2_q1, q2=p2_q2, p1=0.0, tmax = tmax, number = 2) p2_prime = DoublePendulum_RK4(E=6, q1=p2_q1, q2=p2_q2_prime, p1=0.0, tmax = tmax, number = 2)

"""Calculation of trajectory, with/out noise, dissipation"""


Fnoise = noise(noise_switch=i) #damp = 0.00 damp = 0.05 p.trajectory(Fnoise, damp) p_prime.trajectory(Fnoise, damp) p2.trajectory(Fnoise, damp) p2_prime.trajectory(Fnoise, damp)

"""Plots""" #IC1.append(p.plotIC(fig = True)) #p.plotPS() #p.poincare(21) p.plotEnergy() p.plot3Dtraj(31) p.plotDamp(damp) Lyap.append( p.Lyapunov(p_prime.phaseSpace, fig = True ) ) #IC2.append(p2.plotIC(fig = True)) #p2.plotPS() #p2.poincare(22) p2.plotEnergy() p2.plot3Dtraj(32) p2.plotDamp(damp) Lyap2.append( p2.Lyapunov(p2_prime.phaseSpace, fig = True ) )
p2.plotNoise(Fnoise)

#p2.plotScale()
SqDist.append(p.dist(p2.phaseSpace, fig = True, noise = i )) BIGloopcount = BIGloopcount +1 print print print print " " "#############" "BIGloopcount =", BIGloopcount "##############"

"""Calculate mean square distance"""


SqDist = array(SqDist) MeanSqDist = SqDist[0] * 0 for i in xrange(len(SqDist)): MeanSqDist = MeanSqDist + SqDist[i] MeanSqDist = MeanSqDist/len(SqDist)

#BIGLoop variable plots def plotBIGloop(): figure(71) semilogy(p.t,MeanSqDist) xlabel("time") ylabel('Mean Square Distance (PhaseSpace)') legend() #plotBIGloop()
show()

17

Vous aimerez peut-être aussi