[关闭]
@2014301020054 2016-11-06T16:33:30.000000Z 字数 5393 阅读 465

Exercise_7: Oscillatory and Motion and Chaos

physics python 3.13&3.14


Abstract

  • Using Euler-Cromer method to solve the oscillatory motion.

  • Also using class function,and take more factors into consideratioon.

Background

  • 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.

  1. We do not assume the small-angle approximation, and thus do not expand term in

  2. We include friction of the form

  3. 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.


Main body

Codes

  1. import pylab as pl
  2. import math
  3. class oscillatory:
  4. def __init__(self,g=10,l=10,q=0.5,F_D=0.5,O_D=2/3,time_step=0.04,\
  5. total_time=50,initial_theta=0.2,initial_omega=0,initial_omega1=0,\
  6. initial_theta1=0.201,q1=0.5):
  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.247*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$=0.5']))
  63. pl.show()
  64. a = oscillatory()
  65. a.run()
  66. a.show_results()

Reslut1:
1. F=0.5
结果1
2. F=1.2
结果2

Codes

  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()

Reslut2:
F=0.5
结果4
F=1.2
结果3


Conlusion


Acknowledgment

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