(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 13.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 64116, 1696] NotebookOptionsPosition[ 62942, 1665] NotebookOutlinePosition[ 63424, 1683] CellTagsIndexPosition[ 63381, 1680] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["\<\ The evolution of condition-dependent self-fertilisation with a fixed inbreeding depression component\ \>", "Title", CellChangeTimes->{{3.960434881926375*^9, 3.960434894760737*^9}, { 3.987820791194696*^9, 3.987820797542747*^9}},ExpressionUUID->"5e2c2e28-c3e8-4407-bc37-\ 5defd94dfc69"], Cell["\<\ Thomas Lesaffre John Pannell Charles Mullon Last updated May 15th, 2026.\ \>", "Text", CellChangeTimes->{{3.960434903302127*^9, 3.960434986824787*^9}, { 3.9606071424122868`*^9, 3.960607148467173*^9}, {3.965612279924382*^9, 3.965612297230742*^9}, {3.987820801421797*^9, 3.987820805601878*^9}},ExpressionUUID->"c6ef5d3c-f525-46e3-8246-\ 64a09bde5e0e"], Cell[CellGroupData[{ Cell["Definitions and initialisation", "Section", CellChangeTimes->{{3.960435005982473*^9, 3.960435023868626*^9}},ExpressionUUID->"bfa7063b-a507-4317-96d3-\ 49dc05e6d5c4"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Zm", "=", RowBox[{"{", RowBox[{"\[Alpha]AAm", ",", "\[Alpha]Aam", ",", "\[Alpha]aam"}], "}"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Mutant", " ", RowBox[{"haplotype", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Z", "=", RowBox[{"{", RowBox[{"\[Alpha]AA", ",", "\[Alpha]Aa", ",", "\[Alpha]aa"}], "}"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Resident", " ", RowBox[{"haplotype", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "Condition"}], " ", "depending", " ", "on", " ", "genotype", " ", "at", " ", "condition", " ", RowBox[{"locus", "."}]}], " ", "**)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"wAA", "=", "1"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"wAa", "=", RowBox[{"1", "-", RowBox[{"s", " ", "h"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"waa", "=", RowBox[{"1", "-", "s"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"wbar", "=", RowBox[{ RowBox[{"wAA", " ", "qAA"}], "+", RowBox[{"wAa", " ", "qAa"}], "+", RowBox[{"waa", " ", "qaa"}]}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Mean", " ", RowBox[{"condition", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "Resident"}], " ", "pollen", " ", "types"}], " ", "***)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "*", " ", "Haplotype", " ", "frequencies", " ", "before", " ", "mutation"}], "..."}], " ", "**)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PAMbef", "=", FractionBox[ RowBox[{ RowBox[{"wAA", " ", "qAA"}], "+", RowBox[{ FractionBox["wAa", "2"], "qAa"}]}], "wbar"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"PaMbef", "=", FractionBox[ RowBox[{ RowBox[{"waa", " ", "qaa"}], "+", RowBox[{ FractionBox["wAa", "2"], "qAa"}]}], "wbar"]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"*", " ", "..."}], " ", "after", " ", RowBox[{"mutation", "."}]}], " ", "**)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PAM", " ", "=", " ", RowBox[{ RowBox[{"PAMbef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", RowBox[{"\[Mu]a", " ", "PaMbef"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"PaM", " ", "=", " ", RowBox[{ RowBox[{"PaMbef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}], "+", RowBox[{"\[Mu]A", " ", "PAMbef"}]}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "Resident"}], " ", "outcross", " ", "ovule", " ", "types"}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FAMbef", "=", RowBox[{ RowBox[{"qAA", " ", "F0", " ", "wAA", " ", RowBox[{"(", RowBox[{"1", "-", " ", "\[Alpha]AA"}], ")"}]}], " ", "+", " ", RowBox[{ FractionBox["qAa", "2"], "F0", " ", "wAa", " ", RowBox[{"(", RowBox[{"1", "-", "\[Alpha]Aa"}], ")"}]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"FaMbef", "=", RowBox[{ RowBox[{"qaa", " ", "F0", " ", "waa", " ", RowBox[{"(", RowBox[{"1", "-", " ", "\[Alpha]aa"}], ")"}]}], " ", "+", " ", RowBox[{ FractionBox["qAa", "2"], "F0", " ", "wAa", " ", RowBox[{"(", RowBox[{"1", "-", " ", "\[Alpha]Aa"}], ")"}]}]}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FAM", " ", "=", " ", RowBox[{ RowBox[{"FAMbef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], " ", "+", " ", RowBox[{"\[Mu]a", " ", "FaMbef"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"FaM", " ", "=", " ", RowBox[{ RowBox[{"FaMbef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}], "+", " ", RowBox[{"\[Mu]A", " ", "FAMbef"}]}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "Mutant"}], " ", "contributions"}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w1i", " ", "=", RowBox[{ RowBox[{"F0", " ", "w", " ", RowBox[{"(", RowBox[{ RowBox[{"2", "\[Alpha]", " ", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], "gAM", " ", "gAm"}], " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]"}], ")"}], "gAm", " ", "PAM"}]}], ")"}]}], "+", RowBox[{"FAM", " ", "gAm", " ", FractionBox["w", "wbar"]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w2i", " ", "=", " ", RowBox[{ RowBox[{"F0", " ", "w", RowBox[{"(", RowBox[{ RowBox[{"2", "\[Alpha]", " ", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], "gAM", " ", "gam"}], "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]"}], ")"}], "gam", " ", "PAM"}]}], ")"}]}], " ", "+", " ", RowBox[{"FAM", " ", "gam", FractionBox["w", "wbar"]}]}]}], ";"}], " "}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w3i", " ", "=", RowBox[{ RowBox[{"F0", " ", "w", RowBox[{"(", RowBox[{ RowBox[{"2", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gAm", " ", "gaM"}], " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ", "gAm", " ", "PaM"}]}], ")"}]}], " ", "+", " ", RowBox[{"FaM", " ", "gAm", FractionBox["w", "wbar"]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w4i", " ", "=", " ", RowBox[{ RowBox[{"F0", " ", "w", RowBox[{"(", RowBox[{ RowBox[{"2", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gaM", " ", "gam"}], "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]"}], ")"}], "gam", " ", "PaM"}]}], ")"}]}], "+", RowBox[{"FaM", " ", "gam", " ", FractionBox["w", "wbar"]}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w5i", " ", "=", RowBox[{"F0", " ", "w", " ", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gAm", " ", "gAm"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w6i", " ", "=", RowBox[{"F0", " ", "w", " ", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gAm", " ", "gam"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"w7i", "=", RowBox[{"F0", " ", "w", " ", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gam", " ", "gAm"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w8i", " ", "=", RowBox[{"F0", " ", "w", " ", "\[Alpha]", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "gam", " ", "gam"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww", " ", "=", " ", RowBox[{"{", RowBox[{ "w1i", ",", "w2i", ",", "w3i", ",", "w4i", ",", "w5i", ",", "w6i", ",", "w7i", ",", "w8i"}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "1"}], ":", " ", RowBox[{ RowBox[{"AM", "/", "Am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "**)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Haplotype", " ", "frequencies", " ", "in", " ", "gametes"}], " ", "*)"}], "\n"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM1", " ", "=", " ", FractionBox[ RowBox[{"1", "-", "\[Mu]A"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM1", " ", "=", " ", FractionBox["\[Mu]A", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm1", " ", "=", " ", FractionBox[ RowBox[{"1", "-", "\[Mu]A"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam1", " ", "=", " ", FractionBox["\[Mu]A", "2"]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Selfing", " ", "rate", " ", "and", " ", "condition"}], " ", "*)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]1", " ", "=", " ", FractionBox[ RowBox[{"\[Alpha]AA", "+", "\[Alpha]AAm"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w1", " ", "=", " ", "wAA"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep1", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w1"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]1"}], ",", " ", RowBox[{"gAM", "->", "gAM1"}], ",", " ", RowBox[{"gaM", "->", "gaM1"}], ",", " ", RowBox[{"gAm", "->", "gAm1"}], ",", " ", RowBox[{"gam", "->", "gam1"}]}], "}"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Replacement", " ", "rule"}], " ", "*)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww1", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep1"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "2"}], ":", " ", RowBox[{ RowBox[{"AM", "/", "am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\n"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM2", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", " ", RowBox[{"r", " ", "\[Mu]a"}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM2", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], "\[Mu]A"}], "+", RowBox[{"r", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm2", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{"r", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], "\[Mu]a"}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam2", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{"r", " ", "\[Mu]A"}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}]}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]2", " ", "=", " ", FractionBox[ RowBox[{"\[Alpha]Aa", "+", "\[Alpha]Aam"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w2", " ", "=", " ", "wAa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep2", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w2"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]2"}], ",", " ", RowBox[{"gAM", "->", "gAM2"}], ",", " ", RowBox[{"gaM", "->", "gaM2"}], ",", " ", RowBox[{"gAm", "->", "gAm2"}], ",", " ", RowBox[{"gam", "->", "gam2"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww2", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep2"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "3"}], ":", " ", RowBox[{ RowBox[{"Am", "/", "aM"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM3", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{"r", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], "\[Mu]a"}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM3", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{"r", " ", "\[Mu]A"}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm3", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", RowBox[{"r", " ", "\[Mu]a"}]}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam3", " ", "=", " ", FractionBox[ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "r"}], ")"}], "\[Mu]A"}], "+", RowBox[{"r", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}]}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]3", " ", "=", " ", FractionBox[ RowBox[{"\[Alpha]Aa", "+", "\[Alpha]Aam"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w3", " ", "=", " ", "wAa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep3", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w3"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]3"}], ",", " ", RowBox[{"gAM", "->", "gAM3"}], ",", " ", RowBox[{"gaM", "->", "gaM3"}], ",", " ", RowBox[{"gAm", "->", "gAm3"}], ",", " ", RowBox[{"gam", "->", "gam3"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww3", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep3"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "4"}], ":", " ", RowBox[{ RowBox[{"aM", "/", "am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM4", " ", "=", " ", FractionBox["\[Mu]a", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM4", " ", "=", " ", FractionBox[ RowBox[{"1", "-", "\[Mu]a"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm4", " ", "=", " ", FractionBox["\[Mu]a", "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam4", " ", "=", " ", FractionBox[ RowBox[{"1", "-", "\[Mu]a"}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]4", " ", "=", " ", FractionBox[ RowBox[{"\[Alpha]aa", "+", "\[Alpha]aam"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w4", " ", "=", " ", "waa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep4", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w4"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]4"}], ",", " ", RowBox[{"gAM", "->", "gAM4"}], ",", " ", RowBox[{"gaM", "->", "gaM4"}], ",", " ", RowBox[{"gAm", "->", "gAm4"}], ",", " ", RowBox[{"gam", "->", "gam4"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww4", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep4"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\t", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "5"}], ":", " ", RowBox[{ RowBox[{"Am", "/", "Am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM5", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM5", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm5", " ", "=", " ", RowBox[{"1", "-", "\[Mu]A"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam5", " ", "=", " ", "\[Mu]A"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]5", " ", "=", " ", "\[Alpha]AAm"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w5", " ", "=", " ", "wAA"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep5", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w5"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]5"}], ",", " ", RowBox[{"gAM", "->", "gAM5"}], ",", " ", RowBox[{"gaM", "->", "gaM5"}], ",", " ", RowBox[{"gAm", "->", "gAm5"}], ",", " ", RowBox[{"gam", "->", "gam5"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww5", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep5"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\n", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "6"}], ":", " ", RowBox[{ RowBox[{"Am", "/", "am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM6", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM6", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm6", " ", "=", " ", FractionBox[ RowBox[{"\[Mu]a", "+", "1", "-", "\[Mu]A"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam6", " ", "=", " ", FractionBox[ RowBox[{"\[Mu]A", "+", "1", "-", "\[Mu]a"}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]6", " ", "=", " ", "\[Alpha]Aam"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w6", " ", "=", " ", "wAa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep6", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w6"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]6"}], ",", " ", RowBox[{"gAM", "->", "gAM6"}], ",", " ", RowBox[{"gaM", "->", "gaM6"}], ",", " ", RowBox[{"gAm", "->", "gAm6"}], ",", " ", RowBox[{"gam", "->", "gam6"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww6", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep6"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "7"}], ":", " ", RowBox[{ RowBox[{"am", "/", "Am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM7", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM7", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm7", " ", "=", " ", FractionBox[ RowBox[{"\[Mu]a", "+", "1", "-", "\[Mu]A"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam7", " ", "=", " ", FractionBox[ RowBox[{"\[Mu]A", "+", "1", "-", "\[Mu]a"}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]7", " ", "=", " ", "\[Alpha]Aam"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w7", " ", "=", " ", "wAa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep7", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w7"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]7"}], ",", " ", RowBox[{"gAM", "->", "gAM7"}], ",", " ", RowBox[{"gaM", "->", "gaM7"}], ",", " ", RowBox[{"gAm", "->", "gAm7"}], ",", " ", RowBox[{"gam", "->", "gam7"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww7", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep7"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"**", " ", "Class"}], " ", "8"}], ":", " ", RowBox[{ RowBox[{"am", "/", "am"}], " ", "focal", " ", RowBox[{"mutant", "."}]}]}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAM8", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gaM8", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gAm8", " ", "=", " ", "\[Mu]a"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"gam8", " ", "=", " ", RowBox[{"1", "-", "\[Mu]a"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[Alpha]8", " ", "=", " ", "\[Alpha]aam"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"w8", " ", "=", " ", "waa"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"rep8", "=", RowBox[{"{", RowBox[{ RowBox[{"w", "->", "w8"}], ",", " ", RowBox[{"\[Alpha]", "->", " ", "\[Alpha]8"}], ",", " ", RowBox[{"gAM", "->", "gAM8"}], ",", " ", RowBox[{"gaM", "->", "gaM8"}], ",", " ", RowBox[{"gAm", "->", "gAm8"}], ",", " ", RowBox[{"gam", "->", "gam8"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Ww8", " ", "=", " ", RowBox[{"Ww", "/.", " ", "rep8"}]}], ";"}], RowBox[{"(*", " ", RowBox[{"Mutant", " ", "offspring", " ", RowBox[{"produced", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", "**", " ", "Replacement"}], " ", "rules"}], " ", "*****)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"WeakSel", "=", RowBox[{"{", RowBox[{ RowBox[{"\[Mu]A", "->", RowBox[{"\[Mu]A", " ", SuperscriptBox["\[Epsilon]", "2"]}]}], ",", " ", RowBox[{"s", "->", RowBox[{"s", " ", "\[Epsilon]"}]}], ",", " ", RowBox[{"\[Mu]a", "->", RowBox[{"\[Mu]a", " ", SuperscriptBox["\[Epsilon]", "2"]}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PFdec", "=", RowBox[{"{", RowBox[{ RowBox[{"p", "->", RowBox[{"p0", "+", RowBox[{"\[Epsilon]", " ", "p1"}], "+", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "2"], "2"], "p2"}], "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "3"], "6"], "p3"}]}]}], ",", " ", RowBox[{"Cc", "->", RowBox[{"C0", "+", RowBox[{"\[Epsilon]", " ", "C1"}], "+", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "2"], "2"], "C2"}], "+", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "3"], "6"], "C3"}]}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Gen", " ", "=", " ", RowBox[{"{", RowBox[{ RowBox[{"fAA", "->", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{"1", "-", "p"}], ")"}], "2"], "+", "Cc"}]}], ",", " ", RowBox[{"fAa", "->", " ", RowBox[{ RowBox[{"2", "p", RowBox[{"(", RowBox[{"1", "-", "p"}], ")"}]}], "-", RowBox[{"2", " ", "Cc"}]}]}], ",", " ", RowBox[{"faa", "->", RowBox[{ SuperscriptBox["p", "2"], "+", "Cc"}]}], ",", RowBox[{"qAA", "->", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{"1", "-", "p"}], ")"}], "2"], "+", "Cc"}]}], ",", RowBox[{"qAa", "->", " ", RowBox[{ RowBox[{"2", "p", RowBox[{"(", RowBox[{"1", "-", "p"}], ")"}]}], "-", RowBox[{"2", " ", "Cc"}]}]}], ",", RowBox[{"qaa", "->", RowBox[{ SuperscriptBox["p", "2"], "+", "Cc"}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GenDec", "=", RowBox[{"{", RowBox[{ RowBox[{"fAA", "->", RowBox[{"fAA0", "+", RowBox[{"\[Epsilon]", " ", "fAA1"}], "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "2"], "2"], "fAA2"}], " ", "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "3"], "6"], "fAA3"}]}]}], ",", RowBox[{"fAa", "->", RowBox[{"fAa0", "+", RowBox[{"\[Epsilon]", " ", "fAa1"}], "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "2"], "2"], "fAa2"}], " ", "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "3"], "6"], "fAa3"}]}]}], ",", RowBox[{"faa", "->", RowBox[{"faa0", "+", RowBox[{"\[Epsilon]", " ", "faa1"}], "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "2"], "2"], "faa2"}], " ", "+", " ", RowBox[{ FractionBox[ SuperscriptBox["\[Epsilon]", "3"], "6"], "faa3"}]}]}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"mono", " ", "=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]AAm", "->", "\[Alpha]AA"}], ",", " ", RowBox[{"\[Alpha]Aam", "->", "\[Alpha]Aa"}], ",", " ", RowBox[{"\[Alpha]aam", "->", "\[Alpha]aa"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"NoCondDep", " ", "=", " ", RowBox[{"{", RowBox[{ RowBox[{"\[Alpha]AA", "->", "\[Alpha]"}], ",", " ", RowBox[{"\[Alpha]Aa", "->", "\[Alpha]"}], ",", " ", RowBox[{"\[Alpha]aa", "->", "\[Alpha]"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", "**", " ", "Invasion"}], " ", "matrix"}], " ", "*****)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"W", "=", " ", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "/", RowBox[{"(", RowBox[{"F0", " ", RowBox[{"(", RowBox[{ RowBox[{"qAA", " ", "wAA", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]AA", " ", "\[Delta]"}]}], ")"}]}], "+", RowBox[{"qAa", " ", "wAa", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]Aa", " ", "\[Delta]"}]}], ")"}]}], "+", RowBox[{"qaa", " ", "waa", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]aa", " ", "\[Delta]"}]}], ")"}]}]}], ")"}]}], ")"}]}], ")"}], RowBox[{"{", RowBox[{ "Ww1", ",", "Ww2", ",", "Ww3", ",", "Ww4", ",", "Ww5", ",", "Ww6", ",", "Ww7", ",", "Ww8"}], "}"}]}], " ", "//", " ", "Transpose"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Wneut", " ", "=", " ", RowBox[{"W", "/.", "mono"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"Invasion", " ", "matrix", " ", "under", " ", "neutrality"}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"*", " ", "Matrices", " ", "of", " ", "class"}], "-", RowBox[{"specific", " ", "effects"}]}], " ", "**)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"DAA", "=", RowBox[{ RowBox[{"D", "[", RowBox[{"W", ",", "\[Alpha]AAm"}], "]"}], "/.", "mono"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"DAa", "=", RowBox[{ RowBox[{"D", "[", RowBox[{"W", ",", "\[Alpha]Aam"}], "]"}], "/.", "mono"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Daa", "=", RowBox[{ RowBox[{"D", "[", RowBox[{"W", ",", "\[Alpha]aam"}], "]"}], "/.", "mono"}]}], ";"}], "\[IndentingNewLine]", "\n", RowBox[{"(*", RowBox[{ RowBox[{"**", "**", " ", "Genetic"}], " ", "dynamics", " ", "at", " ", "condition", " ", "locus", " ", "in", " ", "resident", " ", RowBox[{"population", "."}]}], " ", "*****)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PAfBef", "=", FractionBox[ RowBox[{ RowBox[{"fAA", " ", "wAA"}], "+", RowBox[{"fAa", " ", FractionBox["wAa", "2"]}]}], RowBox[{ RowBox[{"fAA", " ", "wAA"}], "+", RowBox[{"fAa", " ", "wAa"}], " ", "+", " ", RowBox[{"faa", " ", "waa"}]}]]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"PafBef", "=", FractionBox[ RowBox[{ RowBox[{"faa", " ", "waa"}], "+", RowBox[{"fAa", " ", FractionBox["wAa", "2"]}]}], RowBox[{ RowBox[{"fAA", " ", "wAA"}], "+", RowBox[{"fAa", " ", "wAa"}], " ", "+", " ", RowBox[{"faa", " ", "waa"}]}]]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PAf", " ", "=", " ", RowBox[{ RowBox[{"PAfBef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}]}], "+", RowBox[{"PafBef", " ", "\[Mu]a"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Paf", " ", "=", " ", RowBox[{ RowBox[{"PafBef", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}]}], "+", RowBox[{"PAfBef", " ", "\[Mu]A"}]}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Wfbar", "=", " ", RowBox[{ RowBox[{"fAA", " ", "wAA", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]AA", " ", "\[Delta]"}]}], ")"}]}], "+", RowBox[{"fAa", " ", "wAa", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]Aa", " ", "\[Delta]"}]}], ")"}]}], "+", RowBox[{"faa", " ", "waa", RowBox[{"(", RowBox[{"1", "-", RowBox[{"\[Alpha]aa", " ", "\[Delta]"}]}], ")"}]}]}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"pAhet", " ", "=", " ", FractionBox[ RowBox[{"1", "-", "\[Mu]A", "+", "\[Mu]a"}], "2"]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"pahet", "=", FractionBox[ RowBox[{"1", "-", "\[Mu]a", "+", "\[Mu]A"}], "2"]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"fAANext", "=", " ", RowBox[{ FractionBox["1", "Wfbar"], RowBox[{"(", RowBox[{ RowBox[{"fAA", " ", "wAA", " ", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]AA", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], SuperscriptBox[ RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}], "2"]}], "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]AA"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}], " ", "PAf"}]}], ")"}]}], " ", "+", " ", RowBox[{"fAa", " ", "wAa", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]Aa", " ", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", "pAhet", " ", "pAhet"}], " ", "+", " ", RowBox[{"pAhet", " ", RowBox[{"(", RowBox[{"1", "-", "\[Alpha]Aa"}], ")"}], " ", "PAf"}]}], ")"}]}], " ", "+", " ", RowBox[{"faa", " ", "waa", " ", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]aa", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", SuperscriptBox["\[Mu]a", "2"]}], "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]aa"}], ")"}], " ", "\[Mu]a", " ", "PAf"}]}], ")"}]}]}], ")"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"fAaNext", " ", "=", RowBox[{ FractionBox["1", "Wfbar"], RowBox[{"(", RowBox[{ RowBox[{"fAA", " ", "wAA", RowBox[{"(", RowBox[{ RowBox[{"2", " ", "\[Mu]A", RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}], "\[Alpha]AA", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}]}], " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]AA"}], ")"}], RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Mu]A"}], ")"}], "Paf"}], " ", "+", " ", RowBox[{"\[Mu]A", " ", "PAf"}]}], ")"}]}]}], ")"}]}], "+", " ", RowBox[{"fAa", " ", "wAa", " ", RowBox[{"(", RowBox[{ RowBox[{"2", " ", "\[Alpha]Aa", " ", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], "pAhet", " ", "pahet"}], " ", "+", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]Aa"}], ")"}], " ", RowBox[{"(", RowBox[{ RowBox[{"pAhet", " ", "Paf"}], "+", RowBox[{"pahet", " ", "PAf"}]}], ")"}]}]}], ")"}]}], "+", " ", RowBox[{"faa", " ", "waa", " ", RowBox[{"(", RowBox[{ RowBox[{"2", " ", "\[Mu]a", RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}], "\[Alpha]aa", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}]}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]aa"}], ")"}], RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}], "PAf"}], "+", RowBox[{"\[Mu]a", " ", "Paf"}]}], ")"}]}]}], ")"}]}]}], ")"}]}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"faaNext", "=", RowBox[{ FractionBox["1", "Wfbar"], RowBox[{"(", RowBox[{ RowBox[{"fAA", " ", "wAA", " ", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]AA", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], " ", SuperscriptBox["\[Mu]A", "2"]}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]AA"}], ")"}], " ", "\[Mu]A", " ", "Paf"}]}], ")"}]}], "+", RowBox[{"fAa", " ", "wAa", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]Aa", " ", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], "pahet", " ", "pahet"}], "+", RowBox[{"pahet", RowBox[{"(", RowBox[{"1", "-", "\[Alpha]Aa"}], ")"}], "Paf"}]}], ")"}]}], " ", "+", " ", RowBox[{"faa", " ", "waa", " ", RowBox[{"(", RowBox[{ RowBox[{"\[Alpha]aa", RowBox[{"(", RowBox[{"1", "-", "\[Delta]"}], ")"}], SuperscriptBox[ RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}], "2"]}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "\[Alpha]aa"}], ")"}], RowBox[{"(", RowBox[{"1", "-", "\[Mu]a"}], ")"}], " ", "Paf"}]}], ")"}]}]}], ")"}]}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]fAA", "=", RowBox[{"fAANext", "-", "fAA"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]fAa", "=", RowBox[{"fAaNext", "-", "fAa"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"\[CapitalDelta]faa", "=", RowBox[{"faaNext", " ", "-", " ", "faa"}]}], ";"}], "\n", RowBox[{ RowBox[{"\[CapitalDelta]p", "=", RowBox[{ RowBox[{"\[CapitalDelta]faa", "+", FractionBox["\[CapitalDelta]fAa", "2"]}], "/.", "Gen"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\[CapitalDelta]C", "=", RowBox[{ RowBox[{"faaNext", "-", SuperscriptBox[ RowBox[{"(", RowBox[{"faaNext", "+", FractionBox["fAaNext", "2"]}], ")"}], "2"], "-", " ", "Cc"}], " ", "/.", "Gen"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "Numerical"}], " ", "sanity", " ", "check"}], " ", "***)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"num", "=", RowBox[{"{", RowBox[{ RowBox[{"r", "->", "0.5"}], ",", " ", RowBox[{"\[Mu]A", "->", "0.001"}], ",", RowBox[{"\[Mu]a", "->", "0.000"}], ",", " ", RowBox[{"s", "->", "0.05"}], ",", " ", RowBox[{"h", "->", ".25"}], ",", " ", RowBox[{"\[Alpha]AA", "->", "1"}], ",", " ", RowBox[{"\[Alpha]Aa", "->", "1"}], ",", " ", RowBox[{"\[Alpha]aa", "->", "0"}], ",", " ", RowBox[{"F0", "->", "1"}], ",", " ", RowBox[{"\[Delta]", "->", "0.4695"}]}], "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"freq", "=", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"qAA", "->", "fAA"}], ",", " ", RowBox[{"qAa", "->", "fAa"}], ",", " ", RowBox[{"qaa", "->", "faa"}]}], "}"}], "/.", RowBox[{"FindRoot", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"\[CapitalDelta]fAA", "==", "0"}], "&&", " ", RowBox[{"\[CapitalDelta]fAa", "==", "0"}], "&&", " ", RowBox[{"\[CapitalDelta]faa", " ", "==", "0"}]}], "/.", "num"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"fAA", ",", "0.998"}], "}"}], ",", " ", RowBox[{"{", RowBox[{"fAa", ",", "0.001"}], "}"}], ",", RowBox[{"{", RowBox[{"faa", ",", "0.001"}], "}"}]}], "}"}]}], "]"}]}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Wn", " ", "=", " ", RowBox[{ RowBox[{"Wneut", "/.", "num"}], "/.", "freq"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Eigenvectors", "[", "Wn", "]"}], "[", RowBox[{"[", "1", "]"}], "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{"Qn", " ", "=", RowBox[{ FractionBox["%", RowBox[{"Total", "[", "%", "]"}]], " ", "//", " ", "Chop"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Eigenvectors", "[", RowBox[{"Wn", " ", "//", " ", "Transpose"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}], " ", "//", "Chop"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Vn", "=", FractionBox["%", RowBox[{"%", ".", "Qn"}]]}], ";"}], "\[IndentingNewLine]", RowBox[{"S", "=", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Vn", ".", "DAA", ".", "Qn"}], ",", " ", RowBox[{"Vn", ".", "DAa", ".", "Qn"}], ",", " ", RowBox[{"Vn", ".", "Daa", ".", "Qn"}]}], "}"}], "/.", "freq"}], "/.", "num"}]}]}], "Input", InitializationCell->True, CellChangeTimes->{{3.947661039586792*^9, 3.947661173427747*^9}, { 3.947661277012837*^9, 3.9476613687968884`*^9}, {3.947661742890378*^9, 3.947661743016943*^9}, {3.9476619872178297`*^9, 3.947662068564999*^9}, { 3.94766210659181*^9, 3.9476623048164*^9}, {3.947662334817252*^9, 3.947662463654538*^9}, {3.947662555929509*^9, 3.947662600405588*^9}, { 3.947662635359226*^9, 3.947663054156507*^9}, {3.94766314541782*^9, 3.947663293946878*^9}, {3.947663395835639*^9, 3.947663482892063*^9}, { 3.947663529367299*^9, 3.947663673877572*^9}, {3.9476637976552773`*^9, 3.9476640106242113`*^9}, {3.947664043396241*^9, 3.947664141347052*^9}, { 3.9476642898585253`*^9, 3.94766444585038*^9}, {3.947664488447031*^9, 3.9476645224469347`*^9}, {3.9476646121250553`*^9, 3.947664705364938*^9}, { 3.947664740763192*^9, 3.9476650042255783`*^9}, {3.947665072223288*^9, 3.9476650783060217`*^9}, {3.947665166039015*^9, 3.9476651797668953`*^9}, { 3.947665552319476*^9, 3.947665923684361*^9}, {3.947665960898096*^9, 3.947666146121011*^9}, {3.947666177004161*^9, 3.9476664205836163`*^9}, { 3.9476664571952057`*^9, 3.9476669807521477`*^9}, {3.947668311334918*^9, 3.947668316210341*^9}, {3.947668890554962*^9, 3.9476689046961946`*^9}, { 3.94766993392035*^9, 3.947669936921496*^9}, 3.94767005606131*^9, { 3.947671306162431*^9, 3.947671309525926*^9}, {3.947671524824465*^9, 3.94767153337464*^9}, {3.9476715727459784`*^9, 3.94767157310542*^9}, { 3.94767200358926*^9, 3.947672014052796*^9}, {3.947672618314928*^9, 3.94767262042155*^9}, {3.94767818543445*^9, 3.947678192674328*^9}, { 3.947678694348378*^9, 3.947678831038933*^9}, 3.9476797171717787`*^9, { 3.947731551099822*^9, 3.947731556949753*^9}, 3.947732448689054*^9, { 3.947732790882656*^9, 3.9477327994747877`*^9}, {3.9477328740000477`*^9, 3.947732879817034*^9}, {3.9477364985945*^9, 3.947736504083338*^9}, { 3.94773851591068*^9, 3.947738520598201*^9}, {3.947753844331571*^9, 3.947753948695784*^9}, {3.9512214377272377`*^9, 3.951221454935988*^9}, { 3.951221504889757*^9, 3.9512215598366623`*^9}, 3.9512223623076057`*^9, { 3.951222463658976*^9, 3.95122250905317*^9}, {3.951224005788224*^9, 3.95122406633392*^9}, 3.951224105976554*^9, 3.951224465986767*^9, { 3.951287352466301*^9, 3.951287396245247*^9}, {3.951287435899811*^9, 3.951287488676366*^9}, 3.9512881253648243`*^9, {3.951288806621315*^9, 3.951288825767291*^9}, {3.951289391346567*^9, 3.9512894052710333`*^9}, { 3.9512894553912888`*^9, 3.951289478574898*^9}, {3.9512911077827673`*^9, 3.951291118566152*^9}, 3.9512913934290113`*^9, 3.95129209871943*^9, { 3.951292312542288*^9, 3.95129231434342*^9}, {3.951292348225844*^9, 3.9512923636442337`*^9}, {3.9512929342830763`*^9, 3.951293012681151*^9}, { 3.9512931707247267`*^9, 3.951293184572069*^9}, {3.951293972014524*^9, 3.951294015518778*^9}, {3.951294048143248*^9, 3.9512940516124163`*^9}, { 3.951294697697607*^9, 3.9512947082038527`*^9}, {3.951295574091826*^9, 3.9512955762166853`*^9}, {3.951296194039905*^9, 3.9512961950676203`*^9}, { 3.9512963212698*^9, 3.951296359749683*^9}, {3.951298781006975*^9, 3.9512987813489227`*^9}, {3.951308394704249*^9, 3.95130846041113*^9}, { 3.951308822669839*^9, 3.951308846429058*^9}, {3.951310098266603*^9, 3.951310107226383*^9}, {3.951378965984469*^9, 3.9513789663449593`*^9}, { 3.9514609174449453`*^9, 3.951460955057933*^9}, {3.951463330427568*^9, 3.9514633305723963`*^9}, 3.951463411361874*^9, 3.951463949232914*^9, { 3.951470087176374*^9, 3.9514700897188997`*^9}, {3.951472023286127*^9, 3.9514720239786043`*^9}, {3.951478744698498*^9, 3.951478911460046*^9}, { 3.9514790416866007`*^9, 3.951479056979508*^9}, {3.951479214513053*^9, 3.951479220281351*^9}, {3.9515384678486347`*^9, 3.9515385347934523`*^9}, { 3.9515396019990673`*^9, 3.9515396325177517`*^9}, {3.95153983504753*^9, 3.9515398390556297`*^9}, {3.95154117419543*^9, 3.95154118905941*^9}, { 3.9515425543885927`*^9, 3.951542556386208*^9}, {3.951548956382991*^9, 3.951549024215613*^9}, {3.95155232281563*^9, 3.951552368224514*^9}, 3.951554433291005*^9, {3.951554606509554*^9, 3.9515546375014143`*^9}, { 3.95155683029143*^9, 3.951556846287141*^9}, 3.951561643172195*^9, { 3.9515626702211027`*^9, 3.9515626704273367`*^9}, {3.952088576274102*^9, 3.9520886077574244`*^9}, {3.952088662052704*^9, 3.952088662222322*^9}, { 3.9520903704411*^9, 3.952090374337023*^9}, {3.9521386487908897`*^9, 3.952138652436529*^9}, {3.953889474756983*^9, 3.9538898230903254`*^9}, { 3.953951312932727*^9, 3.953951433336596*^9}, {3.953951606684895*^9, 3.9539516574597197`*^9}, {3.953951992796398*^9, 3.9539521563252487`*^9}, { 3.9539522006553793`*^9, 3.953952311095501*^9}, {3.953952347648328*^9, 3.953952611365756*^9}, {3.953954360989437*^9, 3.953954361357059*^9}, { 3.954466037844101*^9, 3.9544660405366993`*^9}, {3.954466088500957*^9, 3.954466089870541*^9}, {3.9544663010057783`*^9, 3.9544663162549353`*^9}, { 3.954466569275454*^9, 3.9544666208389187`*^9}, {3.9544666591458883`*^9, 3.954466811472674*^9}, {3.954466898056427*^9, 3.9544669804816637`*^9}, { 3.954467030798069*^9, 3.954467182402733*^9}, {3.95446721352141*^9, 3.954467226646529*^9}, {3.954467279409639*^9, 3.954467330390635*^9}, { 3.954467573980928*^9, 3.9544675800455647`*^9}, {3.9544684060407953`*^9, 3.9544684608511744`*^9}, {3.954468496467827*^9, 3.954468513113545*^9}, { 3.9544685451846533`*^9, 3.954468567957325*^9}, {3.95446864037326*^9, 3.954468772658304*^9}, {3.954468805127985*^9, 3.954468823673401*^9}, { 3.954468859938105*^9, 3.954468950129733*^9}, {3.954468985018209*^9, 3.954469499679274*^9}, {3.9544700640047626`*^9, 3.954470149204522*^9}, { 3.954470214392798*^9, 3.954470280839427*^9}, {3.954470332301935*^9, 3.954470383858656*^9}, {3.954470469797736*^9, 3.9544706381821833`*^9}, { 3.9544712779804296`*^9, 3.954471292798691*^9}, {3.9544713874561863`*^9, 3.9544714080571327`*^9}, 3.954473627765465*^9, 3.954476586035824*^9, 3.954476756623124*^9, {3.9544770081774693`*^9, 3.9544770087284203`*^9}, 3.954500531298579*^9, 3.954569093150069*^9, {3.954572418062446*^9, 3.9545724212731323`*^9}, {3.954572763344561*^9, 3.9545727866828403`*^9}, { 3.954573396820241*^9, 3.9545734137118187`*^9}, {3.9545735801944313`*^9, 3.9545736583800163`*^9}, 3.954641721736813*^9, {3.95483112091466*^9, 3.9548311424064407`*^9}, {3.954831173589465*^9, 3.954831233430876*^9}, { 3.954831265463554*^9, 3.954831302446682*^9}, {3.954837058790185*^9, 3.954837073811932*^9}, {3.954846332139688*^9, 3.954846373557905*^9}, { 3.9561136033725967`*^9, 3.956113610608549*^9}, {3.9602544852153873`*^9, 3.960254486294434*^9}, {3.9602968014880123`*^9, 3.960296897283646*^9}, { 3.96029695560074*^9, 3.96029704836653*^9}, {3.960339967582856*^9, 3.960339973585215*^9}, {3.960340047962717*^9, 3.960340048225217*^9}, { 3.9603401094250107`*^9, 3.960340123937644*^9}, {3.960340162070343*^9, 3.960340168736264*^9}, {3.960340269037039*^9, 3.960340343520907*^9}, { 3.9603403735316877`*^9, 3.9603404492933903`*^9}, {3.960340541922537*^9, 3.960340603102151*^9}, {3.9603411772523327`*^9, 3.96034121329984*^9}, { 3.960341259505189*^9, 3.960341263054429*^9}, {3.9603508660936193`*^9, 3.9603508740832853`*^9}, {3.965612320067136*^9, 3.965612432446926*^9}, { 3.96561248502489*^9, 3.9656127729023542`*^9}, {3.965612803004239*^9, 3.965612845468536*^9}, {3.972040624280575*^9, 3.9720406326262617`*^9}, { 3.973577824422584*^9, 3.9735778630187387`*^9}, 3.973580172405846*^9, { 3.987228073064966*^9, 3.9872283830187483`*^9}, {3.9872284209039183`*^9, 3.987228478921438*^9}, {3.987228519470521*^9, 3.9872285904622707`*^9}, { 3.987232572741815*^9, 3.9872326716492434`*^9}, 3.9872327892861433`*^9, { 3.987232993025777*^9, 3.987233031961678*^9}, {3.9878244726243877`*^9, 3.987824581594389*^9}, {3.98784027851265*^9, 3.9878403622279053`*^9}, { 3.987841164071981*^9, 3.987841226609515*^9}, {3.987841340481885*^9, 3.987841372427017*^9}, {3.987841631299941*^9, 3.9878416579337893`*^9}, { 3.987841722115596*^9, 3.9878417296649027`*^9}, {3.9878442162035217`*^9, 3.987844306197514*^9}, {3.987845258818284*^9, 3.987845307633429*^9}, 3.989394920821265*^9},ExpressionUUID->"25a3802e-983c-4161-82bc-\ b0f754f4744f"] }, Open ]], Cell[CellGroupData[{ Cell["Numerical investigations", "Section", CellChangeTimes->{{3.9604350547985897`*^9, 3.960435064273971*^9}, 3.989394950936763*^9},ExpressionUUID->"7a3ed80a-6b95-4b9b-8da1-\ 902ab87b0610"], Cell[CellGroupData[{ Cell["Gradient iteration approach", "Subsection", CellChangeTimes->{{3.960540050885124*^9, 3.9605400602839203`*^9}},ExpressionUUID->"68826bf7-f96f-4904-a90c-\ 2f5b6e844e2c"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Aa", " ", "=", RowBox[{"{", RowBox[{"0.5", ",", "0.5", ",", "0.5"}], "}"}]}], ";"}], " ", RowBox[{"(*", RowBox[{"*", " ", "Initial", " ", "trait", " ", RowBox[{"values", "."}]}], " ", "**)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"pAa", "=", RowBox[{"{", RowBox[{ RowBox[{"-", "100"}], ",", RowBox[{"-", "100"}], ",", RowBox[{"-", "100"}]}], "}"}]}], ";"}], " ", RowBox[{"(*", RowBox[{ RowBox[{ "*", " ", "Values", " ", "in", " ", "the", " ", "previous", " ", "time"}], "-", RowBox[{ "step", " ", "used", " ", "for", " ", "stopping", " ", "criterion", " ", "and", " ", "so", " ", "initialised", " ", "to", " ", "something", " ", RowBox[{"large", "."}]}]}], " ", "**)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"vA", "=", RowBox[{"{", "Aa", "}"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"tol", "=", SuperscriptBox["10", RowBox[{"-", "12"}]]}], ";"}], " ", RowBox[{"(*", RowBox[{"*", " ", "Tolerance", " ", "for", " ", RowBox[{"stopping", "."}]}], " ", "**)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"num", "=", RowBox[{"{", RowBox[{ RowBox[{"r", "->", "0.5"}], ",", " ", RowBox[{"\[Mu]A", "->", "0.001"}], ",", RowBox[{"\[Mu]a", "->", "0.001"}], ",", " ", RowBox[{"s", "->", "0.05"}], ",", " ", RowBox[{"h", "->", "0.1"}], ",", " ", RowBox[{"F0", "->", "1"}], ",", " ", RowBox[{"\[Delta]", "->", ".47"}]}], "}"}]}], ";"}], " ", RowBox[{"(*", RowBox[{"*", " ", "Parameter", " ", RowBox[{"values", "."}]}], " ", "**)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"Total", "[", SuperscriptBox[ RowBox[{"(", RowBox[{"Aa", "-", "pAa"}], ")"}], "2"], "]"}], " ", ">", " ", "tol"}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "While", " ", "the", " ", "selfing", " ", "rates", " ", "keep", " ", "changing"}], " ", "..."}], " ", "*)"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"rA", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], "->", RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}]}], "&"}], ")"}], "/@", RowBox[{"Transpose", "@", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"\[Alpha]AA", ",", "\[Alpha]Aa", ",", "\[Alpha]aa"}], "}"}], ",", " ", "Aa"}], "}"}]}]}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"Replacement", " ", "rule", " ", "for", " ", "selfing", " ", RowBox[{"rates", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "RESIDENT"}], " ", "EQUILIBRIUM"}], " ", "***)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"\[CapitalDelta]f", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ "\[CapitalDelta]fAA", ",", " ", "\[CapitalDelta]fAa", ",", " ", "\[CapitalDelta]faa"}], "}"}], "/.", "num"}], " ", "/.", "rA"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ "Change", " ", "in", " ", "genotypic", " ", "frequencies", " ", "at", " ", "condition", " ", "locus", " ", "in", " ", "resident", " ", RowBox[{"pop", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ff", "=", RowBox[{"{", RowBox[{"0.25", ",", "0.5", ",", "0.25"}], "}"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"Initial", " ", "genotypic", " ", RowBox[{"freqs", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"pf", "=", RowBox[{"{", RowBox[{ RowBox[{"-", "100"}], ",", RowBox[{"-", "100"}], ",", RowBox[{"-", "100"}]}], "}"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"Genotypic", " ", "frequencies", " ", "in", " ", "previous", " ", RowBox[{"gen", ".", " ", "for"}], " ", "stopping", " ", RowBox[{"criterion", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"Total", "[", SuperscriptBox[ RowBox[{"(", RowBox[{"ff", "-", "pf"}], ")"}], "2"], "]"}], " ", ">", " ", "tol"}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "While", " ", "genotypic", " ", "frequencies", " ", "keep", " ", "changing"}], " ", "..."}], " ", "*)"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"rf", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], "->", RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}]}], "&"}], ")"}], "/@", RowBox[{"Transpose", "@", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"fAA", ",", "fAa", ",", "faa"}], "}"}], ",", " ", "ff"}], "}"}]}]}]}], ";", RowBox[{"(*", " ", RowBox[{"Replacement", " ", "rule", " ", "for", " ", RowBox[{"frequencies", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"pf", "=", "ff"}], ";", " ", RowBox[{"(*", " ", RowBox[{"Update", " ", RowBox[{"freqs", ".", " ", "in"}], " ", "previous", " ", RowBox[{"gen", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"ff", "+=", RowBox[{"\[CapitalDelta]f", "/.", "rf"}]}]}]}], " ", RowBox[{"(*", " ", RowBox[{ "Genotypic", " ", "frequencies", " ", "in", " ", "the", " ", "next", " ", RowBox[{"generation", "."}]}], " ", "*)"}], "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"rq", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], "->", RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}]}], "&"}], ")"}], "/@", RowBox[{"Transpose", "@", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"qAA", ",", "qAa", ",", "qaa"}], "}"}], ",", "ff"}], "}"}]}]}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ "Replacement", " ", "rule", " ", "for", " ", "genotypic", " ", "frequencies", " ", "at", " ", RowBox[{"equilibrium", "."}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "SELECTION"}], " ", "GRADIENT"}], " ", "***)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"Wn", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"Wneut", "/.", "num"}], "/.", "rq"}], " ", "/.", "rA"}]}], ";", "\[IndentingNewLine]", RowBox[{"Qn", " ", "=", " ", RowBox[{ RowBox[{"Eigenvectors", "[", "Wn", "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"Qn", " ", "/=", RowBox[{"Total", "[", "Qn", "]"}]}], " ", "//", " ", "Chop"}], ";", "\[IndentingNewLine]", RowBox[{"Vn", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"Eigenvectors", "[", RowBox[{"Wn", " ", "//", " ", "Transpose"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}], " ", "//", "Chop"}]}], ";", "\[IndentingNewLine]", RowBox[{"Vn", " ", "/=", " ", RowBox[{"Vn", ".", "Qn"}]}], ";", "\[IndentingNewLine]", RowBox[{"Sn", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Vn", ".", "DAA", ".", "Qn"}], ",", " ", RowBox[{"Vn", ".", "DAa", ".", "Qn"}], ",", " ", RowBox[{"Vn", ".", "Daa", ".", "Qn"}]}], "}"}], "/.", "rq"}], "/.", "num"}], " ", "/.", "rA"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"**", " ", "CHANGE"}], " ", "IN", " ", "TRAIT", " ", "VALUES"}], " ", "***)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"pAa", "=", "Aa"}], ";", " ", RowBox[{"(*", " ", RowBox[{ "Update", " ", "trait", " ", "values", " ", "in", " ", "previous", " ", RowBox[{"timestep", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Aa", "+=", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"dA", RowBox[{"{", RowBox[{ FractionBox[ RowBox[{"Sn", "[", RowBox[{"[", "1", "]"}], "]"}], "qAA"], ",", FractionBox[ RowBox[{" ", RowBox[{"Sn", "[", RowBox[{"[", "2", "]"}], "]"}]}], "qAa"], ",", " ", FractionBox[ RowBox[{"Sn", "[", RowBox[{"[", "3", "]"}], "]"}], "qaa"]}], "}"}]}], "/.", "rq"}], "/.", "num"}], " ", "/.", "rA"}], "/.", RowBox[{"dA", "->", "0.05"}]}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ "Trait", " ", "values", " ", "move", " ", "in", " ", "the", " ", "direction", " ", "of", " ", "the", " ", RowBox[{"gradients", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Here", ",", " ", RowBox[{ "gradients", " ", "are", " ", "divided", " ", "by", " ", "frequencies", " ", "of", " ", "each", " ", "genotype", " ", "to", " ", "speed", " ", "up", " ", "the", " ", "process"}], ",", " ", RowBox[{ "because", " ", "selection", " ", "on", " ", "rare", " ", "genotypes", " ", "is", " ", "very", " ", RowBox[{"weak", ".", " ", "This"}], " ", "does", " ", "not", " ", "change", " ", "the", " ", "sign", " ", "of", " ", "gradients"}], ",", " ", RowBox[{ "so", " ", "this", " ", "does", " ", "not", " ", "affect", " ", "the", " ", "equilibrium", " ", RowBox[{"reached", "."}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Aa", " ", "=", " ", RowBox[{ RowBox[{ RowBox[{"Clip", "[", RowBox[{"#", ",", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], "]"}], " ", "&"}], "/@", " ", "Aa"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ "Trait", " ", "values", " ", "are", " ", "clipped", " ", "to", " ", "be", " ", "kept", " ", "within", " ", RowBox[{"bounds", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"vA", " ", "=", RowBox[{"Append", "[", RowBox[{"vA", ",", "Aa"}], "]"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "Input", CellChangeTimes->{{3.960435856472116*^9, 3.960435981274601*^9}, { 3.960436021631117*^9, 3.96043614254275*^9}, {3.9604362122591267`*^9, 3.960436301730568*^9}, {3.960436339525963*^9, 3.960436417988968*^9}, { 3.960436465996665*^9, 3.960436468977632*^9}, {3.960436506698946*^9, 3.960436548778645*^9}, {3.960436828192601*^9, 3.960437304235188*^9}, { 3.96043738964606*^9, 3.960437465710607*^9}, {3.9604375507502947`*^9, 3.960437567783469*^9}, 3.960538595915695*^9, {3.987234267233369*^9, 3.987234355148847*^9}, {3.987234398292283*^9, 3.987234423922904*^9}, 3.987234527536277*^9, {3.987234654759677*^9, 3.987234666750948*^9}, 3.98723476837792*^9, {3.987234860134491*^9, 3.9872348619897003`*^9}, 3.987235003485938*^9, {3.987237878990384*^9, 3.987237879059671*^9}, 3.9872381447936697`*^9, {3.9877369792147617`*^9, 3.987736986058392*^9}, { 3.9878241398562307`*^9, 3.9878241562103367`*^9}, {3.987824195498642*^9, 3.9878241960226593`*^9}, {3.987832704688973*^9, 3.987832738879171*^9}, 3.987832827400032*^9, {3.987832862474957*^9, 3.987832862928898*^9}, { 3.987832965417055*^9, 3.98783296805729*^9}, {3.9878345732651443`*^9, 3.987834573642599*^9}, 3.987834951995034*^9, {3.9878401494030323`*^9, 3.9878401539086514`*^9}, {3.987845361311285*^9, 3.987845365238934*^9}},ExpressionUUID->"dfac4141-7cb1-4fc8-8602-\ 29bd5f1201ea"] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{1915.5, 1055.25}, WindowMargins->{{Automatic, -1917.75}, {Automatic, -22.5}}, TaggingRules-><|"TryRealOnly" -> False|>, Magnification:>0.9 Inherited, FrontEndVersion->"14.2 for Linux x86 (64-bit) (December 26, 2024)", StyleDefinitions->"Default.nb", ExpressionUUID->"7a41408b-4cef-4603-80df-220fc33b6e39" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 300, 7, 141, "Title",ExpressionUUID->"5e2c2e28-c3e8-4407-bc37-5defd94dfc69"], Cell[883, 31, 369, 11, 109, "Text",ExpressionUUID->"c6ef5d3c-f525-46e3-8246-64a09bde5e0e"], Cell[CellGroupData[{ Cell[1277, 46, 175, 3, 59, "Section",ExpressionUUID->"bfa7063b-a507-4317-96d3-49dc05e6d5c4"], Cell[1455, 51, 48502, 1280, 4954, "Input",ExpressionUUID->"25a3802e-983c-4161-82bc-b0f754f4744f", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell[49994, 1336, 194, 3, 59, "Section",ExpressionUUID->"7a3ed80a-6b95-4b9b-8da1-902ab87b0610"], Cell[CellGroupData[{ Cell[50213, 1343, 177, 3, 47, "Subsection",ExpressionUUID->"68826bf7-f96f-4904-a90c-2f5b6e844e2c"], Cell[50393, 1348, 12509, 312, 815, "Input",ExpressionUUID->"dfac4141-7cb1-4fc8-8602-29bd5f1201ea"] }, Open ]] }, Open ]] }, Open ]] } ] *)