Question: Hello, i need help editing my python code. The objective is to pass the arrays as parameters into the system of equations (I also want

Hello, i need help editing my python code. The objective is to pass the arrays as parameters into the system of equations (I also want to plot the solution). Basically I need all the first elements of each array to be passed into the system of odes, and then I need all the second elements of each array to be passed into the system, so on and so forth. But i dont know how to do that. I know I need a for loop somewhere but I am stuck on how to do this efficiently. Please help me edit it properly. Here is what I have that works so far.

#i put a hashtag by the parameter values that I would like to change into arrays.

#please make sure that the Python code runs and works properly without errors. Thanks!

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

c = 0.04 #I want to change this to the array c = 0.03,0.041,0.02 sigma_a = 0.11 f = 100000 e = 0.4 sigma_b = 0.3 d = 0.03 #I want to change this to the array d = 0.04,0.05,0.02 alpha = 0.09 gamma = 1/4 a = 0.2 #I want to change this to the array a = 0.32,0.51,0.12 b = 0.3 #I want to change this to the array b = 0.4,0.551,0.14

def eqs(t, y): return np.array([-(e*(y[2]+y[3])/f)*y[0], (e*(y[2]+y[3])/f)*y[0]-gamma*y[1], a*gamma*y[1]-sigma_a*y[2], (1-a)*gamma*y[1]-sigma_b*y[3], b*sigma_a*y[2]-alpha*y[4], (1-b-d)*sigma_b*y[2]+sigma_b*y[3]+(1-c)*alpha*y[4], d*sigma_a*y[2]+c*alpha*y[4]]) t0 = 0 t_bound = 100 y0 = np.array([90000,700,500,500,0,0,0]) sol = scipy.integrate.RK45(eqs, 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", "E","Is", "Ia", "H", "R", "D")) 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!