-
Notifications
You must be signed in to change notification settings - Fork 0
/
toyspatial.m
59 lines (41 loc) · 1.1 KB
/
toyspatial.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
clear all
close all
N = 100;
beta = 1;
gamma = 1;
b = 1e-2;
mu = b;
dt = 0.1;
tmax = 30;
trange = tmax/dt;
S = round(rand(N,N));
I = zeros(N);
R = I;
one.infec = randsample(find(S==0),1);
I(one.infec) = 1;
%writerObj = VideoWriter('SpatialSIR.gif'); % Name it.
%writerObj.FrameRate = 30; % How many frames per second.
%open(writerObj);
for t=1:trange
colormap('hot')
imagesc(I)
title(['Spatial SIR with Birth - Infected Class, time: ' num2str(t*dt)] )
xlabel('Spatial co-ordinate (x)')
ylabel('Spatial co-ordinate (y)')
caxis([0,1])
colorbar
drawnow
for i=2:(N-1)
for j=2:(N-1)
trans = beta * S(i,j) * (I(i-1,j+1)+I(i-1,j)+I(i-1,j-1)+I(i,j+1)+I(i,j-1)+I(i+1,j+1)+I(i+1,j)+I(i+1,j-1));
infec = gamma * I(i,j);
birth = b * (S(i,j) + I(i,j) + R(i,j));
S(i,j) = S(i,j) + dt*(birth - trans - mu * S(i,j));
I(i,j) = I(i,j) + dt*(trans - infec - mu * I(i,j));
R(i,j) = R(i,j) + dt*(infec - mu * R(i,j));
end
end
%frame = getframe(gcf); % 'gcf' can handle if you zoom in to take a movie.
%writeVideo(writerObj, frame);
end
%close(writerObj); % Saves the movie.