@ibilis
2016-10-30T11:39:46.000000Z
字数 1648
阅读 578
计算物理
# -*- coding: utf-8 -*-"""Created on Sat Oct 29 15:38:19 2016@author: dw"""import mathimport pylab as plclass pendu:def __init__(self, q=0.5,g=9.8,l=9.8,Od=2/3,dt=0.04,Fd_1=1.2,Fd_2=1.2,a_t=400,time_step=0.04,theta10=0.201,theta20=0.2,d_theta0=0.001):self.q=qself.Od=Odself.dt=time_stepself.Fd1=Fd_1self.Fd2=Fd_2self.theta_1=[theta10]self.theta_2=[theta20]self.d_theta=[0]self.t=[0]self.w_1=[0]self.w2=[0]self.nsteps=int(a_t//time_step +1)def calculate(self):for i in range(self.nsteps):self.w_1.append(self.w_1[i]-math.sin(self.theta_1[i])*self.dt-self.q*self.w_1[i]*self.dt+self.Fd1*math.sin(2*self.t[i]/3)*self.dt)self.theta_1.append(self.theta_1[i]+self.w_1[i+1]*self.dt)self.w2.append(self.w2[i]-math.sin(self.theta_2[i])*self.dt-self.q*self.w2[i]*self.dt+self.Fd2*math.sin(2*self.t[i]/3)*self.dt)self.theta_2.append(self.theta_2[i]+self.w2[i+1]*self.dt)if self.theta_1[i+1]<-math.pi :self.theta_1[i+1]=self.theta_1[i+1]+2*math.pielif self.theta_1[i+1]>math.pi :self.theta_1[i+1]=self.theta_1[i+1]-2*math.pielse :passif self.theta_2[i+1]<-math.pi :self.theta_2[i+1]=self.theta_2[i+1]+2*math.pielif self.theta_2[i+1]>math.pi :self.theta_2[i+1]=self.theta_2[i+1]-2*math.pielse :passself.d_theta.append(math.log(abs(self.theta_1[i]-self.theta_2[i])))self.t.append(self.t[i]+self.dt)def show(self):pl.plot(self.t,self.theta_1,'r')pl.plot(self.t,self.theta_2,'g')pl.legend(loc='best')a= pendu()a.calculate()a.show()
阻尼系数
