python - 为什么'odeint'不允许我在这里解压浮动对象?
问题描述
我正在用 odeint 测试一些运动方程。我试图整合和测试这些,同时说我的控制(我们)一直是 0。但是,我收到上述错误,我不明白为什么。非常感谢任何建议!
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
from scipy.interpolate import interp1d
import pickle
Ro = 6371000 #m
hs = -7254.24 #m scale height
rhosl = 1.225 #kg^3
Aref = 250 #m^2
m = 92079 #kg mass of vehicle
#cl and cd spline
dat = pickle.load(open('clp.pkl','rb'))
AOA =dat[0]
cl = dat[1]
cd = dat[2]
AOAnew = AOA.tolist()
cl1 = cl.tolist()
cd1 = cd.tolist()
clnew = interp1d(AOAnew,cl1,kind='linear')
cdnew = interp1d(AOAnew,cd1,kind='linear')
def rhos(h):
rho = rhosl*np.exp((hs)/h)
return rho
def f(t,xs):
r,theta,phi,V,gamma,psi = xs
L = Ro*(rhos(r))*V**2*Aref*(clnew(gamma))/(2*m)
D = Ro*(rhos(r))*V**2*Aref*(cdnew(gamma))/(2*m)
us = 0
drdot = V*np.sin(gamma)
dthetadot = (V*np.cos(gamma)*np.sin(gamma))/(r*np.cos(phi))
dphidot = (V*np.cos(gamma)*np.cos(psi))/r
dVdot = -D - np.sin(gamma/r**2)
dgammadot = (L*np.cos(us)/V) + (V**2 - (1/r))*np.cos(gamma/(V*r))
dpsidot = L*np.sin(us)/(V*np.cos(gamma)) + V*np.cos(gamma)*np.sin(psi)*np.tan(phi/r)
return [drdot,dthetadot,dphidot,dVdot,dgammadot,dpsidot]
#initial/terminal conditiions
h0 = 79248
theta0 = 0
phi0 = 0
V0 = 7802.88
gamma0 = -1/np.pi
psi0 = 90/np.pi
y0 = [h0,theta0,phi0,V0,gamma0,psi0]
t = np.linspace(0,20)
y = odeint(f,y0,t)
plt.plot(t,y)
plt.show()
解决方案
您需要传递tfirst=True
给 odeint,正如f(y, t)
默认情况下所期望的那样。
推荐阅读
- laravel - 带有身份验证的 Laravel Passport (Api) (Google、Facebook)
- dynamics-crm - Dynamics CRM 365 销售和业务中心集成
- c# - 使用 .net core 3.1 将 .Net5.0 包添加到项目中
- reactjs - React HashLink - 不变式失败:您不应该在外部使用
- scala - 如何在 Spark Dataframe 中将一个时区转换为另一个时区
- docker - 如何从 ngnix.conf 文件中解决基本 URL 中的 www 问题
- r - loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) 中的错误:没有名为“rio”的包
- javascript - 使用 JavaScript 在 HTML 表格中显示从 JSON 获取的数据 - 网站上不同部分中的不同数据部分
- jquery - 如何在点击时覆盖 jQuery 函数以进行图像缩放?
- python - 如何将 HTML 转换为 docx