Last active
June 11, 2021 17:40
-
-
Save Quantalabs/54a4c293ab7923af28e319e5985b9a91 to your computer and use it in GitHub Desktop.
Basic SIR Model in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sir (rn, s, i, time, u, p) { | |
data = { | |
S: [s], | |
I: [i], | |
R: [p-(s+i)] | |
} | |
b = rn*u | |
for(i = 0; i < time; i++) { | |
data.S.push(data.S[i]-(b*data.S[i]*data.I[i])/p) // Susceptible | |
data.I.push(data.I[i]+(b*data.S[i]*data.I[i])-(u*data.I[i])/p) // Infected | |
data.R.push(data.R[i]+(u*data.I[i])/p) // Recovered | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment