[关闭]
@zy-0815 2016-10-30T14:47:51.000000Z 字数 5541 阅读 1296

张梓桐计算物理第七次作业

1.Problem

3.12,3.13,3.14

2.Abstract

Having dicussed the Euler method in calculating projectile movement of a cannon shell,in the passage,we are going to talk about the Euler-Cromer method of the better calculation of oscillatory under damped and external force.

3.Background

Now we start to figure out the movement rule of a damped and forced pendulum.With the basic knowledge of Newtoon second law and the definition of , we have the following equation:


where is the module of the external force with unit,and is the frequency of external force,also with unit.
Here we introduce the variables to transfer the secdonary differential equation into firs-order differential equation:


Now we rewrite the physics formula into precodes,notcing the Euler-Cromer method,rather than Euler method,which will lead to a divergence in the infinity.

In problem 3.13 and 3.14,we are asked to calculate the and compare the behacior of two,nearly identical pendulums.And we are going to draw a ' versus time' plot.

3.Main body

3.1 Solution to 3.13,3.14

  1. import math
  2. import pylab as pl
  3. class oscillatory_motion():
  4. def __init__(self):
  5. intial_theta=0.2
  6. intial_w=0
  7. time_of_duration=150
  8. self.theta=[intial_theta]
  9. self.t=[0]
  10. self.w=[intial_w]
  11. self.dt=0.04
  12. self.q=0.5
  13. self.F_D=1.2
  14. self.w_D=0.6666667
  15. self.nsteps = int(time_of_duration // self.dt + 1)
  16. self.w2=[intial_w]
  17. self.theta2=[intial_theta+0.001]
  18. self.a=[abs(self.theta[0]-self.theta2[0])]
  19. def run(self):
  20. for i in range(self.nsteps):#set an arbitrary time limit of the plot
  21. tmp_w=self.w[i]-(math.sin(self.theta[i])+self.q*self.w[i]-self.F_D*math.sin(self.w_D*self.t[i]))*self.dt
  22. self.w.append(tmp_w)
  23. tmp_theta=self.theta[i]+self.w[i+1]*self.dt
  24. self.theta.append(tmp_theta)
  25. # while self.theta[-1]>1*math.pi:
  26. # self.theta[-1]=self.theta[-1]-2*math.pi
  27. #while self.theta[-1]<-1*math.pi:
  28. # self.theta[-1]=self.theta[-1]+2*math.pi
  29. tmp_w2=self.w2[i]-(math.sin(self.theta2[i])+self.q*self.w2[i]-self.F_D*math.sin(self.w_D*self.t[i]))*self.dt
  30. self.w2.append(tmp_w2)
  31. tmp_theta2=self.theta2[i]+self.w2[i+1]*self.dt
  32. self.theta2.append(tmp_theta2)
  33. # while self.theta2[-1]>1*math.pi:
  34. # self.theta2[-1]=self.theta[-1]-2*math.pi
  35. #while self.theta2[-1]<-1*math.pi:
  36. # self.theta2[-1]=self.theta2[-1]+2*math.pi
  37. self.t.append(self.t[i]+self.dt)
  38. self.a.append(abs(self.theta[i+1]-self.theta2[i+1]))
  39. def show(self):
  40. pl.semilogy(self.t, self.a,label='$F_{D}$=%.2f'%self.F_D)
  41. pl.xlabel('Time ($s$)')
  42. pl.ylabel('$\Delta \\theta $(radius)')
  43. pl.title('$\Delta \\theta $ versus time')
  44. pl.legend(loc='upper right',frameon = True)
  45. pl.grid(True)
  46. pl.show()
  47. a=oscillatory_motion()
  48. a.run()
  49. a.show()

3.2 Solution to 3.12

  1. import math
  2. import pylab as pl
  3. class oscillatory_motion():
  4. def __init__(self):
  5. intial_theta=0.2
  6. intial_w=0
  7. time_of_duration=10000
  8. self.theta=[intial_theta]
  9. self.t=[0]
  10. self.w=[intial_w]
  11. self.dt=0.01
  12. self.q=0.5
  13. self.F_D=1.2
  14. self.w_D=0.6666667
  15. self.nsteps = int(time_of_duration // self.dt + 1)
  16. self.tmp_w=[0]
  17. self.tmp_theta=[0]
  18. def run(self):
  19. for i in range(self.nsteps):#set an arbitrary time limit of the plot
  20. tmp_w=self.w[i]-(math.sin(self.theta[i])+self.q*self.w[i]-self.F_D*math.sin(self.w_D*self.t[i]))*self.dt
  21. self.w.append(tmp_w)
  22. tmp_theta=self.theta[i]+self.w[i+1]*self.dt
  23. self.theta.append(tmp_theta)
  24. while self.theta[-1]>1*math.pi:
  25. self.theta[-1]=self.theta[-1]-2*math.pi
  26. while self.theta[-1]<-1*math.pi:
  27. self.theta[-1]=self.theta[-1]+2*math.pi
  28. self.t.append(self.t[i]+self.dt)
  29. for i in range(self.nsteps):
  30. if self.t[i]%(2*math.pi/self.w_D)<0.01:
  31. self.tmp_w.append(self.w[i])
  32. self.tmp_theta.append(self.theta[i])
  33. def show(self):
  34. pl.plot(self.tmp_theta, self.tmp_w,'.',label='$F_{D}$=%.2f'%self.F_D)
  35. pl.xlabel('$\\theta$ (radians)')
  36. pl.ylabel('$w$(radius/s)')
  37. pl.title('$w$ versus $\\theta$')
  38. pl.legend(loc='upper right',frameon = True)
  39. pl.grid(True)
  40. pl.show()
  41. a=oscillatory_motion()
  42. a.run()
  43. a.show()

4.Result

4.1 Result with different intial angle.

Here the parameters are , , , ,

1.png-52kB
Here are the expoential simulation plot:()
0.139.png-49kB

Here the parameters are , , , ,
2.png-48.3kB

Here are the expoential simulation plot:()
-0.249.png-55kB
Here are the photos with different of ' versus time' plots
5.png-78kB
Here are the photos with different of ' versus time' plots
7.png-70.8kB

4.2 Result with different damping factors

Here the parameters are , , , ,
3.png-44.5kB
Simulation:(
14.png-45.5kB
Here the parameters are , , , ,
13.png-53.6kB
Simulation plot():
12.png-54.1kB

4.3 Result with 3.12

Here the parameters are , , , ,,time duration =10000.This is a plot corresponding to a maximum of the frive force.
8.png-38.2kB
This is a plot corresponding to a phase of the frive force.
9.png-38.7kB

6.Ackanowledgement

After my dicsussion,here is one thing that I want to stress.Withoud the attention of the calculation of computer,I ignore the difference of fraction and decimal,which led to a serious and confusing problem,that is, I mistakely took as 0.67.This problem leads to a zero result with my external force and out of which I had struggled almost two hours to figure it out.And I want to thanks to Yukang,who found its out but he didn't know why at first and finally told by Wang shixing.Thanks to both of them.

7.Refernece

1.Yu kang for his help in
2.Matplotilb
3.<< How to think like a computer scientist>>

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