【预测模型】基于matlab SEIR模型疫情分析预测【含Matlab源码 666期】

一、简介

基于matlab SEIR模型的疫情分析预测

二、源代码

clear;clc;
[data,~]=xlsread('data.xls');%读取data中的数据放入data中
%声明全局变量
global g;           %潜伏着发病率
global t;           %发病者隔离率
global mu;          %治愈概率
global S;           %易感者人数
global E;           %潜伏者数量
global Ii;          %发病但未隔离数量
global Iu;          %发病且隔离数量
global D;           %死亡人数
global R;           %退出者

now_confirmed=data(45,:);       %现存确诊
sofar_confirmed=data(46,:);     %累计确诊
death=data(47,:);               %累计死亡
cured=data(48,:);               %累计治愈
N=5917e4;                       %总人口数
[testdata,~]=xlsread('test.xlsx');%读取test中的数据放入testdata中
Iu_new=testdata(1,:);
R_new=testdata(4,:);
D_new=testdata(3,:);
%---------------------------------------------------


D=[death(25:end) D_new];
R=[cured(25:end) R_new];
Iu=[now_confirmed(25:end) Iu_new];
sofar_confirmed=[sofar_confirmed(25:end) testdata(2,:)];
figure
plot(R,'g');
hold on;
plot(D,'r');
hold on;
plot(Iu,'b');


%estimate mu---------------------------------------------------------------
figure ('name','治愈率');
plot(diff(R)./Iu(2:end),'r');hold on;
p=polyfit(1:length((diff(R))./Iu(2:end)),diff(R)./Iu(2:end),1);
plot(1:length(diff(R)./Iu(2:end)),polyval(p,1:length(diff(R)./Iu(2:end))),'b');
mu=polyval(p,1:length(diff(R)./Iu(2:end)));
legend('实际','拟合');

%estimate E----------------------------------------------------------------
figure('name','潜伏者数量');
E=[];
for i=1:28
    E(end+1)=sofar_confirmed(i+12)-sofar_confirmed(i);
end
plot(E,'b');hold on
f=@(x,xdata)(x(1)*exp(-1*(x(2)*xdata+x(3))));
coeff=lsqcurvefit(f,[16000,1,0],1:length(E),E);
plot(f(coeff,1:length(E)),'r');
title('E estiamte');
legend('实际','拟合');
E=f(coeff,1:40);E=E(1:end-2);


%estimate Ii---------------------------------------------------------------
Ii=[];
for i=1:38
    Ii(end+1)=sofar_confirmed(i+2)-sofar_confirmed(i);
end


%--------------------------------------------------------------------------
D=D(1:end-2);
R=R(1:end-2);
Iu=Iu(1:end-2);
S=N-D-R-Ii-Iu-E;
t=1;
g=0.1;
global start;
start=[S(1),E(1),Ii(1),Iu(1),R(1),D(1)];            %定义初始状态
[x fval]=fmincon('ff',[0.05 0.05 1e-7 1e-7],[],[],[],[],[0 0 0 0],[5 5 0.1 0.1]);       %求解非线性多元函数最小值
mu=polyval(p,1:100);
y=SEIR_discrete(start,t,g,mu,x(1),x(2),x(3),x(4),54);

三、运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、备注

完整代码或者代写添加QQ 1564658423

猜你喜欢

转载自blog.csdn.net/TIQCmatlab/article/details/115375810