@2014301020054
2016-11-13T17:45:12.000000Z
字数 4128
阅读 587
python physics 2014301020054 陈佩卓
Using Euler-Cromer method to solve the oscillatory motion.
Also using class function,and take more factors into consideratioon.
Find out how the value of influences the routes of the chaos.
We can use Euler method to solve some easy questions, but to solve the problem of the oscillatory motion and chaos with the conservation of energy, we cannot solve the problems easily by Euler method. we should use Euler-Cromer method to find the answer.
we know the Euler-Cromer method. Now I will take the Euler-Cromer method into the oscillatory motion and chaos calculation:
Newton’s second law for ideal pendulum with small angle:
Write the second-order equations as two firest-order differential equations:
Finite difference form with Euler-Cromer method:
To make the question more realistic,we can take some factors into consideration.
We do not assume the small-angle approximation, and thus do not expand term in
We include friction of the form
We add to our model a sinusoidal driving force
Putting all of these ingredients together, we have the equation of motion:
We can rewrite the two-order differential equation now as two first-order differential equations and obtian:
Finite difference form with Euler-Cromer method:
If is out of the range , add or subtract to keep it in this range.
And for the pioncare section, we chose the time that:
Question 3.18
Calculate Poincare sections for the pendulum as it undergoes the period-doubling route to chaos. Plot versus , with one point plotted for each drive cycle, as in Figure 3.9. Do this for , and , using the other parameters as given in connection with Figure 3.10. You should find that after removing the points corresponding to the initial transient the attractor in the period-1 regime will contain only a single point. Likewise, if the behavior is period , the attractor will contain discrete points.
import pylab as plimport mathclass oscillatory:def __init__(self,g=9.8,l=9.8,q=0.5,F_D=1.2,O_D=2/3,time_step=3*math.pi/1000,\total_time=100,initial_theta=0.2,initial_omega=0):self.g=gself.l=lself.q=qself.F=F_Dself.O=O_Dself.t=[0]self.initial_theta=initial_thetaself.initial_omega=initial_omegaself.dt=time_stepself.time= total_timeself.omega= [initial_omega]self.theta= [initial_theta]self.nsteps=int(total_time//time_step+1)self.tmpo=[0]self.tmpt=[0]def run(self):for i in range(self.nsteps):tmpo=self.omega[i]+(-1*(self.g/self.l)*math.sin(self.theta[i])-\self.q*self.omega[i]+self.F*math.sin(self.O*self.t[i]))*self.dttmpt=self.theta[i]+tmpo*self.dtwhile(tmpt<(-1*math.pi) or tmpt>math.pi):if tmpt<(-1*math.pi):tmpt+=2*math.piif tmpt>math.pi:tmpt-=2*math.piself.omega.append(tmpo)self.theta.append(tmpt)self.t.append(self.t[i]+self.dt)for i in range(len(self.t)):if self.t[i] // (3 * math.pi) > 300:if ((2 / 3 * self.t[i]) % (2 * math.pi)) <= (2 / 3 * self.dt * 0.5) or (2 * math.pi - ((2 / 3 * self.t[i]) % (2 * math.pi))) <= (2 / 3 * self.dt * 0.5):self.tmpo.append(self.omega[i])self.tmpt.append(self.theta[i])def show_results(self):font = {'family': 'serif','color': 'darkred','weight': 'normal','size': 16,}pl.plot(self.t,self.theta)#pl.scatter(self.tmpt, self.tmpo)pl.title(r'$\theta$ versus time', fontdict = font)pl.xlabel(r'$\theta$(radians)')pl.ylabel(r'$\omega$(rad/s)')#pl.xlim(0,3)#pl.ylim(-3,0)pl.legend((['$F_D$=1.2']))pl.show()a = oscillatory()a.run()a.show_results()

If we chose the time :
where n is integer and is a angle between .
We will have the result that:

1.We can solve the oscillatory motion by using Euler-Cromer method easily.We can see chaos when the problem become more complex,and from this problem,we know that the period of chaos is related to .
2.we can easily find the period of the pendulum by choosing the time .