Help with an infection simulation?

4 views (last 30 days)
Lo
Lo on 8 May 2014
Hi,
I'm trying to create a simulation of an infection spreading. I have the code for a spatial view of the spread, just on a grid. Now, I'm trying to put that on a map of the world. I think that geoshow might be the best bet in creating that, but I'm not sure about how to go about that.
I've attached my code for the original. I've been playing around with the simulation on the world map, but I really dont know what direction I should be headed in:
close all clear all
figure; worldmap world load coast plotm(lat, long) geoshow('landareas.shp','Facecolor',[0.5 0.7 0.5]) set(gcf,'double','on') hold on
dt=0.1; t1=10; time=0:dt:t1; a=0.5;b=1;ratio=a/b;
N=101;L=50; latgrid=ones(N,1)*linspace(-L,L,N); longrid=linspace(-L,L,N)'*ones(1,N); state=zeros(N,N); % state(i,j)=1 infected; -1 recoverd; 0 susceptible
%initial geoshow(
Nstep=length(time); S=zeros(1,Nstep); % total number of S, I, R at each time step I=zeros(1,Nstep); R=zeros(1,Nstep); S(1)=length(find(state==0)); I(1)=length(find(state==1)); R(1)=length(find(state==-1));
k=1; for t=dt:dt:t1 k=k+1; th=conv2(double(state>0),ones(3,3),'same'); % count # of infected in neighbor SI_ind=find(rand(size(S_ind))<th(S_ind)*a*dt); IR_ind=find(rand(size(I_ind))<b*dt); state(S_ind(SI_ind))=1; % S -> I state(I_ind(IR_ind))=-1;
S(k)=length(find(state==0));
I(k)=length(find(state==1));
R(k)=length(find(state==-1));
I_ind=find(state==1); % I
set(h1,'xdata',Xgrid(I_ind),'ydata',Ygrid(I_ind));
S_ind=find(state==0); % S
set(h2,'xdata',Xgrid(S_ind),'ydata',Ygrid(S_ind));
R_ind=find(state==-1);% R
set(h3,'xdata',Xgrid(R_ind),'ydata',Ygrid(R_ind));
drawnow;
geoshow(xdata,ydata,'DisplayType',surface)
end
figure; plot(time,[S;I;R])
Thanks!

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!