From 2f85db6f4380f323e769d6111b6976d9346654ef Mon Sep 17 00:00:00 2001 From: Ta180m Date: Tue, 28 Apr 2020 21:39:05 -0500 Subject: Add files via upload --- SARS in Hong Kong.xlsx | Bin 0 -> 8246 bytes sir_model.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 SARS in Hong Kong.xlsx create mode 100644 sir_model.cpp diff --git a/SARS in Hong Kong.xlsx b/SARS in Hong Kong.xlsx new file mode 100644 index 0000000..f53cee9 Binary files /dev/null and b/SARS in Hong Kong.xlsx differ diff --git a/sir_model.cpp b/sir_model.cpp new file mode 100644 index 0000000..f054c36 --- /dev/null +++ b/sir_model.cpp @@ -0,0 +1,48 @@ +#include +#include +using namespace std; + +// Iterations for Euler's method +const int DAYS = 200, ITER = 10000; + +// Population size +const int POP = 2000; + +// Model parameters +// Beta = infection rate +// Gamma = removal rate +const double beta = 0.42, gamma = 0.25; + +// Compartments +double S[DAYS + 1], I[DAYS + 1], R[DAYS + 1]; + +int main() { + // Initial conditions + S[0] = 1 - 1.0 / POP, I[0] = 1.0 / POP, R[0] = 0; + + // Run simulation + for (int i = 0; i < DAYS; ++i) { + double S_[ITER + 1], I_[ITER + 1], R_[ITER + 1]; + + S_[0] = S[i], I_[0] = I[i], R_[0] = R[i]; + + // Euler's method + for (int j = 0; j < ITER; ++j) { + S_[j+1] = S_[j] + (-beta * S_[j] * I_[j]) / ITER; + I_[j+1] = I_[j] + (beta * S_[j] * I_[j] - gamma * I_[j]) / ITER; + R_[j+1] = R_[j] + (gamma * I_[j]) / ITER; + } + + S[i + 1] = S_[ITER], I[i + 1] = I_[ITER], R[i + 1] = R_[ITER]; + } + + // Print results + cout << "| DAY | SUSCEPTIBLE | INFECTIOUS | RECOVERED |\n"; + cout << "-------------------------------------------------\n"; + for (int i = 0; i < DAYS; ++i) { + cout << "| " << setw(3) << i << " | "; // Day + cout << setw(11) << (int)(POP * S[i] + .5) << " | "; // Suspectible + cout << setw(11) << (int)(POP * I[i] + .5) << " | "; // Infectious + cout << setw(11) << (int)(POP * R[i] + .5) << " |\n"; // Recovered + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2