SIRVALUE
This page runs the SIRVALUE program from the BASIC listing below (see page 65), rewritten in Python. The Python runs right here in your browser, and the table shows whatever the program prints. Edit the code and press Run to update it; Reset brings back the original program.
The model is the same as before: susceptible people become infected at a rate of a × S × I, and infected people recover at a rate of b × I, with a = 0.00001 and b = 1 / 14. What’s new is the goal. Instead of printing a value every day, SIRVALUE estimates S, I and R at a single later time, tfinal = 1. It gets there by splitting the interval from tinitial to tfinal into numberofsteps = 10 equal steps, so deltat = (1 - 0) / 10 = 0.1, and taking one Euler step for each.
Notes from the textbook
Add notes here.
1 DEFDBL A-Z
2 tinitial = 0
3 tfinal = 1
4 t = tinitial
5 S = 45400
6 I = 2100
7 R = 2500
8 numberofsteps = 10
9 deltat = (tfinal - tinitial) / numberofsteps
10 FOR k = 1 TO numberofsteps
11 Sprime = -.00001 * S * I
12 Iprime = .00001 * S * I - I / 14
13 Rprime = I / 14
14 deltaS = Sprime * deltat
15 deltaI = Iprime * deltat
16 deltaR = Rprime * deltat
17 t = t + deltat
18 S = S + deltaS
19 I = I + deltaI
20 R = R + deltaR
21 NEXT k
22 PRINT t, S, I, R
Output table
Each print(...) of numbers becomes a row.
Python code
Press Run (or Ctrl/⌘ + Enter) to update the table. Press Esc, then Tab, to leave the editor.