我刚开始学习python,老师让我模拟模型火箭的轨迹,知道发动机的推力
我已经用odeint函数得到了火箭的速度和加速度。但是,我不知道如何使用速度和时间
我已经得到了火箭的飞行距离,因为速度是用odeint函数求出来的
下面是我用来计算速度的代码:
def getforce(t):
if 0<=t<0.15:
F = 40*t
elif 0.15<=t<0.7:
F = -9.09*t+7.36
elif 0.7<=t<1.25:
F = 1
elif 1.25<=t<1.65:
F = 7.5*t-8.375
elif 1.65<=t<1.8:
F = -26.6*t+48
else:
F = 0
return F
def getspeed(x,t):
Ft = getforce(t)
y0,y1 = x
dy0 = y1
dy1 = (Ft-0.0001277422*y1**2*np.sign(y1)-0.174)/0.0177
return dy0,dy1
t = np.linspace(0,10,100)
sol = si.odeint(getspeed,(0,0),t)
plt.plot(t,sol[:,0])
plt.show()
假设其他一切都是正确的,您只需手动积分速度
(我无法轻松检查整体正确性的原因是,您在速度部分使用了一个非正统(给定)表达式,而不是求解包含质量损失F=ma>;d(m*v)/dt=dm/dt*v+m*dv/dt.)
我没有使用numpy或lambda表达式来集成以保持它的可读性,因为执行速度对于本例来说无关紧要
相关问题 更多 >
编程相关推荐