SEIR模型的matlab实现

  1. 基础版matlab代码:
clear;clc;

global N;   N = 2489.43e4;	%地区总人数
T = 1:100;  %设置时间观察到第150[data,~]=xlsread('data.xlsx');%读取data中的数据放入data中
Ir = data(:,2); %63天实际感染者数量

z = zeros(length(T)-length(Ir),1); %未知天数数据赋0
Ir = [Ir;z]; %数组扩展
Ir = Ir';
zz = find(Ir==0);
Ir(zz)=NaN;

% Real
% figure
% %plot(T(1:63),Ir);grid on
% plot(T,Ir,'LineWidth',1.5);grid on
% legend('实际感染者')
% xlabel('天数');ylabel('人数')
% hold on

% Estimate
% 定义初始状态各人数
%N = 24894300; %总人数

E = 590;  %E类暴露者Exposed,指接触过感染者,但暂无能力传染给其他人的人,对潜伏期长的传染病适用;
%本例中第一天为590个。

I = 401;  %I类感病者Infectious,指染上传染病的人,可以传播给S类易感成员,将其变为 E 类或 I 类成员;
%本例中第一天为401个。

S = N - I;  %易感者 (Susceptible),指未得病者,但缺乏免疫能力,与感染者接触后容易受到感染;
%假设某区域的人口数为10000,那么第一天的S=N-I=9999

R = 0;  %康复者Recovered,指被隔离或因病愈而具有免疫力的人。如免疫期有限,R 类成员可以重新变为 S 类。
%本例中第一天为0个。

r = 20; %感染患者(I)每天接触的易感者数目,本例为20

B = 0.023;   %传染系数;由疾病本身的传播能力,人群的防控能力决定,本例设置为0.03

a = 0.07;    %潜伏者的发病概率;一般为潜伏期的倒数,本例为1/14

y = 0.1;    %恢复系数;一般为病程的倒数,例如流感的病程5天的话,那么它的γ就是1/5,本例设置为1/10=0.1

% T = 1:150;  %设置时间观察到第150for i = 1:length(T)-1

S(i+1) = S(i) - r*B*S(i)*I(i)/N(1);

E(i+1) = E(i) + r*B*S(i)*I(i)/N(1)-a*E(i);

I(i+1) = I(i) + a*E(i) - y*I(i);

R(i+1) = R(i) + y*I(i);

end

plot(T,S,T,E,T,I,T,R,'LineWidth',1.5);grid on;

xlabel('天数');ylabel('人数')

legend('易感者','潜伏者(暴露者)','感染者','康复者')

% plot(T,I,T,Ir,'LineWidth',1.5);grid on
% xlabel('天数');ylabel('人数')
% legend('预测感染者','实际感染者')

参考来源:https://blog.csdn.net/weixin_39790168/article/details/111008359?spm=1001.2014.3001.5506
参考文献:基于SEIR的新冠肺炎传播模型及拐点预测分析_范如国

  1. 优化版(增加动态参数)matlab部分代码:
B = 0.5; %初始传染系数
k = 1; %形态参数
L = 22; %衰减速率

for i = 1:length(T)-1
%-----------------------修改部分-------------------------
B = exp(-(T(i)/L)^k*log(2));
S(i+1) = S(i) + B*(S(i)+a*E(i))*I(i)/N(1);
E(i+1) = E(i) + B*(S(i)+a*E(i))*I(i)/N(1)-a*E(i);
%--------------------------------------------------------
%S(i+1) = S(i) - r*B*S(i)*I(i)/N(1);
%E(i+1) = E(i) + r*B*S(i)*I(i)/N(1)-a*E(i);

I(i+1) = I(i) + a*E(i) - y*I(i);

R(i+1) = R(i) + y*I(i);

end

参考文献:基于改进SEIR算法的疫情传播趋势检测方法_燕杨

  • 11
    点赞
  • 91
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
Sure! Here's an example of a MATLAB code implementation for the SEIR model: ```matlab % SEIR Model Parameters N = 1000; % Total population size beta = 0.3; % Contact rate gamma = 0.1; % Recovery rate sigma = 0.2; % Incubation rate % Initial conditions I0 = 1; % Initial number of infected individuals E0 = 0; % Initial number of exposed individuals R0 = 0; % Initial number of recovered individuals S0 = N - I0 - E0 - R0; % Initial number of susceptible individuals % Time vector tStart = 0; tEnd = 100; tStep = 1; tspan = tStart:tStep:tEnd; % SEIR Model equations dSdt = @(t, S, E, I, R) -beta * S * I / N; dEdt = @(t, S, E, I, R) beta * S * I / N - sigma * E; dIdt = @(t, S, E, I, R) sigma * E - gamma * I; dRdt = @(t, S, E, I, R) gamma * I; % Solve the SEIR equations [~, SEIR] = ode45(@(t, y) [dSdt(t, y(1), y(2), y(3), y(4)); dEdt(t, y(1), y(2), y(3), y(4)); dIdt(t, y(1), y(2), y(3), y(4)); dRdt(t, y(1), y(2), y(3), y(4))], tspan, [S0, E0, I0, R0]); % Plot the results plot(tspan, SEIR(:, 1), 'b', 'LineWidth', 2); hold on; plot(tspan, SEIR(:, 2), 'r', 'LineWidth', 2); plot(tspan, SEIR(:, 3), 'g', 'LineWidth', 2); plot(tspan, SEIR(:, 4), 'm', 'LineWidth', 2); legend('Susceptible', 'Exposed', 'Infected', 'Recovered'); xlabel('Time'); ylabel('Population'); title('SEIR Model Simulation'); ``` This code uses the `ode45` function to solve the differential equations of the SEIR model. The results are then plotted to visualize the dynamics of the susceptible, exposed, infected, and recovered populations over time. Remember to adjust the parameters and initial conditions according to your specific scenario.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值