(* Content-type: application/mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 6.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 145, 7]
NotebookDataLength[ 12953, 456]
NotebookOptionsPosition[ 9956, 342]
NotebookOutlinePosition[ 10365, 358]
CellTagsIndexPosition[ 10322, 355]
WindowFrame->Normal
ContainsDynamic->False*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell["The S-I-R Epidemic Model", "Title",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
by
K. D. Stroyan
University of Iowa\
\>", "Subsubtitle",
Evaluatable->False,
AspectRatioFixed->True],
Cell["copyright 2007 by Keith Stroyan - All rights reserved.", "Text",
Evaluatable->False,
CellChangeTimes->{{3.397565813092762*^9, 3.397565820816804*^9}},
AspectRatioFixed->True,
FontFamily->"Times"],
Cell[CellGroupData[{
Cell[" NoteBook Overview", "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
"The purpose of this NoteBook is to show you how to perform basic \
computations of the S-I-R model using ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" and to get some practice editing with the \"mouse.\" A later NoteBook \
will take a more sophisticated \"loop\" approach to the computations. Use \
this NoteBook to check your own calculations from Exercise 2.1.5, check your \
understanding of how ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" works, and practice using the mouse."
}], "Text",
Evaluatable->False],
Cell["\<\
What follows is a partial program that will do the calculations you have \
already done by hand in Exercise 2.1.5. Once you replace the question marks \
with correct expressions and the computatons, you will have a check \
on your work.\
\>", "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell["References to the Text", "Subsection",
Evaluatable->False],
Cell["\<\
This NoteBook compares the hand computations of Exercise 2.1.1 with computer \
calculation. This is Exercise 2.1.5.\
\>", "Text",
Evaluatable->False]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Step-by-step Computation", "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell["The disease-specific parameters:", "Subsubsection",
Evaluatable->False],
Cell["\<\
First we will define the parameters a and b in the cell below. The question \
marks ?? need to be replaced by the correct computation, in this case a = b \
*c.\
\>", "Text",
Evaluatable->False],
Cell["\<\
To replace question marks with a correct expression, position the cursor to \
the right of the question marks, hold down the mouse button, and drag the \
cursor over the question marks. When the question marks are all darkened, \
start typing the correct expression.\
\>", "Text",
Evaluatable->False],
Cell["\<\
When you have eliminated the question marks from this cell, \"compute\" it by \
pressing the key on the number pad or holding and pressing \
the key. \
\>", "Text",
Evaluatable->False],
Cell["\<\
Complete the commands and press for the rate parameters.\
\>", "Text",
Evaluatable->False],
Cell[BoxData[{
RowBox[{"b", "=",
RowBox[{"N", "[",
FractionBox["1", "11"], "]"}]}], "\n",
RowBox[{"c", "=", "6.8"}], "\n",
RowBox[{"a", "=", "??"}]}], "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell["The initial values of the variables:", "Subsubsection",
Evaluatable->False],
Cell["\<\
Now provide Mathematica with the starting values for the number of people in \
the population that are susceptible, infected, and recovered. In the cell \
below we will let sNr denote the number of people susceptible, iNr denote the \
number of people infected, and rNr denote the number of people recovered. We \
let n denote the total population. We will also define a variable t which \
will denote the number of days that have passed. Enter the cell below after \
you have removed the question marks.\
\>", "Text",
Evaluatable->False],
Cell["\<\
We did not use upper case letters S, I, and R for the numbers as in the text, \
because Mathematica reserves some uppercase letters for special things (such \
as I = Sqrt[ -1].) \
\>", "Text",
Evaluatable->False],
Cell["\<\
Complete the commands and press for the initial values.\
\>", "Text",
Evaluatable->False],
Cell[BoxData[{
RowBox[{
RowBox[{"t", "=", "0"}], ";"}], "\n",
RowBox[{
RowBox[{"sNr", "=", "10000"}], ";"}], "\n",
RowBox[{"iNr", "=",
RowBox[{"??", "\n",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"rNr", "=", "19000"}], ";"}], "\n", "n"}], "=",
RowBox[{"sNr", "+", "??"}]}]}]}]}], "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell["The first day:", "Subsubsection",
Evaluatable->False],
Cell["\<\
Remember how you performed the hand calculations for the S-I-R model. First \
you used the above values of \"S\", \"I\" and \"R\" to calculate the change \
in the number of people in each category, and then added the changes to the \
above values to update them. The cell below will perform the calculation in \
the same way. First it computes the changes, then it computes the new \
values. It will also keep track of the day. Enter it when you have \
completed the commands, by typing the formulas from the text in Mathematica \
syntax.\
\>", "Text",
Evaluatable->False],
Cell["\<\
Complete the commands and press for the new values at the start of \
day 2.\
\>", "Text",
Evaluatable->False],
Cell[BoxData[{
RowBox[{
RowBox[{"tChange", " ", "=", " ", "1"}], " ", ";"}], "\n",
RowBox[{
RowBox[{"sChange", " ", "=", " ",
RowBox[{
RowBox[{"-", " ", "a"}], " ",
FractionBox["sNr", "n"], " ", "iNr"}]}], " ", ";"}], "\n",
RowBox[{"iChange", " ", "=", " ",
RowBox[{"a", " ",
FractionBox["sNr", "n"], " ",
RowBox[{"??",
RowBox[{
RowBox[{
RowBox[{"??", " ", "- ???? iNr ;"}], "\n", "rChange"}], " ", "=", " ",
RowBox[{"??",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"??", " ", ";"}], "\n", "\n", "t"}], " ", "=", " ",
RowBox[{"t", " ", "+", " ", "tChange"}]}], " ", ";", "\n",
RowBox[{"sNr", " ", "=", " ",
RowBox[{"sNr", " ", "+", " ", "sChange"}]}], " ", ";", "\n",
RowBox[{"iNr", " ", "=", " ",
RowBox[{"??",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"??", " ", ";"}], "\n", "rNr"}], " ", "=", " ",
RowBox[{"rNr", " ", "+", " ", "rChange"}]}], " ", ";", "\n", "\n",
RowBox[{"Print", "[", " ",
RowBox[{"\"\\"", ",", " ", "t"}], " ", "]"}], " ", ";",
"\n",
RowBox[{"Print", "[", " ", "sNr", " ", "]"}], " ", ";", "\n",
RowBox[{"Print", "[", " ",
RowBox[{"??",
RowBox[{
RowBox[{"??", " ", "] ;"}], "\n",
RowBox[{
RowBox[{"Print", "[", " ", "rNr", " ", "]"}],
";"}]}]}]}]}]}]}]}]}]}]}]}]}]}], "Input"],
Cell["\<\
These results (after ing) should match your own calculations of the \
number susceptible, infected, and recovered after the 1st day of the epidemic \
in the first column of the table in text Exercise 2.1.1. \
\>", "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell["The second day:", "Subsubsection",
Evaluatable->False],
Cell["\<\
To get the values after the 2nd day of the epidemic you could simply enter \
the above cell again since it has updated the values of t, sNr, iNr, and rNr \
already. If you did this, however, the day 2 results above would disappear \
and be replaced by the new results. To avoid losing the above results you \
can make a new cell below that will perform the same calculation.\
\>", "Text",
Evaluatable->False],
Cell[TextData[StyleBox["Here is a quick review of the copy-paste method:",
FontWeight->"Bold"]], "Text",
Evaluatable->False],
Cell["1. First highlight the cell to be copied. ", "Text",
Evaluatable->False],
Cell["\<\
2. Once it is highlighted hit the key and the key (for copy) \
at the same time. Now the computer has a memory of this cell.\
\>", "Text",
Evaluatable->False],
Cell["\<\
3. Now move cursor to where you wish to put the information and click the \
mouse. (There should be a grey line if it is done between existing cells.)\
\>", "Text",
Evaluatable->False],
Cell["\<\
4. Now you are ready to paste by hitting and (for paste) at \
the same time.\
\>", "Text",
Evaluatable->False],
Cell["\<\
Now you can enter the next day's numbers without losing your original work.\
\>", "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell["Subsequent days:", "Subsubsection",
Evaluatable->False],
Cell["\<\
Copy and paste the calculation cell above 2 more times below. Do this to \
practice some more with the mouse, and save all of Mathematica's calculations \
so you can compare them with your own. Enter the computations in sequence \
and compare the results with your hand computations.\
\>", "Text",
Evaluatable->False]
}, Open ]]
}, Open ]],
Cell[CellGroupData[{
Cell["Complete Sample Computation", "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
"See the NoteBook ",
StyleBox["SecondSIR.nb",
FontWeight->"Bold"]
}], "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell["Exercises", "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[" Exercise 2.1.5", "Subsection",
Evaluatable->False],
Cell[TextData[{
"Run the ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" computations above to check the values you computed by hand for the table \
in Exercise 2.1.5."
}], "Text",
Evaluatable->False]
}, Open ]]
}, Open ]]
}, Open ]]
},
WindowSize->{486, 613},
WindowMargins->{{4, Automatic}, {Automatic, 5}},
FrontEndVersion->"6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007)",
StyleDefinitions->FrontEnd`FileName[{"Creative"}, "NaturalColor.nb",
CharacterEncoding -> "UTF-8"]
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[590, 23, 87, 2, 113, "Title",
Evaluatable->False],
Cell[680, 27, 113, 6, 60, "Subsubtitle",
Evaluatable->False],
Cell[796, 35, 204, 4, 26, "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell[1025, 43, 83, 2, 72, "Section",
Evaluatable->False],
Cell[1111, 47, 553, 13, 103, "Text",
Evaluatable->False],
Cell[1667, 62, 290, 6, 65, "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell[1982, 72, 65, 1, 47, "Subsection",
Evaluatable->False],
Cell[2050, 75, 162, 4, 46, "Text",
Evaluatable->False]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[2261, 85, 89, 2, 42, "Section",
Evaluatable->False],
Cell[CellGroupData[{
Cell[2375, 91, 78, 1, 24, "Subsubsection",
Evaluatable->False],
Cell[2456, 94, 207, 5, 56, "Text",
Evaluatable->False],
Cell[2666, 101, 312, 6, 71, "Text",
Evaluatable->False],
Cell[2981, 109, 220, 5, 56, "Text",
Evaluatable->False],
Cell[3204, 116, 109, 3, 41, "Text",
Evaluatable->False],
Cell[3316, 121, 171, 5, 87, "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell[3524, 131, 82, 1, 24, "Subsubsection",
Evaluatable->False],
Cell[3609, 134, 555, 9, 131, "Text",
Evaluatable->False],
Cell[4167, 145, 223, 5, 56, "Text",
Evaluatable->False],
Cell[4393, 152, 108, 3, 20, "Text",
Evaluatable->False],
Cell[4504, 157, 318, 11, 94, "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell[4859, 173, 60, 1, 28, "Subsubsection",
Evaluatable->False],
Cell[4922, 176, 589, 10, 110, "Text",
Evaluatable->False],
Cell[5514, 188, 128, 4, 35, "Text",
Evaluatable->False],
Cell[5645, 194, 1524, 41, 265, "Input"],
Cell[7172, 237, 259, 5, 50, "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell[7468, 247, 61, 1, 28, "Subsubsection",
Evaluatable->False],
Cell[7532, 250, 421, 7, 80, "Text",
Evaluatable->False],
Cell[7956, 259, 127, 2, 20, "Text",
Evaluatable->False],
Cell[8086, 263, 81, 1, 20, "Text",
Evaluatable->False],
Cell[8170, 266, 185, 4, 35, "Text",
Evaluatable->False],
Cell[8358, 272, 196, 4, 35, "Text",
Evaluatable->False],
Cell[8557, 278, 136, 4, 35, "Text",
Evaluatable->False],
Cell[8696, 284, 120, 3, 20, "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell[8853, 292, 62, 1, 28, "Subsubsection",
Evaluatable->False],
Cell[8918, 295, 330, 6, 65, "Text",
Evaluatable->False]
}, Open ]]
}, Open ]],
Cell[CellGroupData[{
Cell[9297, 307, 92, 2, 62, "Section",
Evaluatable->False],
Cell[9392, 311, 118, 5, 20, "Text",
Evaluatable->False]
}, Open ]],
Cell[CellGroupData[{
Cell[9547, 321, 74, 2, 62, "Section",
Evaluatable->False],
Cell[CellGroupData[{
Cell[9646, 327, 58, 1, 42, "Subsection",
Evaluatable->False],
Cell[9707, 330, 209, 7, 35, "Text",
Evaluatable->False]
}, Open ]]
}, Open ]]
}, Open ]]
}
]
*)
(* End of internal cache information *)