[关闭]
@rfhongyi 2016-11-09T03:41:39.000000Z 字数 7609 阅读 658

Exercise_07 : Oscillatory and Motion and Chaos

Problem 3.12 & 3.13 & 3.14

冉峰 弘毅班 2014301020064


Abstract

Background


The Main Body

Exercise 3.12, we could just easily have chosen to make the plot at times corresponding to a maximum of drive force, or at times out-of-phase with this force, etc.
code

  1. import pylab as pl
  2. import math
  3. class oscillatory:
  4. def __init__(self,g=9.8,l=9.8,q=0.5,F_D=1.2,O_D=2/3,time_step=0.001,\
  5. total_time=5000,initial_theta=0.2,initial_omega=0):
  6. self.g=g
  7. self.l=l
  8. self.q=q
  9. self.F=F_D
  10. self.O=O_D
  11. self.t=[0]
  12. self.initial_theta=initial_theta
  13. self.initial_omega=initial_omega
  14. self.dt=time_step
  15. self.time= total_time
  16. self.omega= [initial_omega]
  17. self.theta= [initial_theta]
  18. self.nsteps=int(total_time//time_step+1)
  19. self.tmpo=[0]
  20. self.tmpt=[0]
  21. def run(self):
  22. for i in range(self.nsteps):
  23. tmpo=self.omega[i]+(-1*(self.g/self.l)*math.sin(self.theta[i])-\
  24. self.q*self.omega[i]+self.F*math.sin(self.O*self.t[i]))*self.dt
  25. tmpt=self.theta[i]+tmpo*self.dt
  26. while(tmpt<(-1*math.pi) or tmpt>math.pi):
  27. if tmpt<(-1*math.pi):
  28. tmpt+=2*math.pi
  29. if tmpt>math.pi:
  30. tmpt-=2*math.pi
  31. self.omega.append(tmpo)
  32. self.theta.append(tmpt)
  33. self.t.append(self.t[i]+self.dt)
  34. for i in range(self.nsteps):
  35. if self.t[i]%(2*math.pi/self.O)<0.01:
  36. self.tmpo.append(self.omega[i])
  37. self.tmpt.append(self.theta[i])
  38. def show_results(self):
  39. font = {'family': 'serif',
  40. 'color': 'darkred',
  41. 'weight': 'normal',
  42. 'size': 16,}
  43. pl.plot(self.tmpt ,self.tmpo,'.',label='$F_{D}$=%.2f'%self.F)
  44. pl.title(r'$\omega$ versus $\theta$', fontdict = font)
  45. pl.xlabel(r'$\theta$(radians)')
  46. pl.ylabel(r'$\omega$(rad/s)')
  47. pl.legend((['$F_D$=1.2']))
  48. pl.show()
  49. a = oscillatory()
  50. a.run()
  51. a.show_results()

Result

7.9.png

7.10.png7.11.png

7.12.png


Exercise 3.13, imagine two identical pendulums only with slightly different initial angles and the difference is 0.001 rad.
- code

  1. import pylab as pl
  2. import math
  3. class oscillatory:
  4. def __init__(self,g=9.8,l=9.8,q=0.5,F_D=0.5,O_D=2/3,time_step=0.04,total_time=80,initial_theta=0.2,initial_omega=0,initial_omega1=0,initial_theta1=0.201,q1=0.5):
  5. self.g=g
  6. self.l=l
  7. self.q=q
  8. self.q1=q1
  9. self.F=F_D
  10. self.O=O_D
  11. self.t=[0]
  12. self.initial_theta=initial_theta
  13. self.initial_theta1=initial_theta1
  14. self.initial_omega=initial_omega
  15. self.dt=time_step
  16. self.time= total_time
  17. self.omega= [initial_omega]
  18. self.omega1=[initial_omega1]
  19. self.theta= [initial_theta]
  20. self.theta1= [initial_theta1]
  21. self.nsteps=int(total_time//time_step+1)
  22. self.D=[0]
  23. self.e=[0]
  24. def run(self):
  25. for i in range(self.nsteps):
  26. tmpo=self.omega[i]+(-1*(self.g/self.l)*math.sin(self.theta[i])-\
  27. self.q*self.omega[i]+self.F*math.sin(self.O*self.t[i]))*self.dt
  28. tmpt=self.theta[i]+tmpo*self.dt
  29. while(tmpt<(-1*math.pi) or tmpt>math.pi):
  30. if tmpt<(-1*math.pi):
  31. tmpt+=2*math.pi
  32. if tmpt>math.pi:
  33. tmpt-=2*math.pi
  34. self.omega.append(tmpo)
  35. self.theta.append(tmpt)
  36. tmpo1=self.omega1[i]+(-1*(self.g/self.l)*math.sin(self.theta1[i])-\
  37. self.q1*self.omega1[i]+self.F*math.sin(self.O*self.t[i]))*self.dt
  38. tmpt1=self.theta1[i]+tmpo1*self.dt
  39. while(tmpt1<(-1*math.pi) or tmpt1>math.pi):
  40. if tmpt1<(-1*math.pi):
  41. tmpt1+=2*math.pi
  42. if tmpt1>math.pi:
  43. tmpt1-=2*math.pi
  44. self.omega1.append(tmpo1)
  45. self.theta1.append(tmpt1)
  46. self.t.append(self.t[i]+self.dt)
  47. tmpD=abs(tmpt-tmpt1)
  48. self.D.append(tmpD)
  49. self.e.append(0.001*math.exp(-0.247*self.t[i]))
  50. def show_results(self):
  51. font = {'family': 'serif',
  52. 'color': 'darkred',
  53. 'weight': 'normal',
  54. 'size': 16,}
  55. pl.semilogy(self.t,self.D)
  56. pl.semilogy(self.t,self.e,'--')
  57. pl.title(r'$\Delta\theta$ versus time', fontdict = font)
  58. pl.xlabel('time(s)')
  59. pl.ylabel(r'$\Delta\theta$(radians)')
  60. pl.legend((['$F_D$=0.5']))
  61. pl.show()
  62. a = oscillatory()
  63. a.run()
  64. a.show_results()

Result


Exercise 3.14, imagine two identical pendulums only with slightly different initial q and the difference is 0.001.
- code

  1. import pylab as pl
  2. import math
  3. class oscillatory:
  4. def __init__(self,g=9.8,l=9.8,q=0.5,F_D=1.2,O_D=2/3,time_step=0.04,\
  5. total_time=150,initial_theta=0.2,initial_omega=0,initial_omega1=0,\
  6. initial_theta1=0.2,q1=0.501):
  7. self.g=g
  8. self.l=l
  9. self.q=q
  10. self.q1=q1
  11. self.F=F_D
  12. self.O=O_D
  13. self.t=[0]
  14. self.initial_theta=initial_theta
  15. self.initial_theta1=initial_theta1
  16. self.initial_omega=initial_omega
  17. self.dt=time_step
  18. self.time= total_time
  19. self.omega= [initial_omega]
  20. self.omega1=[initial_omega1]
  21. self.theta= [initial_theta]
  22. self.theta1= [initial_theta1]
  23. self.nsteps=int(total_time//time_step+1)
  24. self.D=[0]
  25. self.e=[0]
  26. def run(self):
  27. for i in range(self.nsteps):
  28. tmpo=self.omega[i]+(-1*(self.g/self.l)*math.sin(self.theta[i])-\
  29. self.q*self.omega[i]+self.F*math.sin(self.O*self.t[i]))*self.dt
  30. tmpt=self.theta[i]+tmpo*self.dt
  31. while(tmpt<(-1*math.pi) or tmpt>math.pi):
  32. if tmpt<(-1*math.pi):
  33. tmpt+=2*math.pi
  34. if tmpt>math.pi:
  35. tmpt-=2*math.pi
  36. self.omega.append(tmpo)
  37. self.theta.append(tmpt)
  38. tmpo1=self.omega1[i]+(-1*(self.g/self.l)*math.sin(self.theta1[i])-\
  39. self.q1*self.omega1[i]+self.F*math.sin(self.O*self.t[i]))*self.dt
  40. tmpt1=self.theta1[i]+tmpo1*self.dt
  41. while(tmpt1<(-1*math.pi) or tmpt1>math.pi):
  42. if tmpt1<(-1*math.pi):
  43. tmpt1+=2*math.pi
  44. if tmpt1>math.pi:
  45. tmpt1-=2*math.pi
  46. self.omega1.append(tmpo1)
  47. self.theta1.append(tmpt1)
  48. self.t.append(self.t[i]+self.dt)
  49. tmpD=abs(tmpt-tmpt1)
  50. self.D.append(tmpD)
  51. self.e.append(0.001*math.exp(0.25*self.t[i]))
  52. def show_results(self):
  53. font = {'family': 'serif',
  54. 'color': 'darkred',
  55. 'weight': 'normal',
  56. 'size': 16,}
  57. pl.semilogy(self.t,self.D)
  58. pl.semilogy(self.t,self.e,'--')
  59. pl.title(r'$\Delta\theta$ versus time', fontdict = font)
  60. pl.xlabel('time(s)')
  61. pl.ylabel(r'$\Delta\theta$(radians)')
  62. pl.legend((['$F_D$=1.2']))
  63. pl.show()
  64. a = oscillatory()
  65. a.run()
  66. a.show_results()

Result


Conclusion


Thanks For

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