Question: Hello. I need help editing a python code (it's an SIR model). Right now the parameter value, beta = 0.6, which is a single numeric

Hello. I need help editing a python code (it's an SIR model). Right now the parameter value, beta = 0.6, which is a single numeric value. I want to edit this code so that I can consider having a different rate of infection, beta, for different age groups. So beta would be a list of values for each i age group. Something like this:

beta = [0.6,0.4,0.2]

But I dont know how to make the code run with beta being an array of values. Please show me how to edit the code so that it runs properly with the edit I want to make for beta.

import scipy.integrate import matplotlib.pyplot as plt import numpy as np

def ode(t, y): gamma = 0.03 beta = 0.6 N = 30000 mu = (0.02/365) 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])])

t0 = 0 t_bound = 2000 y0 = np.array([2998, 20, 0]) sol = scipy.integrate.RK45(ode, 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(("susceptible", "Infected", "Recovered")) plt.xlabel("time") plt.ylabel("cases") plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!