Study of Forced Double Pendulums

download Study of Forced Double Pendulums

of 17

Transcript of Study of Forced Double Pendulums

  • 8/13/2019 Study of Forced Double Pendulums

    1/17

    .

    PHYS 2030 Final Project:

    Study of trajectories of two double pendulums under external random forcing

    Rizki SyarifDepartment 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 influenceof an external stochastic force. Specifically we investigate the role of noise and dissipation on theconvergence of the trajectories of two chaotic systems and on its transition from chaotic to nonchaoticbehaviour, similar to what have been studied by reference [1] and [2]. We use double pendulumsas our chaotic system and use a model for stochastic forcing as used by reference [3]. Also, weperform our calculations using the fourth-order Runge-Kutta method.

    1. INTRODUCTION

    Chaotic behaviour can present itself through simplesystems such as a double pendulum. This is the con-figuration where one pendulum is connected to the end

    of another pendulum. Motivated by references [1] and[2], we investigate the behaviour of chaotic double pen-dulums that are driven by an external stochastic forceor noise. We also investigate possible synchronisation orconvergence of trajectory between two identical doublependulums under the same noise.

    Ref [1] and Ref [4] claim to have observed a transi-tion from chaos to non chaos due to stochastic forcing.Whereas, Ref [2] refutes these claims by arguing thatthe stochastic force does not play part in the transitionrather it is dissipation that causes the transition. How-ever, Ref[2] claims that under noise, two identical chaoticsystem 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 stud-ied neither by Ref [1], [4] nor Ref [2]). We explore itschaotic and non chaotic behaviour, and later investigatethe effect of noise and dissipation to the system, and howthese contribute to the convergence of trajectories and tothe transition from chaotic to non chaotic behaviour.

    The report is organised as follows. First we discusschaos in double pendulums, modelling and the equationsof motion. Then we elaborate on the methods of calcu-lations we use to measure chaos and convergence. Fol-lowing that we briefly do a test calculation to check forthe initial conditions that will lead to chaotic behaviour.Then we discuss results followed by conclusions and dis-cussion.

    2. CHAOS AND THE DOUBLE PENDULUM

    Chaos can be characterised as apparent random be-havior and extreme sensitivity to initial conditions de-spite the system being deterministic [5]. This is due thenonlinear nature of the dynamics.

    At certain initial conditions the double pendulum mayexhibit chaotic behaviour. Typically, at large angle ini-tial conditions a double pendulum will exhibit chaoticbehaviour and at small angle initial conditions it ex-hibits approximately linear dynamical motion which is

    non chaotic and stable. We will discuss more about theinitial conditions at later section.

    The double pendulum that is considered in this reportconsists of two equal masses attached to two equal lengthmassless rod (see Figure1).

    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 definingthe following:

    x1 = l sin 1 (1)

    y1 = l cos 1 (2)

    x2 = l sin 1+l sin 2 (3)

    y2 = l cos 1 l cos 2 (4)

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

  • 8/13/2019 Study of Forced Double Pendulums

    2/17

    2

    the potential energy:

    T = 1

    2m(x21+ y

    21) +

    1

    2m(x22+ y

    22) (5)

    = ml2(21+1

    222+

    11cos (1 2)) (6)

    and

    U =

    mgy1 mgy2 (7)

    = mgl(2 cos 1+cos2) (8)

    We rescale such that m, l, g are no longer appear inour equations1. Then we further define qi = i, pi =

    Lqi

    ,

    where i = 1, 2 and L = T U is the lagrangian. Thehamiltonian,H=piqi L, of the system is:

    H= 1

    2

    p21 2p22cos (q1 q2)

    1 + sin (q1 q2)2 2cos q1 cos q2+ 3 (9)

    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 modelfrom Ref. [3]. The function is written as the followingrecursion relation

    Fn+1= RnFn+

    (1 R2n)Fn+1 (10)

    where R is the coefficient defined by

    Rn = 1

    t

    2

    1 + t2

    (11)

    wheren is the number of time steps, is the decay timeconstant ofF, t is the step size, and F is a randomlygenerated number from a gaussian centered at zero anda standard deviation of.

    The decay time determines the timescale at whichthe random (noise) force varies. To achieve the desiredeffect, we will set such that noise varies in timescalesmuch larger than the time step size t, but smaller thanthe typical period of our pendulum (which is in the orderof a few time units 2).

    2.3. Equations of motion

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

    1 This can be done by rescaling our coordinates. But we can alsoset l = g and m = 1

    g22 See Figure2.

    qi = H

    pi(12)

    pi = H

    qi+Fext Fdis (13)

    where i = 1, 2, Fext is the noise as described by Eq. 10

    and the last term Eq. 13 is the dissipation term. Wewill consider two cases. One where the dissipation isproportional to the conjugate momentum, ie. Fdis = p,and second where it is proportional to the rate of changeof the angles, ie. Fdis = q, and is the dissipationcoefficient.

    3. METHODS OF CALCULATION

    3.1. Numerical Method

    We implement the fourth-order Runge-Kutta numer-

    ical method3

    for integrating the equations motion inEq. 12-13 to obtain the trajectories of the double pen-dulum. Also, we use a time step size t = 0.01 and wechoose our decay time constant for the noise force= 0.1for all of our proceeding calculations 4.

    We check that this numerical method setting gives usthe correct physics, ie. we check for reasonableness oftrajectories and for energy conservation. First, we setthe initial angles of the pendulum to be close to zero andset the initial conjugate momentum such that the energyis 1 unit. Then set the initial angles and initial conjugatemomentums such that energy is 6 units.

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

    unit.

    We calculate trajectories and energies of the doublependulums in the absence of noise and dissipation. Fig-ure 2 and Figure 4 show the trajectory of the double

    3 This method reproduces the taylor expansion of a function up tofourth order. The local truncation of this method is to order offive[6].

    4 This avoids instability of simulation since typical period of pen-dulum is in the order of 1. So we have t < < Tperiod.

  • 8/13/2019 Study of Forced Double Pendulums

    3/17

    3

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

    pendulums for energy=1 and energy=6 respectively, andthe plots show expected trajectories. More importantly,Figure 3 and Figure 5 show the energy changes in theorder of 107 energy units for the low energy pendulum,and 105 energy units for the high energy pendulum, in100 time units. These tests confirm that our numeri-cal method is producing the correct physics and that thenumerical errors are sufficiently small.

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

    3.2. Measuring chaos

    The way we measure chaos is by calculating what iscalled the Lyapunov exponent. Chaos can be definedby this exponent. If we have two initial conditions, andthey differ by x0 then a chaotic system will have thisseparation grow exponentially in time, ie

    x= x0et (14)

    where is the Lyapunov exponent. So for our doublependulum, given two initial conditions and their sepa-ration, if the Lyapunov exponent is positive or if the

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

    growth of separation with respect to the initial condi-tion diference, ie. x

    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 stepsn= t

    t.

    = 1

    nt

    n

    i=1

    xi+1

    xi

    (15)

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

    3.3. Distance calculation of two double pendulums

    To investigate convergence of trajectories or synchro-nisation between two double pendulum, we calculatethe distance in phase space between two chaotic dou-ble pendulums. More specifically, we calculate norm ofx(q1, p1, q2, p2). We restrict the maximum sep-aration distance to be radians for the angles. To em-phasise differences between distances we calculate thesquare of the norm. (See Figure 6 for a schematic di-agram of the two double pendulums).

    FIG. 6: Schematic diagram of two pendulums under noise

  • 8/13/2019 Study of Forced Double Pendulums

    4/17

    4

    4. INITIAL CONDITIONS LEADING TOCHAOS

    We perform numerical calculations to show that theinitial conditions we use in this investigation do producechaotic behaviour. We contrast it to the low angle low en-ergy initial condition where the behaviour is non chaotic.

    For the (large angle large energy) initial condition thatwe expect to produce chaotic behaviour, we generate ran-dom numbers between and radians for the anglesof both the lower and upper pendulum and we choose avalue of energy of 6 units, where an energy of 0 representsthe pendulum at rest lying straight down, and an energyof 6 units represents the pendulum at rest at the highestposition, i.e. both rod positioned straight up. This initialenergy will determine the initial conjugate momentum ofthe lower pendulum.

    For the non chaotic or low angle initial condition wechoose an angle of 0.01 radians for both the lower andupper pendulum and we choose the initial energy to be

    0.05. For this calculation

    5

    , we set noise and dissipationto be zero.To measure the sensitivity to initial conditions, we cal-

    culate the trajectory of initial conditions that differ onlyby 0.000001 for the angle of the lower pendulum6. Fig-ure7 shows the sensitivity of initial conditions for boththe large angle and the low angle.

    We can see in Figure 7 (top plot) that the growth isexponential for the large angle initial condition as shownby the positive (approximately) linear increase in thesemilog plot fort

  • 8/13/2019 Study of Forced Double Pendulums

    5/17

    5

    ted the growth difference of trajectory with respect toa slightly different initial condition ( x

    x0) and also the

    Lyapunov exponent for both double pendulums. We cal-culate once with noise and once without noise (see Fig-ure9).

    FIG. 9: Top: Growth of xx0

    over time in semilog plot of fourdouble pendulums. Blue and green represents the growthdouble pendulums under noise, red and cyan line representsthe growth for double pendulums without noise. Bottom: TheLyapunov exponents as a function of time.

    We see in Figure9that xx0

    grows at a higher rate withnoise than without noise. We also observe that noisecauses the double pendulums to have higher value forLyapunov exponent any given time. From these obser-vations, it seems that noise (Figure 10) has caused the

    system to be more chaotic.

    FIG. 10: Noise produced using Eq.10with Frandomly gener-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 theenergy to see how noise has affected the total energy of

    the system (see Figure11). We observe that this noise,in this time scale, does not cause the energy to divergesignifincantly.

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

    5.2. Trajectories with noise and dissipation

    In this section, we analyse the effect noise with theaddition of dissipation to the double pendulums. Weperform the same calculations as in the previous section.

    However this time we keep set dissipation coefficient to be constant at 0.05. First we consider the dissipationterm being proportional to the conjugate momentum, ie.Fdis = p.

    We calculate the square of the distance over time be-tween two double pendulums starting from different ini-tial conditions. We do two calculations, one with noiseand the other without noise (see Figure12).

    We observe no clear indication of convergence due tonoise. It is clear that dissipation is at least the majorfactor that causes the trajectories to converge as shownby Figure12 where the distances tends towards zero.

    We also observe that the effect of noise with the pres-

    ence of dissipation causes the system to become slightlymore chaotic in the beginning as shown by the growthof x

    x0in time (see Figure13). At t = 20 to t = 40 the

    system transitions to non chaotic regime, and at t > 40the pendulums become stable and non chaotic shown bythe negative growth of the initial condition separation.

    The energies of the pendulums decrease over time asexpected because of the presence of dissipation (see Fig-ure14). There is little effect on how energy changes dueto noise.

    We repeat all the above calculations using a slightlydifferent dissipation term in the equation of motion. We

  • 8/13/2019 Study of Forced Double Pendulums

    6/17

    6

    FIG. 12: Square of the distance between two double pendu-lums under noise ( = 0.01) with dissipation ( = 0.05) upto t=100 (10000 iterations).

    FIG. 13: Top: Growth of xx0

    over time in semilog plot offour double pendulums with dissipation proportional to theconjugate momentum. Blue and green represents the growthdouble pendulums under noise, red and cyan line representsthe growth for double pendulums without noise. Bottom: TheLyapunov exponents as a function of time.

    consider a dissipation term that is proportional to therate of change of the angles, ie. qi. We obtain differentresults for the distance calculation and the initial condi-tion sensitivity calculation.

    In this configuration, the plot (Figure 15) seems toshow that the pendulums under noise converges morequickly than the ones without noise. However, it is stillnot evident whether or not noise is the cause of this, orwhether this is just random fluke. We will explore thismore in Section5.3. It is also not evident that noise hasany affect on the transition from chaos to non chaos (seeFigure16).

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

    FIG. 15: Square of the distance between two double pendu-lums under noise ( = 0.01) with dissipation ( = 0.05) upto t=100 (10000 iterations).

    5.3. Mean Square Distance

    To get a better measure of the effect of noise to the tra-jectories, we produce 100 double pendulum pairs. Eachwith randomly generated initial conditions and then wecalculate the mean of the square of the distances at eachtime step and plot them over time. We calculate with dif-ferent values for the standard deviation () of the gaus-

    sian that generates F in Eq.10.Similar to previous section, first we calculate using the

    dissipation term p(see Figure17) and the we calculateonce more using q(see Figure18). Both Figure17 andFigure 18 show that for different noise amplitudes theconvergence is slower or about as fast as without noise.

  • 8/13/2019 Study of Forced Double Pendulums

    7/17

    7

    FIG. 16: Top: Growth of xx0

    over time in semilog plot of fourdouble pendulums with dissipation proportional to the rateof change of the angle. Blue and green represents the growthdouble pendulums under noise, red and cyan line represents

    the growth for double pendulums without noise. Bottom: TheLyapunov exponents as a function of time.

    FIG. 17: Mean square distance of 100 pairs of double pen-dulums where the noise is proportional to the conjugate mo-mentum. Different colors represent different values used inthe calculation (for noise).

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

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

    6. CONCLUSION AND DISCUSSION

    We investigate the behaviour of double pendulums ex-

    posed to an external stochastic forcing. Using the fourthorder Runge-Kutta numerical method, we calculate thegrowth of the difference of two trajectories with respect

    FIG. 18: Mean square distance of 100 pairs of double pendu-lums where the noise is proportional to the rate of change ofthe angles. Different colors represent different values usedin the calculation (for noise).

    to the difference of two initial conditions and we alsolook at the Lyapunov exponents. Then we calculatedthe square of the distance in phase space of trajectoriesof two doubles pendulums with initial conditions thatare randomly generated and with exposure to noise anddissipation. Furthermore we calculated the mean of thesquare of distances of 100 pairs of double pendulums.

    There seems to be no indication of transition fromchaos to non chaos due to noise where dissipation is notpresent. When dissipation is present, and when the dissi-pation is either proportional to the conjugate momentumor to the rate of change of the angles, we observe no clearevidence that noise may speed up convergence of trajec-

    tories. We were not able to reproduce the findings bothby Ref.[1] and Ref.[2] using the double pendulum.

    [1] S. Fahy and D. R. Hamann, Transition from chaotic tononchaotic 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 sys-tems, Phys. Rev. E53, 6551 (1996), URL http://link.aps.org/doi/10.1103/PhysRevE.53.6551.

    [3] D. K. Lilly, Numerical Simulation of Two-DimensionalTurbulence, 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 synchro-nization, Phys. Rev. Lett. 72, 1451 (1994), URL http://link.aps.org/doi/10.1103/PhysRevLett.72.1451.

    http://link.aps.org/doi/10.1103/PhysRevLett.69.761http://link.aps.org/doi/10.1103/PhysRevLett.69.761http://link.aps.org/doi/10.1103/PhysRevE.53.6551http://link.aps.org/doi/10.1103/PhysRevE.53.6551http://link.aps.org/doi/10.1103/PhysRevE.53.6551http://scitation.aip.org/content/aip/journal/pof1/12/12/10.1063/1.1692444http://scitation.aip.org/content/aip/journal/pof1/12/12/10.1063/1.1692444http://scitation.aip.org/content/aip/journal/pof1/12/12/10.1063/1.1692444http://link.aps.org/doi/10.1103/PhysRevLett.72.1451http://link.aps.org/doi/10.1103/PhysRevLett.72.1451http://link.aps.org/doi/10.1103/PhysRevLett.72.1451http://link.aps.org/doi/10.1103/PhysRevLett.72.1451http://link.aps.org/doi/10.1103/PhysRevLett.72.1451http://scitation.aip.org/content/aip/journal/pof1/12/12/10.1063/1.1692444http://scitation.aip.org/content/aip/journal/pof1/12/12/10.1063/1.1692444http://link.aps.org/doi/10.1103/PhysRevE.53.6551http://link.aps.org/doi/10.1103/PhysRevE.53.6551http://link.aps.org/doi/10.1103/PhysRevLett.69.761http://link.aps.org/doi/10.1103/PhysRevLett.69.761
  • 8/13/2019 Study of Forced Double Pendulums

    8/17

    8

    [5] A. L. Fetter and J. D. Walecka, Nonlinear Mechanics -A Supplement to Theoretical Mechanics of Particles andContinua(Dover Publications, 2006), 1st ed.

    [6] W. Press, B. Flannery, S. Teukolsky, and W. Vetterling,Numerical Recipes in C: The Art of Scientific Comput-ing (Cambridge University Press, 1992), 2nd ed., ISBN0521431085.

    [7] T. Shinbrot, C. Grebogi, J. Wisdom, and J. A.Yorke, Chaos in a double pendulum, Amer-ican Journal of Physics 60, 491 (1992), URLhttp://scitation.aip.org/content/aapt/journal/

    ajp/60/6/10.1119/1.16860.

    Acknowledgments

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

    http://scitation.aip.org/content/aapt/journal/ajp/60/6/10.1119/1.16860http://scitation.aip.org/content/aapt/journal/ajp/60/6/10.1119/1.16860http://scitation.aip.org/content/aapt/journal/ajp/60/6/10.1119/1.16860http://scitation.aip.org/content/aapt/journal/ajp/60/6/10.1119/1.16860http://scitation.aip.org/content/aapt/journal/ajp/60/6/10.1119/1.16860
  • 8/13/2019 Study of Forced Double Pendulums

    9/17

    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

  • 8/13/2019 Study of Forced Double Pendulums

    10/17

    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

  • 8/13/2019 Study of Forced Double Pendulums

    11/17

    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.

  • 8/13/2019 Study of Forced Double Pendulums

    12/17

    importmath

    fromnumpyimport*

    frompylabimport*

    fromscipy.integrateimportodeint

    importmatplotlibasmpl

    frommpl_toolkits.mplot3dimportAxes3D

    importrandom

    classDoublePendulum_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

    defp2(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

    deftrajectory(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

    defderivative(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 =(p1 -p2 *cos(q1 -q2)) *denom

    p1dot =-2.0*sin(q1) -p1 *p2 *sin(q1 -q2) *denom +numer *sin(q1 -q2) *cos(q1 -q2) *denom**2+noise -damp *q1dot

    q2dot =(2.0*p2 -p1 *cos(q1 -q2)) *denom p2dot =-sin(q2) -p1 *p2 *sin(q2 -q1) *denom +numer *sin(q2 -q1) *cos(q1 -q2) *denom**2+noise -damp *q2dot

    returnarray([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

    ############################################################

    defRK4(self, derivative,tmin,tmax,phaseSpace,t0,dt,noise, damp):

    yi=[phaseSpace]

    ti=[t0]

    nmax=int( (tmax-tmin)/dt +1)

    print"nmax = ", nmax

    count =0

    forn inrange(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

    ifcount%5000==0: print"count = ", count," no.",self.number

    yi.remove(yi[0])

    yi.insert(0,phaseSpace.tolist())

    yi =array(yi)

    1

    Appendix C: Python code

  • 8/13/2019 Study of Forced Double Pendulums

    13/17

  • 8/13/2019 Study of Forced Double Pendulums

    14/17

    xlabel("X")

    ylabel("Y")

    axis([-2,2,-2,2])

    #legend()

    return[x1,y1,x2,y2]

    defplotPS(self):

    figure(1)

    ifself.number ==1:plot(self.phaseSpace[:, 0], self.phaseSpace[:, 1], label ="pendulum 1") ifself.number ==2:plot(self.phaseSpace[:, 0], self.phaseSpace[:, 1], label ="pendulum 2")

    title("trajectory")

    xlabel("q1")

    ylabel("p1")

    legend()

    defplot3Dtraj(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()

    defplotEnergy(self):

    figure(2)

    energyArray =self.Hamiltonian()

    ifself.number ==1: plot(self.t, energyArray, label ="pendulum 1")

    ifself.number ==2: plot(self.t, energyArray, label ="pendulum 2")

    xlabel("time")

    ylabel("energy")

    legend()

    defplotNoise(self,Fnoise):

    figure(4)

    plot(self.t, Fnoise, "r")

    title("Noise vs time")

    xlabel("time")

    ylabel("noise")

    defplotDamp(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)

    defpoincare(self,num):

    q1 =self.phaseSpace[:, 0]

    p1 =self.phaseSpace[:, 1]

    q2 =self.phaseSpace[:, 2]

    p2 =self.phaseSpace[:, 3]

    xList =[]

    yList =[]

    fori inrange(len(q1)-1):

    if(p2[i] >0.0):

    if(sin(q2[i])/sin(q2[i+1])

  • 8/13/2019 Study of Forced Double Pendulums

    15/17

    defLyapunov(self,phaseSpace_prime,fig=False):

    delta_pS =self.phaseSpace-phaseSpace_prime

    ndelta_pS =[]

    fori inxrange(len(delta_pS)):

    ndelta_pS.append(norm(delta_pS[i]))

    ndelta_pS =array(ndelta_pS)

    sumLog =[0.]ratio =[]

    lambd =[0.0]

    fori inxrange(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])

    iffig ==True:

    print" "

    print"Mean Lyapunov exponent p(",self.number,") = ", lambd[-1]

    figure(6)

    subplot(2,1,1)

    ifself.number ==1: semilogy(self.t, ndelta_pS, "-", label ='pendulum 1')

    ifself.number ==2: semilogy(self.t, ndelta_pS, "-", label ='pendulum 2')

    title("")

    ylabel("delta x / delta x0")

    subplot(2,1,2)

    ifself.number ==1: plot(self.t, lambd, label ='pendulum 1')

    ifself.number ==2: plot(self.t, lambd, label ='pendulum 2')

    ylabel('lambda')

    xlabel('time')

    legend()

    self.log_ndelta_pS =log(ndelta_pS)

    returnlambd

    defshow(self):

    show()

    BIGloop =1

    IC1 =[]

    IC2 =[]

    Lyap =[]

    Lyap2 =[]

    SqDist =[]BIGloopcount =0

    fori inxrange(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"""

    defnoise(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]

    forn inrange(1,nmax,1):

    Fr =np.random.normal(mu, sigma)

    Fn =R*F +sqrt(1-R**2) *Fr

    ifnoise_switch ==True: F =Fn

    Fnoise.append(F)

    Fnoise =array(Fnoise)

    print" " print"mean Fnoise =", mean(abs(Fnoise))

    returnFnoise

    4

  • 8/13/2019 Study of Forced Double Pendulums

    16/17

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

    switch =[True]

    #switch = [False]

    #switch = [True,False]

    fori inswitch:

    """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"BIGloopcount =", BIGloopcount

    print"##############"

    """Calculate mean square distance"""

    SqDist =array(SqDist)

    MeanSqDist =SqDist[0] *0

    fori inxrange(len(SqDist)):

    MeanSqDist =MeanSqDist +SqDist[i]

    MeanSqDist =MeanSqDist/len(SqDist)

    #BIGLoop variable plotsdefplotBIGloop():

    figure(71)

    semilogy(p.t,MeanSqDist)

    xlabel("time")

    ylabel('Mean Square Distance (PhaseSpace)')

    legend()

    #plotBIGloop()

    show()

    5

  • 8/13/2019 Study of Forced Double Pendulums

    17/17

    17