[关闭]
@rrtcc 2016-10-16T14:20:40.000000Z 字数 9047 阅读 40

第五次作业

炮弹轨迹 极值 空气阻力


摘要

通过解决Exercise2.9,复现Finger2.5的结果,并进一步考虑,引入空气阻力,进行相关计算。

Exercise 2.9

Calculate the trajectory of our cannon shell including both air drag and the reduced air density at high altitudes so that you can reproduce the results in Figure 2.5. Perform your calculation for different firing angles and determine the value of the angle that gives the maximum range.

背景

不考虑空气阻力

以下斜体部分摘自课本page25
xm-1111型中程炮弹
The Euler method we used to treat the problem in chapter 1 can easily be generalized to deal with motion in two spatial dimensions. To be specific, we can consider a projectile such as a shell shot by a cannon. If we ignore the air resistance, the equations of motion, which are again obtained from Newton's second law, can be written as
牛顿方程
We can write each of these second-order equations as two first-order differential equations
first-order differential equations
利用在上一次作业中所使用的一级欧拉近似法有以下方程
近似方程
于是可以利用python进行相关计算

考虑空气阻力

The Euler method can easily be generalized to deal with motion in two spatial dimensions.
If we ignore the air resistance, the equations of motion, which are again obtained from Newton's second law, can be written as

where x and y are the horizontal and vertical coordinates of the projectile, and g is the acceleration due to the gravity. These are second-order differential equations.We can put them into four first-order ordinary differential equations as
where and are the x and y components of the velocity.
To use the Euler method, we write each derivative in finite difference form
Then we consider air resistance, we assume that the magnitude of the drag force on cannon shell is given by
The components of the drag force are thus
Adding this force to the equations of motion leads to
If we consider the reduced air density at high altitudes, there is a formula of density which depends on altitude
For air:,
So the drag force at altitude can be written as
Then the differential equation of motion can be modified into
The air resistance was included with ,and the initial speed was 700 .

正文

在不考虑空气阻力的情况下,设计代码如下

  1. import math
  2. import pylab as pl
  3. class bicycle:
  4. def __init__(self, power=10, mass=1, time_step=0.1,\
  5. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/6),\
  6. initial_Vy=50*math.sin(math.pi/6)):
  7. self.v = [initial_velocity]
  8. self.x=[initial_x]
  9. self.y=[initial_y]
  10. self.Vx=[initial_Vx]
  11. self.Vy=[initial_Vy]
  12. self.t = [0]
  13. self.m = mass
  14. self.p = force
  15. self.dt = time_step
  16. def run(self):
  17. while(self.y[-1]>=0):
  18. self.x.append(self.x[-1]+self.Vx[0]*self.dt)
  19. self.y.append(self.y[-1]+self.Vy[-1]*self.dt)
  20. self.Vy.append(self.Vy[-1]-9.8*self.dt)
  21. print("yn=", self.y[-1])
  22. print("y(n-1)=",self.y[-2])
  23. print("xn=",self.x[-1])
  24. print("x(n-1)=",self.x[-2])
  25. class diff_step_check(bicycle):
  26. def show_result1(self,style='b'):
  27. pl.plot(self.x, self.y,style,label='30')
  28. pl.title('projectile motion without air resistance')
  29. pl.xlabel('x')
  30. pl.ylabel('y')
  31. pl.legend(loc='best')
  32. a=diff_step_check( power=10, mass=1, time_step=0.1,\
  33. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/6),\
  34. initial_Vy=50*math.sin(math.pi/6))
  35. a.run()
  36. a.show_result1('b')
  37. class diff_step_check(bicycle):
  38. def show_result2(self,style='b'):
  39. pl.plot(self.x, self.y,'k--',label='35')
  40. pl.title('projectile motion without air resistance')
  41. pl.xlabel('x(m)')
  42. pl.ylabel('y(m)')
  43. pl.legend(loc='best')
  44. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  45. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/6*(7/6)),\
  46. initial_Vy=50*math.sin(math.pi/6*(7/6)))
  47. b.run()
  48. b.show_result2('g')
  49. class diff_step_check(bicycle):
  50. def show_result2(self,style='b'):
  51. pl.plot(self.x, self.y,'m-.',label='40')
  52. pl.title('projectile motion without air resistance')
  53. pl.xlabel('x(m)')
  54. pl.ylabel('y(m)')
  55. pl.legend(loc='best')
  56. c=diff_step_check( power=10, mass=1, time_step=0.1,\
  57. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/6*(4/3)),\
  58. initial_Vy=50*math.sin(math.pi/6*(4/3)))
  59. c.run()
  60. c.show_result2('r')
  61. class diff_step_check(bicycle):
  62. def show_result2(self,style='b'):
  63. pl.plot(self.x, self.y,'y-',label='45')
  64. pl.title('projectile motion without air resistance')
  65. pl.xlabel('x(m)')
  66. pl.ylabel('y(m)')
  67. pl.legend(loc='best')
  68. d=diff_step_check( power=10, mass=1, time_step=0.1,\
  69. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/4),\
  70. initial_Vy=50*math.sin(math.pi/4))
  71. d.run()
  72. d.show_result2('c')
  73. class diff_step_check(bicycle):
  74. def show_result2(self,style='b'):
  75. pl.plot(self.x, self.y,'b:',label='50')
  76. pl.title('projectile motion without air resistance')
  77. pl.xlabel('x(m)')
  78. pl.ylabel('y(m)')
  79. pl.legend(loc='best')
  80. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  81. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/4*(10/9)),\
  82. initial_Vy=50*math.sin(math.pi/4*(10/9)))
  83. b.run()
  84. b.show_result2('m')
  85. class diff_step_check(bicycle):
  86. def show_result2(self,style='b'):
  87. pl.plot(self.x, self,'r--',style,label='55')
  88. pl.title('projectile motion without air resistance')
  89. pl.xlabel('x(m)')
  90. pl.ylabel('y(m)')
  91. pl.legend(loc='best')
  92. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  93. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=50*math.cos(math.pi/4*(11/9)),\
  94. initial_Vy=50*math.sin(math.pi/4*(11/9)))
  95. b.run()
  96. b.show_result2('y')
  97. show()

结果如下图所示无空气阻力
课本结果如下课本结果
可以看出复现了课本的结果
考虑空气阻力,代码如下

  1. import math
  2. import pylab as pl
  3. class bicycle:
  4. def __init__(self, power=10, mass=1, time_step=0.1,\
  5. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/6),\
  6. initial_Vy=700*math.sin(math.pi/6)):
  7. self.v = [initial_velocity]
  8. self.x=[initial_x]
  9. self.y=[initial_y]
  10. self.Vx=[initial_Vx]
  11. self.Vy=[initial_Vy]
  12. self.t = [0]
  13. self.m = mass
  14. self.p = power
  15. self.dt = time_step
  16. def run(self):
  17. while(self.y[-1]>=0):
  18. self.x.append(self.x[-1]+self.Vx[-1]*self.dt)
  19. self.Vx.append(self.Vx[-1]-math.exp(-self.y[-1]/(10**4))*4/(10**5)*self.v[-1]*self.Vx[-1]/self.m*self.dt)
  20. self.y.append(self.y[-1]+self.Vy[-1]*self.dt)
  21. self.Vy.append(self.Vy[-1]-9.8*self.dt-math.exp(-self.y[-1]/(10**4))*4/(10**5)*self.v[-1]*self.Vy[-1]/self.m*self.dt)
  22. self.v.append(math.sqrt(self.Vx[-1]**2+self.Vx[-1]**2))
  23. print("yn=", self.y[-1])
  24. print("y(n-1)=",self.y[-2])
  25. print("xn=",self.x[-1])
  26. print("x(n-1)=",self.x[-2])
  27. r=-self.y[-2]/self.y[-1]
  28. xl=(self.x[-2]+r*self.x[-1])/(r+1)
  29. print("零点为",xl)
  30. class diff_step_check(bicycle):
  31. def show_result1(self,style='b'):
  32. pl.plot(self.x, self.y,style,label='30')
  33. pl.title('projectile motion with air resistance and isothermal atmosphere')
  34. pl.xlabel('x')
  35. pl.ylabel('y')
  36. pl.legend(loc='best')
  37. from pylab import *
  38. a=diff_step_check( power=10, mass=1, time_step=0.1,\
  39. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/6),\
  40. initial_Vy=700*math.sin(math.pi/6))
  41. a.run()
  42. a.show_result1('b')
  43. class diff_step_check(bicycle):
  44. def show_result2(self,style='b'):
  45. pl.plot(self.x, self.y,'k--',label='35')
  46. pl.title('projectile motion with air resistance and isothermal atmosphere')
  47. pl.xlabel('x(m)')
  48. pl.ylabel('y(m)')
  49. pl.legend(loc='best')
  50. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  51. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/6*(7/6)),\
  52. initial_Vy=700*math.sin(math.pi/6*(7/6)))
  53. b.run()
  54. b.show_result2('g')
  55. class diff_step_check(bicycle):
  56. def show_result2(self,style='b'):
  57. pl.plot(self.x, self.y,'m-.',label='40')
  58. pl.title('projectile motion with air resistance and isothermal atmosphere')
  59. pl.xlabel('x(m)')
  60. pl.ylabel('y(m)')
  61. pl.legend(loc='best')
  62. c=diff_step_check( power=10, mass=1, time_step=0.1,\
  63. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/6*(4/3)),\
  64. initial_Vy=700*math.sin(math.pi/6*(4/3)))
  65. c.run()
  66. c.show_result2('r')
  67. class diff_step_check(bicycle):
  68. def show_result2(self,style='b'):
  69. pl.plot(self.x, self.y,style,label='45')
  70. pl.title('projectile motion with air resistance and isothermal atmosphere')
  71. pl.xlabel('x(m)')
  72. pl.ylabel('y(m)')
  73. pl.legend(loc='best')
  74. d=diff_step_check( power=10, mass=1, time_step=0.1,\
  75. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/4),\
  76. initial_Vy=700*math.sin(math.pi/4))
  77. d.run()
  78. d.show_result2('c')
  79. class diff_step_check(bicycle):
  80. def show_result2(self,style='b'):
  81. pl.plot(self.x, self.y,'b:',label='50')
  82. pl.title('projectile motion with air resistance and isothermal atmosphere')
  83. pl.xlabel('x(m)')
  84. pl.ylabel('y(m)')
  85. pl.legend(loc='best')
  86. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  87. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/4*(10/9)),\
  88. initial_Vy=700*math.sin(math.pi/4*(10/9)))
  89. b.run()
  90. b.show_result2('m')
  91. class diff_step_check(bicycle):
  92. def show_result2(self,style='b'):
  93. pl.plot(self.x, self.y,style,label='55')
  94. pl.title('projectile motion with air resistance and isothermal atmosphere')
  95. pl.xlabel('x(m)')
  96. pl.ylabel('y(m)')
  97. pl.legend(loc='best')
  98. b=diff_step_check( power=10, mass=1, time_step=0.1,\
  99. initial_velocity=1 ,initial_x=0,initial_y=0,initial_Vx=700*math.cos(math.pi/4*(11/9)),\
  100. initial_Vy=700*math.sin(math.pi/4*(11/9)))
  101. b.run()
  102. b.show_result2('y')
  103. show()

结果如下图所示有空气阻力
无法得出角度为何值时有最大值,故增加60度的曲线如下
有空气阻力
故45到60度时取得最大值,可考虑缩小范围
最后结果如下有空气阻力
故最大值在52到54度之间

结论

复现了书上的结果
得到最大值在52到54度之间

致谢

感想吴帆帆同学的指导

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