xxxxxxxxxx
38
const S0 = 8 * (10 ** 6);
const I0 = 10;
const R0 = 0;
const N = S0 + I0 + R0;
const days = 100;
const beta = 1/3;
function calcInfected(alpha) {
let s = S0;
let i = I0;
let r = R0;
for (let t = 1; t <= days; t++) {
const stemp = s;
const itemp = i;
const rtemp = r;
s = stemp - alpha * stemp * itemp;
i = itemp - beta * itemp + alpha * stemp * itemp;
r = N - stemp - itemp;
}
print(s,i,r,alpha*N)
return r+i;
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
for (let k = 0.5; k <= 3; k+=0.1) {
// print(k, calcInfected(k/N))
calcInfected(k/N)
}
noLoop();
}