@842001323
2016-10-17T00:08:57.000000Z
字数 4425
阅读 279
摘要:用不同的空气密度模型来计算加农炮的炮弹运动轨迹。也可将B2的值和温度联系起来获得不同的曲线。观察adiabatic模型对射程的影响,温度对于曲线的影响
炮弹在空中飞行受到重力与空气阻力的影响
代码
import math
import pylab as pl
class cannon_shell1:
def __init__(self, time_step=0.01 ,angle=1, initial_v=700, T0=273, b=0.0065, Bm=0.00004,g=9.8,c=2.5,y0=10000):
self.y = [0]
self.x = [0]
self.t = [0]
self.ang = angle
self.v = [initial_v]
self.vx =[initial_v*math.cos(self.ang)]
self.vy =[initial_v*math.sin(self.ang)]
self.b = b
self.Bm = Bm
self.T0 = T0
self.dt = time_step
self.g=g
self.c=c
self.y0 = y0
def run1(self):
_time=0
while (self.y[-1]>=0):
self.vx.append(self.vx[-1]-self.Bm*self.dt*self.v[-1]*self.vx[-1]*(1-self.b*self.y[-1]/self.T0)**self.c)
self.vy.append(self.vy[-1]-self.g*self.dt-self.Bm*self.dt*self.v[-1]*self.vy[-1]*(1-self.b*self.y[-1]/self.T0)**self.c)
self.y.append(self.y[-1]+self.vy[-1]*self.dt)
self.x.append(self.x[-1]+self.vx[-1]*self.dt)
self.v.append(math.sqrt(self.vx[-1]*self.vx[-1]+self.vy[-1]*self.vy[-1]))
self.t.append(_time)
_time+=self.dt
def show_results(self):
font = {'family': 'serif','color': 'darkred','weight': 'normal','size': 16,}
pl.plot(self.x, self.y)
pl.title('cannon shell trajectories with air drag', fontdict = font)
pl.xlabel('x/m')
pl.ylabel('y/m')
pl.ylim(0,12000)
a = cannon_shell1()
a.run1()
a.show_results()
pl.show()
代码
class cannon_shell2:
def __init__(self, time_step=0.01 ,angle=1, initial_v=700, T0=273, b=0.0065, Bm=0.00004,g=9.8,c=2.5,y0=10000):
self.y = [0]
self.x = [0]
self.t = [0]
self.ang = angle
self.v = [initial_v]
self.vx =[initial_v*math.cos(self.ang)]
self.vy =[initial_v*math.sin(self.ang)]
self.b = b
self.Bm = Bm
self.T0 = T0
self.dt = time_step
self.g=g
self.c=c
self.y0 = y0
def run2(self):
_time=0
while (self.y[-1]>=0):
self.vx.append(self.vx[-1]-self.Bm*self.dt*self.v[-1]*self.vx[-1]*math.exp(-self.y[-1]/self.y0))
self.vy.append(self.vy[-1]-self.g*self.dt-self.Bm*self.dt*self.v[-1]*self.vy[-1]*math.exp(-self.y[-1]/self.y0))
self.y.append(self.y[-1]+self.vy[-1]*self.dt)
self.x.append(self.x[-1]+self.vx[-1]*self.dt)
self.v.append(math.sqrt(self.vx[-1]*self.vx[-1]+self.vy[-1]*self.vy[-1]))
self.t.append(_time)
_time+=self.dt
def show_results(self):
font = {'family': 'serif','color': 'darkred','weight': 'normal','size': 16,}
pl.plot(self.x, self.y)
pl.title('cannon shell trajectories with air drag', fontdict = font)
pl.xlabel('x/m')
pl.ylabel('y/m')
pl.ylim(0,12000)
a = cannon_shell1()
a.run1()
a.show_results()
b = cannon_shell2()
b.run2()
b.show_results()
pl.show()
代码
class cannon_shell3:
def __init__(self, time_step=0.01 ,angle=1, initial_v=700, T0=273, b=0.0065, Bm=0.00004,g=9.8,c=2.5,y0=10000,T=300):
self.y = [0]
self.x = [0]
self.t = [0]
self.ang = angle
self.v = [initial_v]
self.vx =[initial_v*math.cos(self.ang)]
self.vy =[initial_v*math.sin(self.ang)]
self.b = b
self.Bm = Bm
self.T0 = T0
self.T = T
self.dt = time_step
self.g=g
self.c=c
self.y0 = y0
def run3(self):
_time=0
while (self.y[-1]>=0):
self.vx.append(self.vx[-1]-(self.Bm*(self.T0/self.T)**self.c)*self.dt*self.v[-1]*self.vx[-1]*(1-self.b*self.y[-1]/self.T0)**self.c)
self.vy.append(self.vy[-1]-self.g*self.dt-(self.Bm*(self.T0/self.T)**self.c)*self.dt*self.v[-1]*self.vy[-1]*(1-self.b*self.y[-1]/self.T0)**self.c)
self.y.append(self.y[-1]+self.vy[-1]*self.dt)
self.x.append(self.x[-1]+self.vx[-1]*self.dt)
self.v.append(math.sqrt(self.vx[-1]*self.vx[-1]+self.vy[-1]*self.vy[-1]))
self.t.append(_time)
_time+=self.dt
def show_results(self):
font = {'family': 'serif','color': 'red','weight': 'normal','size': 16,}
pl.plot(self.x, self.y)
pl.title('cannon shell trajectories with air drag', fontdict = font)
pl.xlabel('x/m')
pl.ylabel('y/m')
pl.ylim(0,20000)
a = cannon_shell1()
a.run1()
a.show_results()
b = cannon_shell3()
b.run3()
b.show_results()
pl.show()
密度模型,温度,发射角度对轨迹的影响都很大。将两模型的轨迹进行比较,可知模型二的射程较小,模型一能达到更远的距离。当发射角度在0.7~0.8弧度之间时,射程最大。
老师提供的部分代码