@XF
2016-10-23T16:14:19.000000Z
字数 2058
阅读 83
本作业将对2.10题进行进一步升级,发展“超级辅助精确打击系统”(考虑炮弹初始发射的时候发射角度误差,速度有5%的误差,迎面风阻误差10%,以炮弹落点与打击目标距离差平方均值最小为优胜)
由牛顿第二定律:
import pylab as plimport mathclass cannon :def __init__(self,i=0,air_resistance=0.00004,power=10,mass = 1,time_step=0.1,\initial_velocity=700,initial_x=0,initial_y=0,\initial_velocity_x=700*math.cos(math.pi/4),\initial_velocity_y=700*math.sin(math.pi/4)):self.x = [initial_x]self.y = [initial_y]self.vx = [initial_velocity_x]self.vy = [initial_velocity_y]self.v = [initial_velocity]self.t = [0]self.m = massself.p = powerself.B_2 = air_resistanceself.dt = time_stepdef run(self):while(1):s1=self.x[-1] + self.vx[-1]*self.dts2=self.y[-1] + self.vy[-1]*self.dtv1=self.vx[-1] - self.dt *pow((1-(0.0065*self.y[-1])/300),2.5)*\(0.0039+0.0058/(1+math.exp((self.v[-1]-35)/5)))*\self.v[-1] * self.vx[-1]v2=self.vy[-1] - 9.8*self.dt - self.dt *\pow((1-(0.0065*self.y[-1])/300),2.5)*(0.0039+\0.0058/(1+math.exp((self.v[-1]-35)/5))) *\self.v[-1] * self.vx[-1]self.x.append(s1)self.y.append(s2)self.v.append(math.sqrt(self.vx[-1]*self.vx[-1] + self.vy[-1]*self.vy[-1]))self.vx.append(v1)self.vy.append(v2)if(s2<0):breakdef show_results(self):pl.plot(self.x,self.y,'b',label='angle is 43 degree')pl.title('Precise guidance system')pl.xlabel('X')pl.ylabel('Y')pl.legend()pl.ylim(0,)pl.show()a = cannon()a.run()a.show_results()
(1)Position of goal is(1000,100),the velocity of wind is -10m/s:
The minimum velocity:105.99231719970703m/s,angle:47°
(2)Position of goal is(1000,-100),the velocity of wind is -10m/s::
The minimum velocity:95.76740264892578m/s,angle:41°
(1)目标位置(1000,100),风速为-10m/s
最小速度105.99m/s
(2)目标位置(1000,-100),风速为-10m/m/s
最小速度为95.76m/s
感谢曹昕宇、杜威同学程序方便的帮助。