{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

## Notebook of Fun Chapter 2 Things

\n", "

Problem 1 (Stabilization or lack thereof)

\n", "

For our usual measles epidemic, construct a table of approximations for S(13), I(13), R(13) in which nsteps takes the values 10, 100, 1000, 10000, 100000. At each stage, indicate how many digits of S(13), I(13), R(13) have stabilized.

\n", "

Here is some convenient code for you to use... by the way, you can preserve the output from a calculation by copying it and then pasting it into a different cell (either a text cell or an evaluation cell).

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = (fill me in)\n", "stoptime = (fill me in)\n", "nsteps = (fill me in)\n", "S = 45400\n", "I = 2100\n", "R = 2500\n", "t = starttime\n", "deltat = float((stoptime-starttime)/nsteps)\n", "for step in range(nsteps):\n", " S_prime = -.00001*S*I\n", " I_prime = .00001*S*I - I/14\n", " R_prime = I/14\n", " deltaS = S_prime*deltat\n", " deltaI = I_prime*deltat\n", " deltaR = R_prime*deltat\n", " t = t + deltat\n", " S = S + deltaS\n", " I = I + deltaI\n", " R = R + deltaR\n", "print(t,S,I,R)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Problem 2 (Survivors)

\n", "

Let 200 days pass, so t = 200. Determine the values of I(200) and S(200) to one decimal place accuracy by constucting tables of approximations in which you let nsteps increase by powers of 10 (as in Problem 1).  Here's the code again...

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = (fill me in)\n", "stoptime = (fill me in)\n", "nsteps = (fill me in)\n", "S = 45400\n", "I = 2100\n", "R = 2500\n", "t = starttime\n", "deltat = float((stoptime-starttime)/nsteps)\n", "for step in range(nsteps):\n", " S_prime = -.00001*S*I\n", " I_prime = .00001*S*I - I/14\n", " R_prime = I/14\n", " deltaS = S_prime*deltat\n", " deltaI = I_prime*deltat\n", " deltaR = R_prime*deltat\n", " t = t + deltat\n", " S = S + deltaS\n", " I = I + deltaI\n", " R = R + deltaR\n", "print(t,S,I,R)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

How do you interpret the values of S, i and R when nsteps = 10?

\n", "

\n", "

Are there any \"survivors\", that is, susceptibles who never become ill before the illness disappears?  If so, how many are there (measured in a whole number of persons)?  State clearly the evidence on which you base your assertions.  This last part is crucial!

\n", "

\n", "

Was it necessary to go out 200 days to answer this question?  That is, can you argue that the infection disappears in even fewer days?  Or does it take even more than 200 days?

\n", "

\n", "\n", "

Problem 3 (Survivors compared to susceptibles)

\n", "

Do you suspect that having a larger susceptible population will increase or decrease the number of survivors?   What about a smaller susceptible population?

\n", "

Explore how the eventual number of survivors depends on the number of susceptibles at the outset. That is, keep I(0) = 2100 and R(0) = 2500, but vary the number of susceptibles; let S(0) = 4540 and determine the number of survivors, then let S(0) = 20000, and then let S(0) = 80000, and then decide how many and which other values of S(0) to test.

\n", "

" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = (fill me in)\n", "stoptime = (fill me in)\n", "nsteps = (fill me in)\n", "S = (fill me in)\n", "I = 2100\n", "R = 2500\n", "t = starttime\n", "deltat = float((stoptime-starttime)/nsteps)\n", "for step in range(nsteps):\n", " S_prime = -.00001*S*I\n", " I_prime = .00001*S*I - I/14\n", " R_prime = I/14\n", " deltaS = S_prime*deltat\n", " deltaI = I_prime*deltat\n", " deltaR = R_prime*deltat\n", " t = t + deltat\n", " S = S + deltaS\n", " I = I + deltaI\n", " R = R + deltaR\n", "print(t,S,I,R)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Roughly speaking, does the number of survivors depend directly or inversely on the initial number of susceptibles? How does this compare with your earlier conjecture about this question?

\n", "\n", "

Problem 4 (Peak of infection rate)

\n", "

Below is a version of the S-I-R code which will run from starttime to stoptime as long as I_prime is positive. Notice that we have changed the for loop to a while loop, and as a result we had to introduce an iterating variable.   Run the code.

\n", "

" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = 0\n", "stoptime = 10\n", "nsteps = 1000\n", "S = 45400\n", "I = 2100\n", "R = 2500\n", "t = starttime\n", "deltat = float((stoptime-starttime)/nsteps)\n", "I_prime = 1\n", "j = 1\n", "while (j0):\n", " S_prime = -.00001*S*I\n", " I_prime = .00001*S*I - I/14\n", " R_prime = I/14\n", " deltaS = S_prime*deltat\n", " deltaI = I_prime*deltat\n", " deltaR = R_prime*deltat\n", " t = t + deltat\n", " S = S + deltaS\n", " I = I + deltaI\n", " R = R + deltaR\n", " j = j+1\n", "print(t,S,I,R)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Does this tell you when i is at its highest point?  Why or why not?

\n", "

What stopped the code from running?

\n", "

(Hint: there are three possibilities...  (1) j > nsteps (2) I_prime 0 (3) t=10. Which is it?)

\n", "

If this code didn't tell you when I is at its peak, then modify it so it does tell you when i is at its peak.

\n", "

What is the value of i at its peak?  What is the value of S when I is at its peak?

\n", "\n", "

Problem 5 (Epidemic Duration)

\n", "

Here's another copy of the code.  Modify this code to make it show you when the epidemic is over, that is, when the number of infected people is less than 1.  What value of t do you get as the duration of the epidemic?

\n", "

" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = 0\n", "stoptime = 10\n", "nsteps = 1000\n", "S = 45400\n", "I = 2100\n", "R = 2500\n", "t = starttime\n", "deltat = float((stoptime-starttime)/nsteps)\n", "I_prime = 1\n", "j = 1\n", "while (j0):\n", " S_prime = -.00001*S*I\n", " I_prime = .00001*S*I - I/14\n", " R_prime = I/14\n", " deltaS = S_prime*deltat\n", " deltaI = I_prime*deltat\n", " deltaR = R_prime*deltat\n", " t = t + deltat\n", " S = S + deltaS\n", " I = I + deltaI\n", " R = R + deltaR\n", " j = j+1\n", "print(t,S,I,R)" ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 8.0", "language": "", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }