如何解决如何在python中的ODE中为变量添加约束?
我需要求解一个微分方程组,并且我有一个返回dx / dt和du / dt的函数,但是我需要添加u在区间[0,1]中的约束。我怎样才能做到这一点?到目前为止,我一直在使用scipy.integrate的odeint来解决它。这是模型:
def model_case_1(z,t,Kmax):
'''The input z corresponds to the current state of the system,z = [x,u,m]
(x is the population,u is the resistance rate and m whether there is treatment or not).
t is the current time.
Kmax corresponds to the unkNown parameter.
'''
x,u= z
if t>0:
m=1
else:
m=0
dxdt = x*(r*(1-x//(Kmax*(1-u)))-m//(k+b*u)-d)
dudt = sigma*(m*b//((k+b*u)**2)-r*x//(Kmax*(1-u)**2))
return [dxdt,dudt]
然后我估计Kmax并用以下公式求解ODE:
y = odeint(model_case_1,[x0,u0],teval,args=(Kmax0,))
但是,当然,我得到的u值大于1,这是不可能的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。