2015-12-03 48 views
0

我對任何編碼都非常新,並且有很多python問題(python 3)。 我正試圖在一篇有關艾滋病的科學論文中重現數字。他們使用了我必須重新創建的模型的計算機模擬。我不斷變化的方面,並不斷收到不同的錯誤信息 - 目前是 TypeError: odeint() missing 1 required positional argument: 't'使用Odeint圖形使用微分方程

這是我使用的代碼,基於我以前的任務。

#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

的變量在紙 我很抱歉,如果這似乎很基本的,但會給予非常感謝任何幫助。這已被編輯添加在我的代碼。

+0

我以爲我把它作爲一個圖片添加進來:我是新來的 - 現在已經添加了。謝謝。 –

回答

0

您不正確使用它。你的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字典。