From 0bb48824d312095fe0a2c8b22013fa662c47866b Mon Sep 17 00:00:00 2001 From: Kelly Anne Pierce Date: Tue, 4 Apr 2017 11:17:17 -0700 Subject: [PATCH] added basic SIR model function --- functions.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/functions.py b/functions.py index e69de29..de4ce4f 100644 --- a/functions.py +++ b/functions.py @@ -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() +