-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.2.py
61 lines (51 loc) · 1.53 KB
/
2.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
####################################################################
### This is the PYTHON version of program 2.2 from page 27 of #
### "Modeling Infectious Disease in humans and animals" #
### by Keeling & Rohani. #
### It is the simple SIR epidemic with equal births and deaths. #
####################################################################
###################################
### Written by Ilias Soumpasis #
### [email protected] (work) #
### [email protected] #
###################################
import scipy.integrate as spi
import numpy as np
import pylab as pl
mu=1/(70*365.0)
beta=520/365.0
gamma=1/7.0
TS=1.0
ND=60*365
S0=0.1
I0=1e-4
R0=1-S0-I0
INPUT = (S0, I0, R0)
def diff_eqs(INP,t):
'''The main set of equations'''
Y=np.zeros((3))
V = INP
Y[0] = mu - beta * V[0] * V[1] - mu * V[0]
Y[1] = beta * V[0] * V[1] - gamma * V[1] - mu * V[1]
Y[2] = gamma * V[1] - mu * V[2]
return Y # For odeint
t_start = 0.0; t_end = ND; t_inc = TS
t_range = np.arange(t_start, t_end+t_inc, t_inc)
RES = spi.odeint(diff_eqs,INPUT,t_range)
print RES
#Ploting
pl.subplot(311)
pl.plot(RES[:,0], '-g', label='Susceptibles')
pl.title('Program_2_2.py')
pl.xlabel('Time')
pl.ylabel('Susceptibles')
pl.subplot(312)
pl.plot(RES[:,1], '-r', label='Infectious')
pl.xlabel('Time')
pl.ylabel('Infectious')
pl.subplot(313)
pl.plot(RES[:,2], '-k', label='Recovereds')
pl.xlabel('Time')
pl.ylabel('Recovereds')
pl.show()