微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Scipy solve_ivp RuntimeWarning: 在 true_divide 中遇到除以零

如何解决Scipy solve_ivp RuntimeWarning: 在 true_divide 中遇到除以零

solve_ivp 求解器非常适合我。然后我改变了一个初始条件,它停止工作,即使我把它改回来。

C:\Program Files FF\lib\site-packages\scipy\interpolate\interpolate.py:630: RuntimeWarning: divide by zero encountered in true_divide
slope = (y_hi - y_lo) / (x_hi - x_lo)[:,None]

C:\Program Files FF\lib\site-packages\scipy\interpolate\interpolate.py:633: RuntimeWarning: invalid value encountered in multiply
y_new = slope*(x_new - x_lo)[:,None] + y_lo

我的代码片段

cd = interp( machData,cdData,bounds_error=False,fill_value="extrapolate" )
thrust = interp( timeData,thrustData,fill_value="extrapolate" )
massFuel = interp( timeData,massData,fill_value="extrapolate")

def drag(h,v):
    return( np.sign(v)*0.5*cd(v/sos(h))*dens(h)*v**2*area)

def mass(t):
    return( massEmpty + massFuel(t))

def ode1(t,y):
    dy = np.zeros((2,))
    dy[0] = y[1]
    dy[1] = (thrust(t)-drag(y[0],y[1]))/mass(t) - 9.81
    return(dy)
def ode2(t,))
    dy[0] = y[1]
    dy[1] = (-drag(y[0],y[1]))/massEmpty - 9.81
    return(dy)
def event( t,y):
    return( y[1] )
event.terminal = True
event.direction = -1

tspan = (timeData[0],timeData[-1])
y0 = [xlcell("SimulateFlight",2,3),0]
sol = solve_ivp( ode1,tspan,y0,rtol=1e-7 )


tspan = [sol.t[-1],100]
y0 = sol.y[:,-1]
sol2 = solve_ivp( ode2,rtol=1e-7,events=event )

t = np.append(sol.t,sol2.t)
y = np.append(sol.y,sol2.y,axis=1)

这应该是我队友使用的计算器,所以我需要一个内置的集成器。希望找到更像 MATLAB 的 ode45 的东西。我想我不需要很高的准确度,所以我可以编写一个 eular 积分器。只是想知道是否有人知道发生了什么以及为什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。