Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·149 lines (135 loc) · 4.49 KB
/
Copy pathmain.js
File metadata and controls
executable file
·149 lines (135 loc) · 4.49 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Right-hand side of our ODE written as a system of first-order ODEs.
*
* @param objectOfInputs An object containing all the problem parameters.
* @param t Time (seconds).
* @param vars An array of dependent variables.
* @return An array of derivatives.
*/
function f(objectOfInputs, t, vars, dt) {
var [S, I, R] = vars;
var { beta, gamma, delta } = objectOfInputs;
// Determine N
var N = S + I + R;
// Calculate derivatives
var dSdt = - beta * S * I * (1 - delta) / N;
var dIdt = beta * S * I * (1 - delta) / N - gamma * I;
var dRdt = gamma * I;
// Put into return value
return [dt * dSdt, dt * dIdt, dt * dRdt];
}
/**
* Generates a 3D phase plot
*
* @param solution An object containing solution data.
* @return Nothing.
*/
function generateSIRPhasePlot(solution) {
// Extract solution data
var { vars } = solution;
var [S, I, R] = vars;
// Generate 3D plot
gen3DPlot(S, I, R, "phasePlotSIR", "Phase plot of the solution to the SIR equations.", { xtitle: "Susceptible", ytitle: "Infectious", ztitle: "Recovered" });
}
/**
* Generates a SI phase plot
*
* @param solution An object containing solution data.
* @return Nothing.
*/
function generateSIPhasePlot(solution) {
// Extract solution data
var { vars } = solution;
var S = vars[0];
var I = vars[1];
// Generate 2D plot
gen2DPlot(S, I, "phasePlotSI", "Infectious vs susceptible phase plot", "Susceptible", "Infectious")
}
/**
* Generates a SR phase plot
*
* @param solution An object containing solution data.
* @return Nothing.
*/
function generateSRPhasePlot(solution) {
// Extract solution data
var { vars } = solution;
var S = vars[0];
var R = vars[2];
// Generate 2D plot
gen2DPlot(S, R, "phasePlotSR", "Recovered vs susceptible phase plot", "Susceptible", "Recovered");
}
/**
* Generates a IR phase plot
*
* @param solution An object containing solution data.
* @return Nothing.
*/
function generateIRPhasePlot(solution) {
// Extract solution data
var { vars } = solution;
var I = vars[1];
var R = vars[2];
// Generate 2D plot
gen2DPlot(I, R, "phasePlotIR", "Recovered vs infectious phase plot", "Infectious", "Recovered");
}
/**
* Generates a time plot
*
* @param solution An object containing solution data.
* @return Nothing.
*/
function generateTimePlot(solution) {
// Generate time plot
genMultPlot(solution, ["Susceptible", "Infectious", "Recovered"], "timePlot", "Plot of SIR against time");
}
/**
* Generate five plots:
* - The first is a 3D phase plot of S, I and R.
* - The second is a 2D phase plot of I against S.
* - The third is a 2D phase plot of R against S.
* - The fourth is a 2D phase plot of R against I.
* - The fifth is a plot of S, I and R against time.
*
* @param objectOfInputs An object containing all the form parameters.
* @return Nothing. Just generates the plots.
*/
function generatePlots(objectOfInputs = undefined, solution = undefined) {
if (objectOfInputs == undefined) {
var objectOfInputs = readInputs();
}
if (solution == undefined) {
var solution = solveProblem(RKF45, objectOfInputs);
}
// Generate plots
generateSIRPhasePlot(solution);
generateSRPhasePlot(solution);
generateSRPhasePlot(solution);
generateIRPhasePlot(solution);
generateTimePlot(solution);
};
/**
* Generate animation
* @return nothing.
*/
function generateAnimation(objectOfInputs = undefined, solution = undefined) {
if (objectOfInputs == undefined) {
var objectOfInputs = readInputs();
}
if (solution == undefined) {
var solution = solveProblem(RKF45, objectOfInputs);
}
animate3D(solution, { varnames: ["Susceptible", "Infectious", "Recovered"], title: "Susceptible, infectious and recovered population phase plot for the SIR infectious disease model." });
}
function generateTable(objectOfInputs = undefined, solution = undefined) {
if (objectOfInputs == undefined) {
var objectOfInputs = readInputs();
}
if (solution == undefined) {
var solution = solveProblem(RKF45, objectOfInputs);
}
fillTable(objectOfInputs, ['Susceptible', 'Infectious', 'Recovered'], solution)
}
function generateTable(objectOfInputs = undefined, solution = undefined) {
fillTable(objectOfInputs, ['Susceptible', 'Infectious', 'Recovered'], solution)
}