[关闭]
@ibilis 2016-10-30T11:39:46.000000Z 字数 1648 阅读 578

第七次作业

计算物理


1.正文

1.方程推导


2.代码

  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Oct 29 15:38:19 2016
  4. @author: dw
  5. """
  6. import math
  7. import pylab as pl
  8. class pendu:
  9. 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):
  10. self.q=q
  11. self.Od=Od
  12. self.dt=time_step
  13. self.Fd1=Fd_1
  14. self.Fd2=Fd_2
  15. self.theta_1=[theta10]
  16. self.theta_2=[theta20]
  17. self.d_theta=[0]
  18. self.t=[0]
  19. self.w_1=[0]
  20. self.w2=[0]
  21. self.nsteps=int(a_t//time_step +1)
  22. def calculate(self):
  23. for i in range(self.nsteps):
  24. 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)
  25. self.theta_1.append(self.theta_1[i]+self.w_1[i+1]*self.dt)
  26. 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)
  27. self.theta_2.append(self.theta_2[i]+self.w2[i+1]*self.dt)
  28. if self.theta_1[i+1]<-math.pi :
  29. self.theta_1[i+1]=self.theta_1[i+1]+2*math.pi
  30. elif self.theta_1[i+1]>math.pi :
  31. self.theta_1[i+1]=self.theta_1[i+1]-2*math.pi
  32. else :
  33. pass
  34. if self.theta_2[i+1]<-math.pi :
  35. self.theta_2[i+1]=self.theta_2[i+1]+2*math.pi
  36. elif self.theta_2[i+1]>math.pi :
  37. self.theta_2[i+1]=self.theta_2[i+1]-2*math.pi
  38. else :
  39. pass
  40. self.d_theta.append(math.log(abs(self.theta_1[i]-self.theta_2[i])))
  41. self.t.append(self.t[i]+self.dt)
  42. def show(self):
  43. pl.plot(self.t,self.theta_1,'r')
  44. pl.plot(self.t,self.theta_2,'g')
  45. pl.legend(loc='best')
  46. a= pendu()
  47. a.calculate()
  48. a.show()

3.结果

阻尼系数

时,只微小的改变初始角度,结果如下
20161030184711.png
当阻尼系数有微小差距时
20161030184925.png
第一次

变化后



20161030190758.png
20161030190440.png

4。结束

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注