[关闭]
@Guibeen 2016-10-16T16:51:01.000000Z 字数 2809 阅读 613

第五次作业


作业内容

考虑风阻,以及空气密度随高度增加而减小这两个因素,绘制出导弹的轨迹(Exercise2.6)。

思路

欧勒法:

坐标



阻力


其中
速度


其中,正比于,取,炮弹发射处


等温过程

,故

其中为竖直方向位移。取

代码

  1. import math
  2. import pylab as pl
  3. class cannon_shell():
  4. def __init__(self, velocity=700, fixing_angle=9*math.pi/36, position_x=0,
  5. position_y=0,drag_constant=0.00004, #drag_constant is B2/m
  6. acceleration_of_gravity=9.8, decay_index=10000, time_step=0.1):
  7. self.theta=fixing_angle*180/math.pi
  8. self.x = [position_x]
  9. self.y = [position_y]
  10. self.v = [velocity]
  11. self.v_x = [velocity*math.cos(fixing_angle)]
  12. self.v_y = [velocity*math.sin(fixing_angle)]
  13. self.B2_m = [drag_constant]
  14. self.g = acceleration_of_gravity
  15. self.y_0 = decay_index
  16. self.dt = time_step
  17. self.t = [0]
  18. def run(self):
  19. while(self.y[-1]>=0):
  20. self.x.append(self.x[-1]+self.v_x[-1]*self.dt/1000)
  21. self.y.append(self.y[-1]+self.v_y[-1]*self.dt/1000)
  22. self.v_x.append(self.v_x[-1]-self.B2_m[-1]*self.v[-1]*self.v_x[-1]*self.dt)
  23. self.v_y.append(self.v_y[-1]-self.g*self.dt-self.B2_m[-1]*self.v_y[-1]*self.v[-1]*self.dt)
  24. self.B2_m.append(self.B2_m[-1]*math.exp(-self.y[-1]/self.y_0))
  25. self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
  26. self.t.append(self.t[-1]+self.dt)
  27. def show_results(self):
  28. plot1=pl.plot(self.x,self.y)
  29. pl.title('cannon shell trajectory')
  30. pl.xlabel('x($km$)')
  31. pl.ylabel('y($km$)')
  32. pl.xlim(0,25)
  33. pl.ylim(0,10)
  34. pl.show
  35. a = cannon_shell()
  36. a.run()
  37. a.show_results()

若不考虑空气密度随高度的变化,则程序将简化:

  1. import math
  2. import pylab as pl
  3. class cannon_shell():
  4. def __init__(self, velocity=700, fixing_angle=9*math.pi/36, position_x=0,
  5. position_y=0,drag_constant=0.00004, #drag_constant is B2/m
  6. acceleration_of_gravity=9.8, time_step=0.1):
  7. self.theta=fixing_angle*180/math.pi
  8. self.x = [position_x]
  9. self.y = [position_y]
  10. self.v = [velocity]
  11. self.v_x = [velocity*math.cos(fixing_angle)]
  12. self.v_y = [velocity*math.sin(fixing_angle)]
  13. self.B2_m = drag_constant
  14. self.g = acceleration_of_gravity
  15. self.dt = time_step
  16. self.t = [0]
  17. def run(self):
  18. while(self.y[-1]>=0):
  19. self.x.append(self.x[-1]+self.v_x[-1]*self.dt/1000)
  20. self.y.append(self.y[-1]+self.v_y[-1]*self.dt/1000)
  21. self.v_x.append(self.v_x[-1]-self.B2_m*self.v[-1]*self.v_x[-1]*self.dt)
  22. self.v_y.append(self.v_y[-1]-self.g*self.dt-self.B2_m*self.v_y[-1]*self.v[-1]*self.dt)
  23. self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
  24. self.t.append(self.t[-1]+self.dt)
  25. def show_results(self):
  26. plot1=pl.plot(self.x,self.y,'--')
  27. pl.title('cannon shell trajectory')
  28. pl.xlabel('x($km$)')
  29. pl.ylabel('y($km$)')
  30. pl.xlim(0,25)
  31. pl.ylim(0,10)
  32. pl.show
  33. a = cannon_shell()
  34. a.run()
  35. a.show_results()

运行结果

  1. 考虑密度随高度变化与不考虑的定性比较:(虚线为未考虑,实线为考虑;初速度为700m/s,角度为45°)
    结果图1
  2. 考虑空气密度随高度变化的情况下,改变炮弹发射角度的值,在同一坐标中作图:(速度不变,角度从30°到65°,每隔5°取一个次)
    结果图2

结论

  1. 考虑空气密度随高度的变化,则炮弹将比不考虑时飞得更高更远。
  2. 所选的角度值中,40°飞行距离最远。
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注