""" Example code from lecture 5/11. Function implementation of the simplest version of the SIR model. This implementation is almost identical to the class version, and a bit simpler, but the class version is better if we want ot run the model for different parameter values. """ from ODESolver import RungeKutta4 import matplotlib.pyplot as plt def SIR_model(t, u): beta = 1.44 nu = 0.2 S, I, R = u[0], u[1], u[2] N = S + I + R dS = -beta * S * I / N dI = beta * S * I / N - nu * I dR = nu * I return [dS, dI, dR] solver = RungeKutta4(SIR_model) T_span = (0, 30) steps = 300 u0 = [50, 1, 0] solver.set_initial_condition(u0) t, u = solver.solve(T_span, steps) plt.plot(t, u) plt.show()