[关闭]
@zy-0815 2016-11-27T17:34:14.000000Z 字数 6574 阅读 877

计算物理第六次作业


摘要

此次作业为2.10的强化版,引入了迎面风阻,即完成L1。

背景介绍

上次作业中我们通过Euler法完成了对炮弹轨迹的探讨,同时此次探讨偏向理想化探讨,然则在实际问题中我们还要考虑风阻等各种问题,因此此次作业变加强了对实际性问题的研究

正文

1、对于标准情况,即考虑风阻的情况并引入绝热模型分析海拔对风阻影响。
绝热模型公式为:


其中,我们很快写出此时的方程如下:

由此,我们可以写出程序果如下,注:以下为的情况

  1. import pylab as pl
  2. import math
  3. class cannon :
  4. def __init__(self,i=0,air_resistance=0.00004,power=10,mass = 1,time_step=0.1,\
  5. initial_velocity=700,initial_x=0,initial_y=0,\
  6. initial_velocity_x=700*math.cos(math.pi/4),\
  7. initial_velocity_y=700*math.sin(math.pi/4)):
  8. self.x = [initial_x]
  9. self.y = [initial_y]
  10. self.vx = [initial_velocity_x]
  11. self.vy = [initial_velocity_y]
  12. self.v = [initial_velocity]
  13. self.t = [0]
  14. self.m = mass
  15. self.p = power
  16. self.B_2 = air_resistance
  17. self.dt = time_step
  18. def run(self):
  19. while(1):
  20. s1=self.x[-1] + self.vx[-1]*self.dt
  21. s2=self.y[-1] + self.vy[-1]*self.dt
  22. v1=self.vx[-1] - self.dt *pow((1-(0.0065*self.y[-1])/300),2.5)*\
  23. (self.B_2 / self.m) *self.v[-1] * self.vx[-1]
  24. v2=self.vy[-1] - 9.8*self.dt - self.dt *\
  25. pow((1-(0.0065*self.y[-1])/300),2.5)*(self.B_2 / self.m) *\
  26. self.v[-1] * self.vx[-1]
  27. self.x.append(s1)
  28. self.y.append(s2)
  29. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  30. self.vx.append(v1)
  31. self.vy.append(v2)
  32. if(s2<0):
  33. break
  34. def show_results(self):
  35. pl.plot(self.x,self.y,'b',label='angle is 45 degree')
  36. pl.title('Precise guidance system')
  37. pl.xlabel('X')
  38. pl.ylabel('Y')
  39. pl.legend()
  40. pl.ylim(0,)
  41. pl.show()
  42. a = cannon()
  43. a.run()
  44. a.show_results()

程序运行结果如图:
image_1avp686hvodp91ga7b1b9akva13.png-17.6kB
2、考虑迎面风阻,由书上(2.26)可知公式为


其中,以及
由此可知程序应为:

  1. import pylab as pl
  2. import math
  3. class cannon :
  4. def __init__(self,i=0,air_resistance=0.00004,power=10,mass = 1,time_step=0.1,\
  5. initial_velocity=700,initial_x=0,initial_y=0,\
  6. initial_velocity_x=700*math.cos(math.pi/4),\
  7. initial_velocity_y=700*math.sin(math.pi/4)):
  8. self.x = [initial_x]
  9. self.y = [initial_y]
  10. self.vx = [initial_velocity_x]
  11. self.vy = [initial_velocity_y]
  12. self.v = [initial_velocity]
  13. self.t = [0]
  14. self.m = mass
  15. self.p = power
  16. self.B_2 = air_resistance
  17. self.dt = time_step
  18. def run(self):
  19. while(1):
  20. s1=self.x[-1] + self.vx[-1]*self.dt
  21. s2=self.y[-1] + self.vy[-1]*self.dt
  22. v1=self.vx[-1] - self.dt *pow((1-(0.0065*self.y[-1])/300),2.5)*\
  23. (0.0039+0.0058/(1+math.exp((self.v[-1]-35)/5)))*\
  24. self.v[-1] * self.vx[-1]
  25. v2=self.vy[-1] - 9.8*self.dt - self.dt *\
  26. pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  27. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  28. self.v[-1] * self.vx[-1]
  29. self.x.append(s1)
  30. self.y.append(s2)
  31. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  32. self.vx.append(v1)
  33. self.vy.append(v2)
  34. if(s2<0):
  35. break
  36. def show_results(self):
  37. pl.plot(self.x,self.y,'b',label='angle is 45 degree')
  38. pl.title('Precise guidance system')
  39. pl.xlabel('X')
  40. pl.ylabel('Y')
  41. pl.legend()
  42. pl.ylim(0,)
  43. pl.show()
  44. a = cannon()
  45. a.run()
  46. a.show_results()

运行结果为:
image_1avp5dipp15rr3dn2ue1jntptlm.png-15.9kB
由此对比看出,当考虑迎面风阻的时候,炮弹所打的距离明显减小;
3、考虑目标位置的变化时(初始海拔为100m),如比原位置更高时候,程序可修改为:

  1. import pylab as pl
  2. import math
  3. class cannon :
  4. def __init__(self,i=0,air_resistance=0.00004,power=10,mass = 1,time_step=0.01,\
  5. total_time=100, initial_velocity=700,initial_x=0,initial_y=100,\
  6. initial_angle=45,angle_c=math.pi/180):
  7. self.x = [initial_x]
  8. self.y = [initial_y]
  9. self.v = [initial_velocity]
  10. self.vx= [initial_velocity*math.cos(initial_angle*angle_c)]
  11. self.vy= [initial_velocity*math.sin(initial_angle*angle_c)]
  12. self.t = [0]
  13. self.m = mass
  14. self.p = power
  15. self.B_2 = air_resistance
  16. self.dt = time_step
  17. self.time = total_time
  18. def run(self):
  19. while(1):
  20. s1=self.x[-1] + self.vx[-1]*self.dt
  21. s2=self.y[-1] + self.vy[-1]*self.dt
  22. v1=self.vx[-1] - self.dt *pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  23. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  24. self.v[-1] * self.vx[-1]
  25. v2=self.vy[-1] - 9.8*self.dt - self.dt *\
  26. pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  27. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  28. self.v[-1] * self.vx[-1]
  29. self.x.append(s1)
  30. self.y.append(s2)
  31. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  32. self.vx.append(v1)
  33. self.vy.append(v2)
  34. if(v2<0 and s2<200):
  35. s1=self.x[-1] + self.vx[-1]*0.001
  36. s2=self.y[-1] + self.vy[-1]*0.001
  37. v1=self.vx[-1] - 0.001 *pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  38. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  39. self.v[-1] * self.vx[-1]
  40. v2=self.vy[-1] - 9.8*0.001 - 0.001 *\
  41. pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  42. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  43. self.v[-1] * self.vx[-1]
  44. self.x.append(s1)
  45. self.y.append(s2)
  46. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  47. self.vx.append(v1)
  48. self.vy.append(v2)
  49. if(s2<200):
  50. break
  51. break
  52. def show_results(self):
  53. pl.plot(self.x,self.y,'b',label='45 degree with headwind')
  54. pl.title('Precise guidance system with higher target')
  55. pl.ylim(0,600)
  56. pl.xlabel('X')
  57. pl.ylabel('Y')
  58. pl.legend()
  59. pl.show()
  60. a = cannon()
  61. a.run()
  62. a.show_results()

运行结果为:
image_1avp6c2qm19o57atcc15skcpm1g.png-16.8kB
对于较低海拔,程序为:

  1. import pylab as pl
  2. import math
  3. class cannon :
  4. def __init__(self,i=0,air_resistance=0.00004,power=10,mass = 1,time_step=0.01,\
  5. total_time=100, initial_velocity=700,initial_x=0,initial_y=100,\
  6. initial_angle=45,angle_c=math.pi/180):
  7. self.x = [initial_x]
  8. self.y = [initial_y]
  9. self.v = [initial_velocity]
  10. self.vx= [initial_velocity*math.cos(initial_angle*angle_c)]
  11. self.vy= [initial_velocity*math.sin(initial_angle*angle_c)]
  12. self.t = [0]
  13. self.m = mass
  14. self.p = power
  15. self.B_2 = air_resistance
  16. self.dt = time_step
  17. self.time = total_time
  18. def run(self):
  19. while(1):
  20. s1=self.x[-1] + self.vx[-1]*self.dt
  21. s2=self.y[-1] + self.vy[-1]*self.dt
  22. v1=self.vx[-1] - self.dt *pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  23. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  24. self.v[-1] * self.vx[-1]
  25. v2=self.vy[-1] - 9.8*self.dt - self.dt *\
  26. pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  27. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  28. self.v[-1] * self.vx[-1]
  29. self.x.append(s1)
  30. self.y.append(s2)
  31. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  32. self.vx.append(v1)
  33. self.vy.append(v2)
  34. if(s2<0):
  35. s1=self.x[-1] + self.vx[-1]*0.001
  36. s2=self.y[-1] + self.vy[-1]*0.001
  37. v1=self.vx[-1] - 0.001 *pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  38. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  39. self.v[-1] * self.vx[-1]
  40. v2=self.vy[-1] - 9.8*0.001 - 0.001 *\
  41. pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\
  42. 0.0058/(1+math.exp((self.v[-1]-35)/5))) *\
  43. self.v[-1] * self.vx[-1]
  44. self.x.append(s1)
  45. self.y.append(s2)
  46. self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))
  47. self.vx.append(v1)
  48. self.vy.append(v2)
  49. if(s2<200):
  50. break
  51. break
  52. def show_results(self):
  53. pl.plot(self.x,self.y,'b',label='45 degree with headwind')
  54. pl.title('Precise guidance system with higher target')
  55. pl.ylim(0,600)
  56. pl.xlabel('X')
  57. pl.ylabel('Y')
  58. pl.legend()
  59. pl.show()
  60. a = cannon()
  61. a.run()
  62. a.show_results()

运行结果为:
image_1avp6hfil8eg8p4s7f1a5n8u41t.png-17.3kB

结论

(1)引入迎面风阻后,炮弹的轨迹明显变小,而这其实与初始速度有关,运行不同的初始速度,轨迹也会大不相同;
(2)对于不同高度的目标,炮弹射速和角度也有显然变化。

致谢

感谢宗玥同学的耐心帮助。

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