How can I find out the amount of susceptible, infected and recovered individuals in time = 50, where S(50), I(50), R(50)? (SIR MODEL)
# Equações diferenciais e suas condições iniciais
h = 0.05
beta = 0.8
nu = 0.3125
def derivada_S(time,I,S):
return -beta*I*S
def derivada_I(time,I,S):
return beta*I*S - nu*I
def derivada_R(time,I):
return nu*I
S0 = 0.99
I0 = 0.01
R0 = 0.0
time_0 = 0.0
time_k = 100
data = 1000
# vetor representativo do tempo
time = np.linspace(time_0,time_k,data)
S = np.zeros(data)
I = np.zeros(data)
R = np.zeros(data)
S[0] = S0
I[0] = I0
R[0] = R0
for i in range(data-1):
S_k1 = derivada_S(time[i], I[i], S[i])
S_k2 = derivada_S(time[i] + (1/2)*h, I[i], S[i] + h + (1/2)*S_k1)
S_k3 = derivada_S(time[i] + (1/2)*h, I[i], S[i] + h + (1/2)*S_k2)
S_k4 = derivada_S(time[i] + h, I[i], S[i] + h + S_k3)
S[i+1] = S[i] + (h/6)*(S_k1 + 2*S_k2 + 2*S_k3 + S_k4)
I_k1 = derivada_I(time[i], I[i], S[i])
I_k2 = derivada_I(time[i] + (1/2)*h, I[i], S[i] + h + (1/2)*I_k1)
I_k3 = derivada_I(time[i] + (1/2)*h, I[i], S[i] + h + (1/2)*I_k2)
I_k4 = derivada_I(time[i] + h, I[i], S[i] + h + I_k3)
I[i+1] = I[i] + (h/6)*(I_k1 + 2*I_k2 + 2*I_k3 + I_k4)
R_k1 = derivada_R(time[i], I[i])
R_k2 = derivada_R(time[i] + (1/2)*h, I[i])
R_k3 = derivada_R(time[i] + (1/2)*h, I[i])
R_k4 = derivada_R(time[i] + h, I[i])
R[i+1] = R[i] + (h/6)*(R_k1 + 2*R_k2 + 2*R_k3 + R_k4)
plt.figure(figsize=(8,6))
plt.plot(time,S, label = 'S')
plt.plot(time,I, label = 'I')
plt.plot(time,R, label = 'R')
plt.xlabel('tempo (t)')
plt.ylabel('Susceptível, Infectado e Recuperado')
plt.grid()
plt.legend()
plt.show()
I'm solving an university problem with python applying Runge-Kutta's fourth order, but a I don't know how to collect the data for time = 50.