Dynamic simulation and theoretical curve of SIS virus model

SIS model

\( \frac{\mathrm{d}}{\mathrm{d}t}I=r\beta I\frac{S}{N}-\gamma I \\ \frac{\mathrm{d}}{\mathrm{d}t}S=-r\beta I\frac{S}{N}+\gamma I\)

View all models and descriptions: Infectious disease model simulation and theoretical trends

clear
figure
N = 100;        %Total population
I = 1;          %Infector
S = N - I;      %Susceptible person

R = 2;          %Number of infected persons exposed to susceptible persons
B = 0.03;       %Probability of infection
Y = 0.01;       %Recovery probability
days = 300;
Dynamic = false;  %Set to true to show the dynamic process


Sdata=[];

state=zeros(1,N);
index=randperm(N,I);
state(index)=1;
if Dynamic
    axis([0 N 0 N]);
    hold on
end
for i=1:days
    xpos=randperm(N);
    ypos=randperm(N);
    if sum(state)==100
        break
    end
    for j=1:N
        if state(j)~=1
            continue
        end
        if rand()<=Y
            state(j)=0;
            continue
        end
        dis=sqrt((xpos-xpos(j)).^2+(ypos-ypos(j)).^2);
        l=0;
        for k=1:N
            if state(k)==1
                continue
            end
            l=l+1;
            peo(l).dis=dis(k);
            peo(l).num=k;
        end
        T = struct2table(peo);
        sortedT = sortrows(T,'dis');
        sortedS = table2struct(sortedT);
        tp=sortedT{1:R,2};
        for k=1:length(tp)
            if rand()<=B
                state(tp(k))=1;
            end
        end
    end
    Sdata(i)=sum(state);
    %a=-8;
    %b=8;
    %xpos=xpos+ a + (b-a).*rand(1,N);
    %ypos=ypos+ a + (b-a).*rand(1,N);
    if Dynamic && rem(i,10)==0
        phd=scatter(xpos,ypos,[],state,"filled");
        title(['第' num2str(i) '天'])
        drawnow
        delete(phd)
    end
end

figure
set(gcf,'visible',true)
MaxFigure
days=length(Sdata);
plot(1:days,Sdata,1:days,N-Sdata)
hold on
T = 1:days+100;
for idx = 1:length(T)-1
    if S(idx)<0
        S(idx)=0;
    elseif S(idx)>N
        S(idx)=N;
    end
    if I(idx)<0
        I(idx)=0;
    elseif I(idx)>N
        I(idx)=N;
    end
    S(idx+1) = S(idx) - R*B*I(idx)*S(idx)/N + Y*I(idx);
    I(idx+1) = I(idx) + R*B*I(idx)*S(idx)/N - Y*I(idx);
end
plot(T,S,T,I);
legend('Simulated Infector','Simulate susceptible people','susceptible people','Infector');
xlabel('Day');ylabel('Number of people')
title('SIS model')Code language: Matlab (matlab)
 Unless otherwise stated, the articles are original.
 Title of this article:Dynamic simulation and theoretical curve of SIS virus model
 Hyperlink to this article:https://manwish.cn/en/article/dynamic-simulation-and-theoretical-curve-of-sis-virus-model-en.html

Leave a Comment