Created
January 13, 2021 10:26
-
-
Save ShuaiGuo16/973f03179a4a407b5d638323d94e7da2 to your computer and use it in GitHub Desktop.
SIR model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def SIR_model(beta, gamma, t, N, I0, R0): | |
"""The function solves the SIR model to simulate | |
the disease spreading""" | |
S0 = N - I0 - R0 | |
def deriv(y, t, N, beta, gamma): | |
S, I, R = y | |
dSdt = -beta * S * I / N | |
dIdt = beta * S * I / N - gamma * I | |
dRdt = gamma * I | |
return dSdt, dIdt, dRdt | |
ret = odeint(deriv, [S0, I0, R0], t, args=(N, beta, gamma)) | |
return ret.T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment