Skip to content

Instantly share code, notes, and snippets.

@ShuaiGuo16
Created January 13, 2021 10:26
Show Gist options
  • Save ShuaiGuo16/973f03179a4a407b5d638323d94e7da2 to your computer and use it in GitHub Desktop.
Save ShuaiGuo16/973f03179a4a407b5d638323d94e7da2 to your computer and use it in GitHub Desktop.
SIR model
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