# How Epidemics Spread 3, Exercise 2: steps that are too big # Exercise 2: steps that are too big. High transmission (assumed beta = 2.0, gamma = 0.2). population, beta, gamma = 10_000, 2.0, 0.2 def run(dt, guard, days=60): S, I, R = population - 1.0, 1.0, 0.0 lowest_S = S for _ in range(int(days / dt)): new_inf = beta * S * I / population * dt if guard: new_inf = min(new_inf, S) new_rec = gamma * I * dt S -= new_inf I += new_inf - new_rec R += new_rec lowest_S = min(lowest_S, S) return lowest_S, I for dt in [1.0, 0.5, 0.1, 0.01]: for guard in [False, True]: low, I = run(dt, guard) note = " <- negative people!" if low < 0 else "" print(f"dt {dt:5.2f} guard {str(guard):5s} lowest S {low:10.1f} I at day 60 {I:10.1f}{note}") # Output when run: # dt 1.00 guard False lowest S -762.3 I at day 60 0.1 <- negative people! # dt 1.00 guard True lowest S 0.0 I at day 60 0.1 # dt 0.50 guard False lowest S 0.0 I at day 60 0.1 # dt 0.50 guard True lowest S 0.0 I at day 60 0.1 # dt 0.10 guard False lowest S 0.3 I at day 60 0.2 # dt 0.10 guard True lowest S 0.3 I at day 60 0.2 # dt 0.01 guard False lowest S 0.4 I at day 60 0.2 # dt 0.01 guard True lowest S 0.4 I at day 60 0.2