(*********************************************************************** 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[ 14558, 503]*) (*NotebookOutlinePosition[ 15613, 539]*) (* CellTagsIndexPosition[ 15569, 535]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{Cell[TextData["CHAPTER 12"], "Section", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{Cell[TextData["1"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{Cell[TextData["1a"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Define the fitness function, plot it for m2=0.05, and evaluate it for \ m1=0.01, m2=0.05. These calculations establish that when m2=0.05 the optimal \ value of m1 is about 1. Repeating this exercise for different values of m2 \ will show that the optimal value of m1 is 0.01 when m2 > 0.15 and is at an \ internal optimum with m1 round about unity when m2 < 0.05."], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["w[m1_,m2_]:=100(1-Exp[-(m1+m2)^2])/m1"], "Input", AspectRatioFixed->True], Cell[TextData["Plot[w[m1,.05],{m1,.01,2}]"], "Input", AspectRatioFixed->True], Cell[TextData["w[.01,.05]"], "Input", AspectRatioFixed->True], Cell[TextData["We now find the optimal value of m1 when m2=0.01:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "f[m1_,m2_]=D[w[m1,m2],m1];\nFindRoot[f[m1,.01]==0,{m1,1}]"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["1b"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["See Exercise 1a."], "Text", Evaluatable->False, AspectRatioFixed->True]}, Open]]}, Open]], Cell[CellGroupData[{Cell[TextData["2"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "I define the recurrence relation, find the equilibrium values, and the \ stability criteria:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["f[p_]:=(1-s)p(2-p)/(1-s p(2-p))"], "Input", AspectRatioFixed->True], Cell[TextData["equil=Solve[f[p]==p,p]"], "Input", AspectRatioFixed->True], Cell[TextData["Simplify[D[f[p],p]/.equil]"], "Input", AspectRatioFixed->True], Cell[TextData["I simulate the system with s = 0.25:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["s=.25;"], "Input", AspectRatioFixed->True], Cell[TextData["sim=NestList[f,.1,25];"], "Input", AspectRatioFixed->True], Cell[TextData["ListPlot[sim]"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["3"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Define the recurrence relation in Equation 8 and set s = 0.25:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "f[x_]:=(a=x[[1]];b=x[[2]];c=x[[3]];d=x[[4]];\n\t\ty={(1-s)(a-0.5a d+b c),\n\t\ \t(1-s)(b+0.5a d+b d),\n\t\t(c+0.5a d-b c),\n\t\t(d-0.5a d-b d)};\n\t\t\ y/Apply[Plus,y])"], "Input", AspectRatioFixed->True], Cell[TextData["s=0.25;"], "Input", AspectRatioFixed->True], Cell[TextData[ "I first calculate the effect of one round of infection as described in the \ text, and show that after 20 generations virtually all individuals are \ infected but the frequency of uniparental individuals has increased from \ 0.010 to 0.013:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "x={0,0,.01,.99};\nx={.01x[[3]],.01x[[4]],.99x[[3]],.99x[[4]]};\n\ res=NestList[f,x,20];"], "Input", AspectRatioFixed->True], Cell[TextData["res//TableForm"], "Input", AspectRatioFixed->True], Cell[TextData[{ StyleBox["I now write two programs. The first, called ", Evaluatable->False, AspectRatioFixed->True], StyleBox["rep", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[" takes the existing value of ", Evaluatable->False, AspectRatioFixed->True], StyleBox["x", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[" and iterates a further 20 generations. The second one, called ", Evaluatable->False, AspectRatioFixed->True], StyleBox["new", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[ " transfers all the infected individuals to the uninfected class and \ introduces a new infection.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["rep:=(x=Nest[f,x,20])"], "Input", AspectRatioFixed->True], Cell[TextData[ "new:=(x={0,0,x[[1]]+x[[3]],x[[2]]+x[[4]]};\n\ x={.01x[[3]],.01x[[4]],.99x[[3]],.99x[[4]]})\t"], "Input", AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "Start with x={0,0,.01,.99} and simulate the introduction of successive new \ infections by using ", Evaluatable->False, AspectRatioFixed->True], StyleBox["new", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox["; follow each infection by repeatedly using ", Evaluatable->False, AspectRatioFixed->True], StyleBox["rep", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[ " until virtually all individuals are either infected (x1 + x2 = 1) or \ uninfected (x3 + x4 = 1):", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["x={0,0,.01,.99};"], "Input", AspectRatioFixed->True], Cell[TextData["new"], "Input", AspectRatioFixed->True], Cell[TextData["rep"], "Input", AspectRatioFixed->True], Cell[TextData["new"], "Input", AspectRatioFixed->True], Cell[TextData["rep"], "Input", AspectRatioFixed->True], Cell[TextData["and so on."], "Text", Evaluatable->False, AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["4"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["The transition matrix is"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["A={{p/(1-r)+(1-p)/2,1/2},{(1-p)/2,1/2}};"], "Input", AspectRatioFixed->True], Cell[TextData[ "Find its eigenvalues and evaluate them for p = 1 and for p small:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["eigen=Eigenvalues[A];"], "Input", AspectRatioFixed->True], Cell[TextData["PowerExpand[Simplify[eigen/.p->1]]"], "Input", AspectRatioFixed->True], Cell[TextData["PowerExpand[Simplify[Series[eigen,{p,0,1}]]]"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["5"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Define the matrix and evaluate its eigenvalues."], "Text", Evaluatable->False, AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["6"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{Cell[TextData["6a"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Define the Poisson distribution and evaluate it with mean = 15:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Poisson[x_,m_]:=Exp[-m] (m^x)/x!"], "Input", AspectRatioFixed->True], Cell[TextData["Table[{x,10^7 Poisson[x,15.]},{x,0,50}]//TableForm"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["6b"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Define the recursion for ", Evaluatable->False, AspectRatioFixed->True], StyleBox["q[t,a]", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[" from Equations 20 and 21 and evaluate ", Evaluatable->False, AspectRatioFixed->True], StyleBox["q", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[" for the appropriate values of the arguments:", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "q[t_,1]:=q[t,1]=Exp[q[t-1,1]-1]\nq[0,1]=0.0;\nq[t_,a_]:=(q[t,1])^a"], "Input",\ AspectRatioFixed->True], Cell[TextData["Do[q[t,1],{t,2000}]"], "Input", AspectRatioFixed->True], Cell[TextData["tvals={1,2,5,10,20,40,100};"], "Input", AspectRatioFixed->True], Cell[TextData[ "Table[{t=tvals[[i]],q[t,1],q[5t,5],q[10t,10],q[20t,20]},\n\t\t\t\ {i,Length[tvals]}]//TableForm"], "Input", AspectRatioFixed->True]}, Open]]}, Open]], Cell[CellGroupData[{Cell[TextData["7"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox[ "I give some functions for calculating the relative advantage of sex under \ truncation selection. ", Evaluatable->False, AspectRatioFixed->True], StyleBox["mu[lambda,k] ", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox["calculates ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\[Mu]", Evaluatable->False, AspectRatioFixed->True], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[" as a function of", Evaluatable->False, AspectRatioFixed->True], StyleBox[" \[Lambda]", Evaluatable->False, AspectRatioFixed->True], StyleBox[" and k from Equation 12.29.", Evaluatable->False, AspectRatioFixed->True], StyleBox[" sexad[U,k,approx] ", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[ "finds the relative advantage of sex from Equations 12.28, 30 and 31; it \ requires an approximate value for ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\[Lambda]", Evaluatable->False, AspectRatioFixed->True], StyleBox[" which must be obtained first (see example). Use ", Evaluatable->False, AspectRatioFixed->True], StyleBox["sexad", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox[ " to verify the advantage of sex for the parameter values in Table 12.3. \ (The calculations for large values of k are time-consuming.)", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "mu[lambda_,k_]:=\nSum[lambda^i/(i-1)!,{i,k-1}]/Sum[lambda^i/i!,{i,0,k-1}]"], "Input", AspectRatioFixed->True], Cell[TextData[ "sexad[U_,k_,approx_]:=Exp[U-lambda] Sum[lambda^i/i!,\n{i,0,k-1}] /. \ FindRoot[lambda==mu[lambda,k]+U,\n\t{lambda,approx}]"], "Input", AspectRatioFixed->True], Cell[TextData["An example with U = 0.5, k = 5:"], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Plot[x-mu[x,5]-0.5,{x,0.5,5}]"], "Input", AspectRatioFixed->True], Cell[TextData["sexad[0.5,5,2.8]"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["8"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{Cell[TextData["8a"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Use pencil and paper."], "Text", Evaluatable->False, AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["8b"], "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[ "Define the continuous-time transition matrix and find its equilibria and \ their stability criteria in the standard way."], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Clear[f,s]"], "Input", AspectRatioFixed->True], Cell[TextData[ "f[1][s1_,s2_]:=s1((10^-4)(100-s1-s2)-10^-4)/100\n\ f[2][s1_,s2_]:=s2((10^-4)(100-s1-s2)- 2 10^-4)/100"], "Input", AspectRatioFixed->True], Cell[TextData[ "equil=Solve[f[1][s[1],s[2]]==f[2][s[1],s[2]]==0,{s[1],s[2]}]"], "Input", AspectRatioFixed->True], Cell[TextData["jac=Table[D[f[i][s[1],s[2]],s[j]],{i,2},{j,2}];"], "Input", AspectRatioFixed->True], Cell[TextData["Eigenvalues[jac]/.equil//N"], "Input", AspectRatioFixed->True]}, Open]]}, Open]], Cell[CellGroupData[{Cell[TextData["9"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Define ", Evaluatable->False, AspectRatioFixed->True], StyleBox["\[Beta]", Evaluatable->False, AspectRatioFixed->True], StyleBox["(x) and then follow the exercise.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["beta[x_]:=1.582(1-Exp[x-1])"], "Input", AspectRatioFixed->True], Cell[TextData["Plot[beta[1-x],{x,0,1}]"], "Input", AspectRatioFixed->True], Cell[TextData["Plot[x+beta[x],{x,0,1}]"], "Input", AspectRatioFixed->True], Cell[TextData[ "f=(1/x)+(D[beta[x],x]/beta[x]);\nxstar=x/.FindRoot[f==0,{x,.5}]"], "Input", AspectRatioFixed->True], Cell[TextData["beta[xstar]"], "Input", AspectRatioFixed->True]}, Open]], Cell[CellGroupData[{Cell[TextData["10"], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData["Use pencil and paper."], "Text", Evaluatable->False, AspectRatioFixed->True]}, Open]]}, Open]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 640}, {0, 460}}, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{520, 365}, WindowMargins->{{12, Automatic}, {30, Automatic}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False}, MacintoshSystemPageSetup->"\<\ AVU/IFiQKFD000000V:^/09R]g0000000OVaH097bCP0AP1Y06`0I@1^0642HZj` 0V:gT0000001nK500TO9>000000000000000009R[[0000000000000000000000 00000000000000000000000000000000\>" ] (*********************************************************************** 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, 87, 2, 70, "Section", Evaluatable->False], Cell[CellGroupData[{ Cell[1841, 55, 81, 2, 70, "Subsection", Evaluatable->False], Cell[CellGroupData[{ Cell[1945, 59, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[2033, 63, 438, 7, 70, "Text", Evaluatable->False], Cell[2474, 72, 90, 1, 70, "Input"], Cell[2567, 75, 79, 1, 70, "Input"], Cell[2649, 78, 63, 1, 70, "Input"], Cell[2715, 81, 123, 2, 70, "Text", Evaluatable->False], Cell[2841, 85, 111, 2, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[2984, 89, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[3072, 93, 90, 2, 70, "Text", Evaluatable->False] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[3203, 97, 81, 2, 70, "Subsection", Evaluatable->False], Cell[3287, 101, 167, 4, 70, "Text", Evaluatable->False], Cell[3457, 107, 84, 1, 70, "Input"], Cell[3544, 110, 75, 1, 70, "Input"], Cell[3622, 113, 79, 1, 70, "Input"], Cell[3704, 116, 110, 2, 70, "Text", Evaluatable->False], Cell[3817, 120, 59, 1, 70, "Input"], Cell[3879, 123, 75, 1, 70, "Input"], Cell[3957, 126, 66, 1, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[4055, 129, 81, 2, 70, "Subsection", Evaluatable->False], Cell[4139, 133, 137, 3, 70, "Text", Evaluatable->False], Cell[4279, 138, 222, 4, 70, "Input"], Cell[4504, 144, 60, 1, 70, "Input"], Cell[4567, 147, 315, 6, 70, "Text", Evaluatable->False], Cell[4885, 155, 141, 3, 70, "Input"], Cell[5029, 160, 67, 1, 70, "Input"], Cell[5099, 163, 865, 29, 70, "Text", Evaluatable->False], Cell[5967, 194, 74, 1, 70, "Input"], Cell[6044, 197, 146, 3, 70, "Input"], Cell[6193, 202, 712, 24, 70, "Text", Evaluatable->False], Cell[6908, 228, 69, 1, 70, "Input"], Cell[6980, 231, 56, 1, 70, "Input"], Cell[7039, 234, 56, 1, 70, "Input"], Cell[7098, 237, 56, 1, 70, "Input"], Cell[7157, 240, 56, 1, 70, "Input"], Cell[7216, 243, 84, 2, 70, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[7332, 247, 81, 2, 70, "Subsection", Evaluatable->False], Cell[7416, 251, 98, 2, 70, "Text", Evaluatable->False], Cell[7517, 255, 93, 1, 70, "Input"], Cell[7613, 258, 140, 3, 70, "Text", Evaluatable->False], Cell[7756, 263, 74, 1, 70, "Input"], Cell[7833, 266, 87, 1, 70, "Input"], Cell[7923, 269, 97, 1, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8052, 272, 81, 2, 70, "Subsection", Evaluatable->False], Cell[8136, 276, 121, 2, 70, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[8289, 280, 81, 2, 70, "Subsection", Evaluatable->False], Cell[CellGroupData[{ Cell[8393, 284, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[8481, 288, 138, 3, 70, "Text", Evaluatable->False], Cell[8622, 293, 85, 1, 70, "Input"], Cell[8710, 296, 103, 1, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8845, 299, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[8933, 303, 578, 20, 70, "Text", Evaluatable->False], Cell[9514, 325, 122, 3, 70, "Input"], Cell[9639, 330, 72, 1, 70, "Input"], Cell[9714, 333, 80, 1, 70, "Input"], Cell[9797, 336, 149, 3, 70, "Input"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[9987, 341, 81, 2, 70, "Subsection", Evaluatable->False], Cell[10071, 345, 1638, 55, 70, "Text", Evaluatable->False], Cell[11712, 402, 130, 3, 70, "Input"], Cell[11845, 407, 177, 3, 70, "Input"], Cell[12025, 412, 105, 2, 70, "Text", Evaluatable->False], Cell[12133, 416, 82, 1, 70, "Input"], Cell[12218, 419, 69, 1, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[12319, 422, 81, 2, 70, "Subsection", Evaluatable->False], Cell[CellGroupData[{ Cell[12423, 426, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[12511, 430, 95, 2, 70, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[12638, 434, 85, 2, 70, "Subsubsection", Evaluatable->False], Cell[12726, 438, 195, 4, 70, "Text", Evaluatable->False], Cell[12924, 444, 63, 1, 70, "Input"], Cell[12990, 447, 155, 3, 70, "Input"], Cell[13148, 452, 114, 2, 70, "Input"], Cell[13265, 456, 100, 1, 70, "Input"], Cell[13368, 459, 79, 1, 70, "Input"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[13488, 462, 81, 2, 70, "Subsection", Evaluatable->False], Cell[13572, 466, 325, 12, 70, "Text", Evaluatable->False], Cell[13900, 480, 80, 1, 70, "Input"], Cell[13983, 483, 76, 1, 70, "Input"], Cell[14062, 486, 76, 1, 70, "Input"], Cell[14141, 489, 117, 2, 70, "Input"], Cell[14261, 493, 64, 1, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[14357, 496, 82, 2, 70, "Subsection", Evaluatable->False], Cell[14442, 500, 95, 2, 70, "Text", Evaluatable->False] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)