""" Example code from lecture 5/11. A version of the SEIR model without lifelong immunity, developed by extending the SIR model class. """ from ODESolver import RungeKutta4 import matplotlib.pyplot as plt class SEIR: def __init__(self, beta = 1.44, mu = 0.2, nu = 0.2, gamma = 0.02): self.beta = beta self.mu = mu self.nu = nu self.gamma = gamma def __call__(self, t, u): beta = self.beta mu = self.mu nu = self.nu gamma = self.gamma S, E, I, R = u[0], u[1], u[2], u[3] N = S + E + I + R dS = -beta * S * I / N + gamma * R dE = beta * S * I / N - mu * E dI = mu * E - nu * I dR = nu * I - gamma * R return [dS, dE, dI, dR] model = SEIR() solver = RungeKutta4(model) T_span = (0, 30) steps = 300 u0 = [50, 1, 0, 0] solver.set_initial_condition(u0) t, u = solver.solve(T_span, steps) plt.plot(t, u) plt.legend(['S', 'E', 'I', 'R']) plt.show()