Created
March 29, 2020 18:24
-
-
Save EZLiang/cc9aaa2de2e42158872b3bb6454279e7 to your computer and use it in GitHub Desktop.
COVID-19 simulator
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
import numpy, scipy.integrate, matplotlib.pyplot | |
pop = 300000000.0 | |
recovery = 0.2 | |
badreco = 0.005 | |
death = 0.001 | |
contact = 0.3 | |
sick = 30000.0 | |
dead = 0.0 | |
recovered = 0.0 | |
def ds(x, y, z, a, b, c, d, e): | |
return sum([b * x * (a - x - z - y) / a, -x * e, -x * c, -x * d]) | |
def dr(x, y, z, a, b, c, d, e): | |
return x * e | |
def dd(x, y, z, a, b, c, d, e): | |
return x * c | |
def dv(t, vec, a, b, c, d, e): | |
return ds(*vec, a, b, c, d, e), dd(*vec, a, b, c, d, e), dr(*vec, a, b, c, d, e) | |
times = numpy.linspace(0, 360, 361) | |
def plot(transm): | |
matplotlib.pyplot.clf() | |
solution = scipy.integrate.odeint(dv, (sick, dead, recovered), times, tfirst=True, args=(pop, transm, death, badreco, recovery)) | |
matplotlib.pyplot.plot(times, solution[:, 0], "b", label="Sick") | |
matplotlib.pyplot.plot(times, solution[:, 1], "r", label="Deaths") | |
matplotlib.pyplot.plot(times, solution[:, 2], "g", label="Recovered") | |
matplotlib.pyplot.legend(loc="best") | |
plot(contact) | |
matplotlib.pyplot.xlabel("Days") | |
matplotlib.pyplot.ylabel("Cases") | |
matplotlib.pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment