This corresponds to the SIR program that appears on page 44 of the printed text, or p. 50 in the pdf version. (You don't need to understand what this does until we get to that part of the book; for now, you can just use the code and perhaps change a few constants.) But using this code, you can set S, I, R, starting time, ending time, and number of increments within the time interval. It prints out t, S, I, R for every time-step.
{{{id=12| t = 0 S = 45400 I = 2100 R = 2500 deltat = 1 nsteps = 3 for step in range(nsteps): S_prime = -.00001*S*I I_prime = .00001*S*I - I/14 R_prime = I/14 deltaS = S_prime*deltat deltaI = I_prime*deltat deltaR = R_prime*deltat t = t + deltat S = S + deltaS I = I + deltaI R = R + deltaR print(t) print(S) print(I) print(R) /// }}}There are lots of ways to make this code better and more useful, and we'll get to them later. Well, unless you're impatient... let's just make the code a tiny bit better.
First, let's make the output a bit tidier, by placing t, S, I, and R all on one line each time:
{{{id=14| t = 0 S = 45400 I = 2100 R = 2500 deltat = 1 nsteps = 3 for step in range(nsteps): S_prime = -.00001*S*I I_prime = .00001*S*I - I/14 R_prime = I/14 deltaS = S_prime*deltat deltaI = I_prime*deltat deltaR = R_prime*deltat t = t + deltat S = S + deltaS I = I + deltaI R = R + deltaR print(t,S,I,R) /// }}}You could imagine that we might want to look far into the future and see what happens, but not actually print out each intermediate value for t, S, I, and R every time. Let's just print out the last one...
{{{id=15| t = 0 S = 45400 I = 2100 R = 2500 deltat = 1 nsteps = 3 for step in range(nsteps): S_prime = -.00001*S*I I_prime = .00001*S*I - I/14 R_prime = I/14 deltaS = S_prime*deltat deltaI = I_prime*deltat deltaR = R_prime*deltat t = t + deltat S = S + deltaS I = I + deltaI R = R + deltaR print(t,S,I,R) /// }}}Notice how subtle the difference is between this code and the previous code. (Lesson: tabs/spacing matter in Sage!) Can you figure out how the computer is reading these two blocks of code differently? That is, what does the computer see as the difference in meaning?