From a666419f12ff5739f398e97e115f35be06ec4c6d Mon Sep 17 00:00:00 2001 From: Lucas Costa Date: Thu, 26 Jan 2023 10:09:21 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Adicionando=20arquivo=20Runge=20Kutta=20de?= =?UTF-8?q?=204=C2=B0=20ordem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RungeKutta_4ordem.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 RungeKutta_4ordem.py diff --git a/RungeKutta_4ordem.py b/RungeKutta_4ordem.py new file mode 100644 index 0000000..105db63 --- /dev/null +++ b/RungeKutta_4ordem.py @@ -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() \ No newline at end of file From 9c74eea6ce5730ce59a06384eceef7fbee7870e7 Mon Sep 17 00:00:00 2001 From: Lucas Costa Date: Tue, 31 Jan 2023 23:40:12 -0300 Subject: [PATCH 2/3] =?UTF-8?q?Adicionando=20m=C3=A9todo=20de=20RungeKutta?= =?UTF-8?q?=20de=205=C2=B0=20ordem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RungeKutta5.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 RungeKutta5.py diff --git a/RungeKutta5.py b/RungeKutta5.py new file mode 100644 index 0000000..f324879 --- /dev/null +++ b/RungeKutta5.py @@ -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() \ No newline at end of file From d3e2cfe9df850ae75f0c38eab8d866dfa54a5bfa Mon Sep 17 00:00:00 2001 From: Lucas Costa Date: Thu, 2 Feb 2023 11:19:12 -0300 Subject: [PATCH 3/3] Adicionando Modelo SIR --- ModeloSIR.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 ModeloSIR.py diff --git a/ModeloSIR.py b/ModeloSIR.py new file mode 100644 index 0000000..368c761 --- /dev/null +++ b/ModeloSIR.py @@ -0,0 +1,55 @@ +# Author: Lucas Costa Fernandes +# Linkedin: https://www.linkedin.com/in/lucascostafernandes/ +# GitHub: https://github.com/LucaCosta +# Email: lucascosfer26@gmail.com + +# 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() \ No newline at end of file