为啥'odeint'不允许我在这里解压浮动对象?
Posted
技术标签:
【中文标题】为啥\'odeint\'不允许我在这里解压浮动对象?【英文标题】:Why will 'odeint' not let me unpack float object here?为什么'odeint'不允许我在这里解压浮动对象? 【发布时间】:2021-11-15 08:53:18 【问题描述】:我正在使用 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()
【问题讨论】:
【参考方案1】:您需要将tfirst=True
传递给odeint,因为它默认需要f(y, t)
。
【讨论】:
以上是关于为啥'odeint'不允许我在这里解压浮动对象?的主要内容,如果未能解决你的问题,请参考以下文章
为啥我在这里看到“Access-Control-Allow-Origin 不允许来源”错误? [复制]