@74849b
2016-10-30T06:58:36.000000Z
字数 5951
阅读 605
One example of a simple pendulum is a particle of mass connected by a massless string to a rigid support. is the angle that the string makes with the verticle.Given the force that the particle beard,the force perpendicular to the string is given by
Code as follows:
import matplotlib.pyplot as plt
import math
class pendulum_1:
def __init__(self,time_step=0,theta1=0,theta2=0,time_of_duration=0,fd=0.5,q=0.5):
self.theta1=[theta1]
self.theta2=[theta2]
self.dt=time_step
self.fd=fd
self.q=q
self.t=[0]
self.w1=[0]
self.w2=[0]
self.nsteps=int(time_of_duration//time_step+1)
def calculate(self):
self.v=[]
wd=float(2.0/3)
for i in range(self.nsteps):
self.w1.append(self.w1[i]+(-math.sin(self.theta1[i])-self.q*self.w1[i]+self.fd*math.sin(wd*self.t[i]))*self.dt)
self.theta1.append(self.theta1[i]+self.w1[i+1]*self.dt)
self.w2.append(self.w2[i]+(-math.sin(self.theta2[i])-self.q*self.w2[i]+self.fd*math.sin(wd*self.t[i]))*self.dt)
self.theta2.append(self.theta2[i]+self.w2[i+1]*self.dt)
self.t.append(self.t[i]+self.dt)
self.v=list(map(lambda x:abs(x[0]-x[1]),zip(self.theta1,self.theta2)))
if self.theta1[i+1]<-math.pi:
self.theta1[i+1]=self.theta1[i+1]+2*math.pi
if self.theta1[i+1]>math.pi:
self.theta1[i+1]=self.theta1[i+1]-2*math.pi
if self.theta2[i+1]<-math.pi:
self.theta2[i+1]=self.theta2[i+1]+2*math.pi
if self.theta2[i+1]>math.pi:
self.theta2[i+1]=self.theta2[i+1]-2*math.pi
return 0
def show_calculate(self,color):
plt.plot(self.t,self.v,color,label="fd=%r"%(self.fd))
plt.title('difference of theta versus time fd=0.5')
plt.xlabel('time/s')
plt.ylabel('difference of theta/radians')
plt.ylim(0,0.001)
a=pendulum_1(0.04,0.200,0.199,60,0,0.5)
a.calculate()
a.show_results('red')
plt.legend()
plt.show()
a=pendulum_1(0.04,0.200,0.199,60,0.5,0.5)
a.calculate()
a.show_results('red')
plt.legend()
plt.show()
a=pendulum_1(0.04,0.200,0.199,60,1.2,0.5)
a.calculate()
a.show_results('red')
plt.legend()
plt.show()
First,draw three plots that behaviours of vary as a function of time for our driven for several different values of the driving force:
At low drrive,the motion is a simple oscillation.On the other hand,at high drive the motion is chaotic.The behaviour can be both deterministic and unpredictable at the same time.
Next,we consider the behaviour of two,nearly identicle pendulums.The results are as followings:
But the y axis'saccuracy isn't enough,the plot can't describe the quality of Lyapunov exponent.I modify the code,and calculate as a function of ,so we can obtain the following explicit results:
The first figure is plotted in ,we can easy to conclude is proportional to ,and ,which represents nonchaotic regimes.This means that the motion of the two pendulums becomes more and more similar,since the difference in the two angles approaches zero as the motion proceeds.
The second figure represents chaotic regimes with and .This is usually described by saying that the two trajectories, and ,diverge from one another.This system can obey certain deterministic laws of physics,but still exhibit behaviour that is unpredictable due to an extreme sensititvty to initial conditions.This's the nature of chaotic.
For ,we calculate the .Pick up two points from the turning point,such as:(0,-6.78) and (53.7,-20.35),we can obtain the slope:
Thanks for the following code(from baidu):
v=list(map(lambda x:x[0]-x[1],zip(v2-v1))