SIR

In review
Calculates values of S, I, and R.

Do I need to cite the textbook if I pull the first sentence of the description from the textbook?

This page runs the SIR (susceptible, infected, recovered) program from the BASIC listing below, rewritten in Python. The Python runs right here in your browser, and the table and graph show whatever the program prints. Edit the code and press Run to update them; Reset brings back the original program.

The model: each day, susceptible people become infected at a rate of a × S × I, and infected people recover at a rate of b × I. In the program, a = 0.00001 is the transmission coefficient and b = 1 / 14 is the recovery coefficient (an illness lasting about two weeks). The program uses Euler’s method: it computes the rates, multiplies by the time step deltat, and adds the changes to S, I and R.

Notes from the textbook

Add notes here.

 1  t = 0
 2  S = 45400
 3  I = 2100
 4  R = 2500
 5  deltat = 1
 6  PRINT t, S, I, R
 7  FOR k = 1 TO 3
 8          Sprime = -.00001 * S * I
 9          Iprime = .00001 * S * I - I / 14
10          Rprime = I / 14
11          deltaS = Sprime * deltat
12          deltaI = Iprime * deltat
13          deltaR = Rprime * deltat
14          t = t + deltat
15          S = S + deltaS
16          I = I + deltaI
17          R = R + deltaR
18          PRINT t, S, I, R
19  NEXT k

Output table

Each print(...) of numbers becomes a row.

Loading Python. The first run takes a few seconds.
Graph

Straight segments join consecutive printed points, so each curve is piecewise linear. The first number in each row is the horizontal axis.

The graph appears once the program runs.

Python code

Press Run (or Ctrl/⌘ + Enter) to update the table and graph. Press Esc, then Tab, to leave the editor.

Loading Python…