Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions ModeloSIR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Author: Lucas Costa Fernandes
# Linkedin: https://www.linkedin.com/in/lucascostafernandes/
# GitHub: https://github.com/LucaCosta
# Email: [email protected]

# O modelo SIR para disseminação de doenças. Baseado no artigo
# "The SIR Model for Spread of Disease - The Differential Equation Model"
# Author(s): David Smith and Lang Moore"

# Importando bibliotecas
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Total population, N.
N = 7900000
# Initial number of infected and recovered individuals, I0 and R0.
I0, R0 = 10, 0
# Everyone else, S0, is susceptible to infection initially.
S0 = N - I0 - R0
# Contact rate, beta, and mean recovery rate, gamma, (in 1/days).
beta, gamma = 1/2, 1/3
# A grid of time points (in days)
t = np.linspace(0, 160,160)
# The SIR model differential equations.
def deriv(y, t, N, beta, gamma):
S, I, R = y
dSdt = (-beta * S * I) / N
dIdt = (beta * S * I) / N - gamma * I
dRdt = gamma * I
return dSdt, dIdt, dRdt
# Initial conditions vector
y0 = S0, I0, R0
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=(N, beta, gamma))
S, I, R = ret.T
# Plot the data on three separate curves for S(t), I(t) and R(t)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, facecolor='#dddddd', axisbelow=True)
plt.title ('Modelo SIR')
plt.figure(figsize=(8, 8))
ax.plot(t, S/N, 'b', alpha=0.5, lw=2, label='Susceptible')
ax.plot(t, I/N, 'r', alpha=0.5, lw=2, label='Infected')
ax.plot(t, R/N, 'g', alpha=0.5, lw=2, label='Recovered with immunity')
ax.set_xlabel('Time /days')
ax.set_ylabel('Number (1000s)')
ax.set_ylim(0,1.2)
ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
for spine in ('top', 'right', 'bottom', 'left'):
ax.spines[spine].set_visible(False)
plt.show()
38 changes: 38 additions & 0 deletions RungeKutta5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import pylab as plt

def f(P,t):
r=0.8
K=100
valor = r*P*(1-P/K)
return valor

a=0
b= 100
Num = 100 # Para diminuir o erro deve-se aumentar o valor de Num
h =(b-a)/Num
P = 0.5 # Xn

t_pontos = np.arange(a,b,h)
P_pontos =[]
# Method of Runge kutta 5th

for i in t_pontos:
P_pontos.append(P)
k1 = h*f(P,i)
k2 = h*f(P + h/4, i + k1/4)
k3 = h*f(P + (3/8 * h), i + (3/32 * k1) + (9/32 * k2))
k4 = h*f(P + (12/13 * h), i + (1932/2197 * k1) - (7200/2197 * k2) + (7296/2197 * k3))
k5 = h*f(P + h, i + (439/216 * k1) - (8 * k2) + (3680/513) * k3 - (845/4104 * k4))
P = P + (25/216 * k1) + (1408/2565 * k3) + (2197/4104 * k4) - k5/5


print(P_pontos[1])

plt.plot(t_pontos,P_pontos,color='#FF4500',linewidth=1.5, label='função dP/dt=P')
plt.ylim(0,110)
plt.title('Gráfico da função sigmóide')
plt.xlabel('t')
plt.ylabel('P(t)')
plt.grid(True)
plt.show()
37 changes: 37 additions & 0 deletions RungeKutta_4ordem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This code is a solution for the differential equation dP/dt =P

# Method of Runge Kutta 4th

import numpy as np
import pylab as plt

def f(P,t):
valor = 10*np.exp(-((t-2)**2)/(2*(0.075)**2)) - 0.6 * P
return valor

a=0
b= 4
Num = 100 # Para diminuir o erro deve-se aumentar o valor de Num
h =(b-a)/Num
P = 0.5

t_pontos = np.arange(a,b,h)
P_pontos =[]
# Method of Runge kutta 4th

for i in t_pontos:
P_pontos.append(P)
k1 = h * f(P,i)
k2 = h * f(P+0.5*k1, i+0.5*h)
k3 = h * f(P+0.5*k2,i+0.5*h)
k4 = h * f(P+k3,i+h)
P += (k1+2*k2+2*k3+k4)/6

print(P_pontos[1])

plt.plot(t_pontos,P_pontos,color='#FF4500',linewidth=1.5, label='função dP/dt=P')
plt.title('Gráfico da função resolução do problema')
plt.xlabel('t')
plt.ylabel('P(t)')
plt.grid(True)
plt.show()