Reputation: 1
I am extremely new to any coding and am having a lot of python issues (python 3). I am trying to recreate figures in a scientific paper relating to HIV. They have used a computer simulation of there model which I have to recreate. I keep changing aspects and keep getting different error messages - the current one is TypeError: odeint() missing 1 required positional argument: 't'
Here is the code I am using,based off of a previous assignment I did.
#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 and v are equations given in the scientific paper which I need to graph against one anotherodeint code:
The variables were given in the paper I'm sorry if this seems really basic but would really appreciate any help. This has been edited to add in my code.
Upvotes: 0
Views: 482
Reputation: 8303
You do not use it correctly. Your ode function MUST be of the form f(x,t,params), where x can be a vector (2-dimensional in your case: for x and v as a variables dependent on time).
Try to rewrite your code in the following way:
#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)
For equation parameters it is good to use python dictionary.
Upvotes: 1