-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQgen.m
63 lines (41 loc) · 1.12 KB
/
Qgen.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
57
58
59
60
61
62
function [q,x] = Qgen(N, beta, gamma)
%QSIR Summary of this function goes here
% Detailed explanation goes here
% X(1): Susceptible
% X(2): Infected
% parameters
% beta - transmission within household
% gamma - recovery of each infected individual
% mu = beta*S*I/(N-1); % infection- logistic growth beta*I*(N-I)/(N-1)
% lambda = gamma*I; % recovery
n = sum(1:N+1); % number of states ordered (0,3),(0,2),(0,1), (0,0),...,(1,2),(1,1),..
q = sparse(n,n);
% Assigning coordinates to states
ss = [];
for i = 0:N
ss = [ss repelem(i,N+1-i)];
end
ii = [];
for i = N:-1:0
ii = [ii i:-1:0];
end
x = [ss;ii]; % [S, I]
% Entering recovery and infection rates into Q
for i = 1:n
if ii(i) > 0
search = x == [ss(i); ii(i)-1];
pos = sum(search) == 2;
q(i,find(pos)) = gamma*ii(i);
end
end
for i=1:n
if ss(i) > 0 && ii(i) % checking that there is someone to be infected and someone to spread the disease
search = x == [ss(i)-1; ii(i)+1];
pos = sum(search)==2;
q(i, find(pos)) = beta*ss(i)*ii(i)/(N-1);
end
end
for i = 1:n
q(i,i) = -sum(q(i,:));
end
end