首页 > 解决方案 > 为什么'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()

标签: pythonodeint

解决方案


您需要传递tfirst=True给 odeint,正如f(y, t)默认情况下所期望的那样。


推荐阅读