I was given two equations one for the growth healthy people in the population,
dh/dt=-.05*h*s+.0003*h,
and the other equation is for the infection rate of sick people
ds/dt=.05*h*s-.01*s.
assume that after 10 days of being infected the people die.
for initial variables h=9000 and s=100
using the differential equations generate a figure predicting the impact of the out come of the infection on the population. It was suggested that eulers method be used, how would I use Eulers method using multiple differential equations? or is there a better method you would suggest and how would you use it?
In python you would use, for instance, scipy.integrate.odeint
and compute
def odesys(u,t):
h, s = u
return [ -.05*h*s+.0003*h, .05*h*s-.01*s]
h0, s0 = 9000, 100
t0, tf = 0, 0.10
t = linspace(t0, tf, 301)
sol = odeint(odesys, [h0, s0], t)
h, s = sol.T
plot(t,h, label="healthy")
plot(t,s, label="sick")
And if you have to use Euler, using the same interface if would look like
def odeinteuler(f, y0, tspan):
y = zeros([len(tspan),len(y0)])
y[0,:]=y0
for k in range(1, len(tspan)):
y[k,:] = y[k-1,:]+(t[k]-t[k-1])*array(f(y[k-1], t[k-1]))
return y
sol = odeint(odesys, [h0, s0], t)