[关闭]
@LiuYongJie 2016-10-23T12:10:22.000000Z 字数 6023 阅读 609

Ex_06 2.10 Consider cases in which the target is higher and lower than the cannon.

author: Liu Yongjie 2014301020094


The title

2.10 Generalize the program developed for the previous problem so that it can deal with situations in which the target is at a different altitude than the cannon. Consider cases in which the target is higher and lower than the cannon. Also investigate how the minimum firing velocity required to hit the target varies as the altitude of the target is varied.

Abstract

In this homework several problems involving the motion of objects through the atmosphere are considered. Still, the problems are all described by ordinary differential equations in which initial values are given and can be solved using Euler method. This report solved cannon trajectory problem, in which air drag and reduced air density at high altitudes are considered.

Key Words: Projectile Motion; Euler Method; Air Drag; Air Density; Cannon Shell

Background

In realistic projectile motion1, we will fail to to obtain a realistic description if we do not include Air resistance must be included if we are to obtain a realistic description of the problem.
In general, air resistance can be written in the fairly form:

²

and the term dominates for most objects at any reasonable velocity. So we can use the fact that an object must push air in front it out of the way to move through the atmosphere.
²

C is the drag coefficient, ρ is air density, A is the front area of the object.
Another important piece of physics we should consider is air density
.
where is the sea level temperature, and the exponent α≈2.9 for air.
With density correction:

where and ³is the density at sea level.
This isothermal model of atmosphere is perhaps not realistic, since we know that the air temperature can vary quitea bit over altitude changes of a few kilometers. This leads to the second simplest model adiabatic model:

where a≈ for air. Here is the sea level temperature (in K)≈300K.
Since the drag force due to air resistance is proportional to the density, so for both models we have

Now we can get for isothermal ideal gas, the equations of motion become


Also, for adiabatic approximation, the equations of motion become


On top of that, we can use several numerical approaches including the simple Euler method and the Runge-Kutta method to yield the numerical solutions to these problems.

code

  1. import time
  2. import math
  3. import matplotlib.pyplot as plt
  4. def correct(string,y_t): ##### delete all the data of (x,y) where y<0
  5. x_record = string[0][-1]
  6. y_record = y_t
  7. while True:
  8. if (string[1][-1] < y_t):
  9. if (string[1][-1] < y_t and string[1][-2] > y_t):
  10. x_record = string[0][-1]
  11. y_record = string[1][-1]
  12. del string[0][-1]
  13. del string[1][-1]
  14. else:
  15. string[0].append(string[0][-1]+(y_t - string[1][-1])*(string[0][-1] - x_record)/(string[1][-2] - y_record))
  16. string[1].append(y_t)
  17. break
  18. return string[0],string[1]
  19. def calculate(v,theta):
  20. vx = []
  21. vy = []
  22. vx.append( v * math.cos(theta*math.pi/180))
  23. vy.append( v * math.sin(theta*math.pi/180))
  24. dt = 0.1
  25. t = []
  26. x = []
  27. y = []
  28. t.append(0)
  29. x.append(0)
  30. y.append(0)
  31. i = 1
  32. while (y[-1] >= 0):
  33. x.append(x[i - 1] + vx[i - 1]*dt)
  34. vx.append(vx[i - 1] - dt*0.00004*math.sqrt(vx[i - 1]**2+vy[i - 1]**2)*vx[i - 1]*(1-(0.0065*y[i - 1])/280)**2.5)
  35. y.append(y[i - 1] + vy[i - 1]*dt)
  36. vy.append(vy[i - 1]-9.8*dt -dt*0.00004*math.sqrt(vx[i - 1]**2+vy[i - 1]**2)*vy[i - 1]*(1-(0.0065*y[i - 1])/280)**2.5)
  37. t.append(t[i - 1] + dt)
  38. i+= 1
  39. r = y[-2] / y[-1]
  40. x[-1] = (x[-2] + r * x[-1]) / (r + 1)
  41. y[-1] = 0
  42. return x, y
  43. def find_maxheight(string):
  44. for i in range(len(string[1])):
  45. if ( string[1][0] < string[1][i] ):
  46. string[1][0] = string[1][i]
  47. return string[1][0]
  48. def scan_angle(v,theta, x_t, y_t, degree):
  49. ran_a = [20, 5, 2, 0.8, 0.2]
  50. delta = [1, 0.5, 0.1, 0.05, 0.01]
  51. theta = theta - ran_a[degree]
  52. theta_record = []
  53. x = []
  54. data = [[],[]]
  55. for i in range(int(ran_a[degree]*2/delta[degree]+1)):
  56. data = calculate(v,theta)[:]
  57. if ( find_maxheight(data) < y_t):
  58. theta = theta + delta[degree]
  59. x.append(100000000)
  60. theta_record.append(theta)
  61. else:
  62. data = correct(data,y_t)[:]
  63. x.append(data[0][-1])
  64. theta_record.append(theta)
  65. theta = theta + delta[degree]
  66. for j in range(len(x)):
  67. if ( abs(x[0] - x_t) > abs(x[j] - x_t)):
  68. x[0] = x[j]
  69. theta_record[0] = theta_record[j]
  70. return theta_record[0],x[0] ##### debug
  71. def scan_v(v,theta, x_target, y_target, degree):
  72. ran_v = [100, 10, 2, 0.8, 0.2]
  73. delta = [10, 2, 0.5, 0.1, 0.02]
  74. v = v - ran_v[degree]
  75. x = []
  76. theta_record = []
  77. v_record = []
  78. for i in range(int(ran_v[degree]*2/delta[degree]+1)):
  79. record_v = scan_angle(v,theta, x_target, y_target, degree)[:]
  80. x.append(record_v[1])
  81. theta_record.append(record_v[0])
  82. v_record.append(v)
  83. v = v + delta[degree]
  84. for j in range(len(x)):
  85. if ( abs(x[0] - x_target) > abs(x[j] - x_target)):
  86. x[0] = x[j]
  87. v_record[0] = v_record[j]
  88. theta_record[0] = theta_record[j]
  89. print v_record
  90. print theta_record
  91. print x
  92. return v_record[0],theta_record[0]
  93. def deep_scan(v, theta, x_target, y_target, precision):
  94. degree = 0
  95. record = [[],[]]
  96. for i in range(precision):
  97. record = scan_v(v,theta,x_target,y_target,degree)[:]
  98. v = record[0]
  99. theta = record[1]
  100. degree = degree + 1
  101. return record
  102. def judge_hitting(string,x_t,y_t):
  103. alpha = 0
  104. for i in range(len(string[0])):
  105. if ( x_t - 8 < string[0][-1] < x_t + 8 ):
  106. alpha = 1
  107. if (alpha == 1):
  108. print 'Successfully hitted'
  109. return 1
  110. else:
  111. print 'Miss'
  112. return 0
  113. def main():
  114. start = time.clock()
  115. x_target = 10000
  116. y_target = 2000
  117. # theta0 = 180*math.atan(y_target/x_target)/math.pi
  118. data_record = deep_scan(700,60,x_target,y_target,5) ### 3 for grade 1, 4 for grade 2 and 5 for grade 3
  119. v = data_record[0]
  120. theta = data_record[1]
  121. cannon_record = correct(calculate(v, theta),y_target)
  122. x_max = cannon_record[0][-1]
  123. judge_hitting(cannon_record,x_target,y_target)
  124. print '%f ' % x_max
  125. print '%f ' % theta
  126. print '%f ' %v
  127. end = time.clock()
  128. print "read: %f s" % (end - start)
  129. plt.figure(figsize = (8,6))
  130. plt.title('Trajectory of cannon shell')
  131. plt.xlabel('x(m)')
  132. plt.ylabel('y(m)')
  133. plt.plot(x_target,y_target,'k*',linewidth = 10,label='Target')
  134. plt.plot(cannon_record[0],cannon_record[1],label= 'Trajectroy')
  135. plt.legend(loc = 'upper left')
  136. plt.savefig('chapter2.png',dpi = 144)
  137. plt.show()
  138. main()

Click to view the results

Hitting point (10000, 2000), Angle: , Speed: 610.48m/s

Conclusion

This assignment allows us to learn how to solve high-order differential equation via transferring it into first-order diferential equations. Also, air density at differential altitude plays an important role in the trejectory of cannon shell.

thanks to

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