Question: Hello please help. I have sir model and I am stuck. I don't know how to plot the proper solution. Right now the code plots
Hello please help. I have sir model and I am stuck. I don't know how to plot the proper solution. Right now the code plots 3 SIR graphs for each of the 3 different parameter values. But instead I want to print 3 graphs that plots the 3 susceptible solutions on one graph, the 3 exposed solutions on another graph and the 3 recovered solutions on the third graph. Thank you.
import scipy.integrate import matplotlib.pyplot as plt import numpy as np
gamma_ = [0.06, 0.05, 0.02] beta_ = [0.5, 0.6, 0.2] N = 10000 mu_ =[0.000041, 0.000064, 0.000014]
def sir(t, y): return np.array([mu*N-(beta*(y[1]/N)*y[0])-mu*y[0], (beta*(y[1]/N)*y[0])-(gamma+mu)*y[1],(gamma*y[1])-(mu*y[2])])
for (gamma, beta, mu) in zip(gamma_,beta_,mu_): t0 = 0 t_bound = 750 y0 = np.array([9000, 1000, 0]) sol = scipy.integrate.RK45(sir, t0, y0, t_bound) t = [] y = [] while sol.status == "running": t.append(sol.t) y.append(sol.y) sol.step()
plt.plot(np.array(t), np.array(y)) plt.legend(("s", "i", "r")) plt.xlabel("time") plt.ylabel("cases") plt.show()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
