"""Original numerical illustration. Tested with Python 3.14, NumPy 2.3 and Matplotlib 3.10. Writes its PNG basename to the current working directory. """ from pathlib import Path import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt EPIDEMIC_RNG=np.random.default_rng(2345) def sir_sim(t_max,X0,beta,gamma,rng=None): if rng is None:rng=EPIDEMIC_RNG state=np.array(X0,dtype=int);population=state.sum();time=0. times=[time];states=[state.copy()] while time0: infection=beta*state[0]*state[1]/population;recovery=gamma*state[1] rate=infection+recovery if rate==0: times.append(float(t_max));states.append(state.copy());break next_time=time+rng.exponential(1/rate) if next_time>t_max: times.append(float(t_max));states.append(state.copy());break if rng.random()