【问题标题】:Using Odeint to Graph Figures Using Differential Equations使用 Odeint 使用微分方程绘制图形
【发布时间】:2016-03-08 09:12:03
【问题描述】:

我对任何编码都非常陌生,并且遇到了很多 python 问题(python 3)。 我正在尝试在一篇与 HIV 相关的科学论文中重现数字。他们使用了我必须重新创建的模型的计算机模拟。我不断改变方面并不断收到不同的错误消息 - 当前的错误消息是 TypeError: odeint() missing 1 required positional argument: 't'

这是我正在使用的代码,基于我之前的作业。

#Import necessary programmes
import numpy as np
from scipy.integrate import odeint as od 
import matplotlib.pyplot as plt
#define equation for uninfected vs free virus
def free_virus(x,y,v,vm):
    x=x=l-(d*x)-(b*x*v)-(bm*x*vm) 
    v=(k*y)-(u*v)
    return np.array(x,v)
l=10
d=0.01
a=0.5
u=3
b=0.01
bm=0.005
e=0.0001
k=km=10
init= [0,0]
t= np.arange(0,40,5)
figure_1=od(free_virus,t,args=(0,40))
plt.plot(figure_1,t)

x 和 v 是科学论文中给出的方程式,我需要将它们相互对照odeint code:

变量在论文中给出 如果这看起来很基本,我很抱歉,但非常感谢任何帮助。这已被编辑添加到我的代码中。

【问题讨论】:

  • 我以为我已将其作为图片附加:我是新来的 - 现在已添加。谢谢。

标签: python-3.x differential-equations odeint


【解决方案1】:

您没有正确使用它。您的 ode 函数必须采用 f(x,t,params) 的形式,其中 x 可以是一个向量(在您的情况下是二维的:对于 x 和 v 作为依赖于时间的变量)。

尝试用以下方式重写你的代码:

#Import necessary programmes
import numpy as np
from scipy.integrate import odeint as od 
import matplotlib.pyplot as plt
#define equation for uninfected vs free virus
def free_virus(X,t,params):
    x = your eq dependent on X, t and params
    v = your second eq
    return np.array(x,v)
paramsDict = {'l':10, 'd':0.01 .... and so on}
init= [0,0]
t= np.arange(0,40,5)
figure_1=od(free_virus,t,args=paramsDict)
plt.plot(figure_1,t)

对于方程参数,最好使用 python 字典。

【讨论】:

    猜你喜欢
    • 2012-02-28
    • 1970-01-01
    • 2020-07-13
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    相关资源
    最近更新 更多