Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions