(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. ***********************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 8631, 230]*) (*NotebookOutlinePosition[ 9526, 261]*) (* CellTagsIndexPosition[ 9482, 257]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData["The S-I-R model, part 1"], "Title", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "The infection spreads from a point source in a one-dimensional space."], "Subtitle", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "The number of susceptibles (at a given time and place) is \"sus\", the \ number of infected is \"inf\", and the number of recovered is \"rec\". The \ domain is the interval 0 <= x <= XM and the time interval is 0 <= t <= TM. \ This sets the boundaries of the domain. However, because we want to look at \ partial derivatives of sus, inf, and rec along the boundary, we extend the \ domain by allowing x = -1, x = XM+1."], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[{ \(XM = 10\ 2; TM = 100; SUS = 100; INF = 5; BET = .01; \), \(dt = .5; ALF = BET - 2\ GAM; GAM = .002; B = 1\/14; \)}], "Input", AspectRatioFixed->True], Cell[TextData[ "First clear the definition of sus, inf, and rec so that any changes we make \ in the parameters will be perceived in the following definitions."], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Clear[sus]; Clear[inf]; Clear[rec]\)], "Input", AspectRatioFixed->True], Cell[TextData[ "Boundary condition: Make the derivative in the x-direction equal to zero \ along the two spatial boundaries. (By the microscope equation, the \ differences z[t, 1, y] - z[t, -1, y] and z[t, XM+1, y] - z[t, XM-1, y]are \ therefore zero. This allows us to define z[t, -1, y] and z[t, XM+1, y] in \ terms of known values of z. Note therefore that these terms must be on the \ left-hand sides of the equations; the expression z[t, 1, y] = z[t, -1, y] \ would _not_ define z[t, -1, y]!)"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Do[sus[t, \(-1\)] = sus[t, 1]; sus[t, XM + 1] = sus[t, XM - 1]; inf[t, \(-1\)] = inf[t, 1]; inf[t, XM + 1] = inf[t, XM - 1]; rec[t, \(-1\)] = rec[t, 1]; rec[t, XM + 1] = rec[t, XM - 1], {t, 0, TM}] \)], "Input", AspectRatioFixed->True], Cell[TextData[ "Initial condition: Set sus = SUS (a constant) on the x-axis when t = 0; set \ inf = 0 except at one point; set rec = 0 everywhere. Note that the total \ number of susceptibles over the whole x-axis is then SUS * (XM+1)."], "Text",\ Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[{ \(\(Do[sus[0, x] = SUS; inf[0, x] = 0; rec[0, x] = 0, {x, \(-1\), XM + 1}]; \)\), \(\(inf[0, XM\/2] = INF; \)\)}], "Input", AspectRatioFixed->True], Cell[TextData[ "Iteration: Compute the next z-value using the discrete versions of the \ PDEs."], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[BoxData[ \(Do[sus[t, x] = N[sus[t - 1, x] - dt\ sus[t - 1, x]\ \((ALF\ inf[t - 1, x] + GAM\ \((inf[t - 1, x + 1] + inf[t - 1, x - 1])\))\)]; inf[t, x] = N[\((1 - B\ dt)\)\ inf[t - 1, x] + dt\ sus[t - 1, x]\ \((ALF\ inf[t - 1, x] + GAM\ \((inf[t - 1, x + 1] + inf[t - 1, x - 1])\))\)]; rec[t, x] = N[rec[t - 1, x] + B\ dt\ inf[t - 1, x]], {t, 1, TM}, {x, 0, XM}]\)], "Input", AspectRatioFixed->True], Cell["\<\ The next three commands are used to check that the three functions \ have been succesfully generated. They are not ordinarily executed.\ \>", "Text"], Cell[BoxData[ \(\(Table[inf[t, x], {t, 0, TM}, {x, 0, XM}]; \)\)], "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(Table[sus[t, x], {t, 0, TM}, {x, 0, XM}]; \)\)], "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(Table[rec[t, x], {t, 0, TM}, {x, 0, XM}]; \)\)], "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(ListPlot3D[Table[sus[t, x], {t, 0, TM}, {x, 0, XM}], PlotRange \[Rule] {\(-10\), 100}, ViewPoint \[Rule] {2, 1, 2}, BoxRatios \[Rule] {1, 2, .8}]; \)\)], "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(ListPlot3D[Table[inf[t, x], {t, 0, TM}, {x, 0, XM}], PlotRange \[Rule] {0, 100}, ViewPoint \[Rule] {2, 1, 2}, BoxRatios \[Rule] {1, 2, .8}]; \)\)], "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(ListPlot3D[Table[rec[t, x], {t, 0, TM}, {x, 0, XM}], PlotRange \[Rule] {0, 100}, ViewPoint \[Rule] {2, 1, 2}, BoxRatios \[Rule] {1, 2, .8}]; \)\)], "Input", AspectRatioFixed->True], Cell["\<\ This command produces a 100-cell animation. The horizontal axis is \ position. The animation shows the infection (in red) growing at the center \ and propagating to the sides. The susceptible population (in blue) drops in \ the center and then toward the sides.\ \>", "Text"], Cell[BoxData[ \(\(Table[ Show[{ListPlot[ \(Table[inf[t, x], {t, 0, TM}, {x, 0, XM}]\)\[LeftDoubleBracket]k \[RightDoubleBracket], PlotRange \[Rule] {0, 100}, PlotLabel \[Rule] k, PlotStyle \[Rule] {RGBColor[1, 0, 0], Thickness[.01]}, PlotJoined \[Rule] True, DisplayFunction \[Rule] Identity], ListPlot[ \(Table[sus[t, x], {t, 0, TM}, {x, 0, XM}]\)\[LeftDoubleBracket]k \[RightDoubleBracket], PlotRange \[Rule] {0, 100}, PlotLabel \[Rule] k, PlotStyle \[Rule] {RGBColor[0, .5, 1], Thickness[.01]}, PlotJoined \[Rule] True, DisplayFunction \[Rule] Identity], ListPlot[ \(Table[rec[t, x], {t, 0, TM}, {x, 0, XM}]\)\[LeftDoubleBracket]k \[RightDoubleBracket], PlotRange \[Rule] {0, 100}, PlotLabel \[Rule] k, PlotStyle \[Rule] {RGBColor[0, 1, .2], Thickness[.01]}, PlotJoined \[Rule] True, DisplayFunction \[Rule] Identity]}, DisplayFunction \[Rule] $DisplayFunction], {k, 1, TM}]; \)\)], "Input",\ AspectRatioFixed->True], Cell["\<\ Here the horizontal axis is time; the plot shows how the numbers of \ susceptibles (blue), infected (red), and recovered (green) vary over time at \ the center.\ \>", "Text"], Cell[BoxData[ \(\(Show[{ ListPlot[Table[inf[t, XM\/2], {t, 0, TM}], PlotRange \[Rule] {0, 100}, PlotJoined \[Rule] True, PlotStyle \[Rule] {RGBColor[1, 0, 0], Thickness[.01]}, DisplayFunction \[Rule] Identity], ListPlot[Table[sus[t, XM\/2], {t, 0, TM}], PlotRange \[Rule] {0, 100}, PlotJoined \[Rule] True, PlotStyle \[Rule] {RGBColor[0, .5, 1], Thickness[.01]}, DisplayFunction \[Rule] Identity], ListPlot[Table[rec[t, XM\/2], {t, 0, TM}], PlotRange \[Rule] {0, 100}, PlotJoined \[Rule] True, PlotStyle \[Rule] {RGBColor[0, 1, .2], Thickness[.01]}, DisplayFunction \[Rule] Identity]}, DisplayFunction \[Rule] $DisplayFunction]; \)\)], "Input", AspectRatioFixed->True] }, Open ]] }, FrontEndVersion->"X 3.0", ScreenRectangle->{{0, 1280}, {0, 1024}}, WindowToolbars->{}, CellGrouping->Automatic, WindowSize->{520, 600}, WindowMargins->{{172, Automatic}, {Automatic, 77}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, 128}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, CharacterEncoding->"XAutomaticEncoding" ] (*********************************************************************** Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. ***********************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1731, 51, 98, 2, 107, "Title"], Cell[1832, 55, 151, 4, 83, "Subtitle"], Cell[1986, 61, 496, 8, 104, "Text"], Cell[2485, 71, 177, 3, 62, "Input"], Cell[2665, 76, 218, 4, 50, "Text"], Cell[2886, 82, 93, 2, 27, "Input"], Cell[2982, 86, 559, 9, 104, "Text"], Cell[3544, 97, 277, 5, 59, "Input"], Cell[3824, 104, 298, 6, 68, "Text"], Cell[4125, 112, 180, 4, 61, "Input"], Cell[4308, 118, 153, 4, 32, "Text"], Cell[4464, 124, 544, 13, 107, "Input"], Cell[5011, 139, 163, 4, 50, "Text"], Cell[5177, 145, 105, 2, 27, "Input"], Cell[5285, 149, 105, 2, 27, "Input"], Cell[5393, 153, 105, 2, 27, "Input"], Cell[5501, 157, 224, 4, 59, "Input"], Cell[5728, 163, 218, 4, 59, "Input"], Cell[5949, 169, 218, 4, 59, "Input"], Cell[6170, 175, 288, 5, 68, "Text"], Cell[6461, 182, 1158, 22, 235, "Input"], Cell[7622, 206, 184, 4, 50, "Text"], Cell[7809, 212, 806, 15, 289, "Input"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)