Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python

"""This program uses scipy to integrate and plot the results of a basic SIR model"""


from scipy import *
from scipy.integrate import *
from pylab import *

#Define Constants
Beta=2.0
gamma=.8
init=array([0.95,0.05,0.0])
finalTime=20.0
time=arange(0,finalTime, 0.01)

def derv(x,t):
"""Computes the derv operator for the basic sir model"""

y=zeros(3);
y[0]=-Beta*x[0]*x[1]
y[1]=Beta*x[0]*x[1]-gamma*x[1]
y[2]=gamma*x[1]
return(y)


r=odeint(derv, init, time)

plot(time, r[:,0], "r", time, r[:,1], "g", time, r[:,2], "b")
legend(("Susceptible","Infected","Recovered"), loc=0)
ylabel("Number of People")
xlabel("Time")
title("SIR Model")

show()