In[]:=
Manipulate[Module[{fDot,mDot,poly,roots,stableRoots,rStar,rIso,endPointStar,endPointIso},(*1.DefinetheSystemDynamics*)fDot=phi1*(f/m)-phi2*(m/f);mDot=mu1*(f/m)-mu2*(m/f);(*2.FindtheEquilibriumRatior=f/m*)(*Thecubicpolynomialgoverningtheratioevolution*)poly[r_]:=-mu1*r^3+phi1*r^2+mu2*r-phi2;(*Solveforpositiverealroots*)roots=r/.NSolve[{poly[r]==0,r>0},r];(*FilterforSTABLErootswhereP'(r)<0*)stableRoots=Select[roots,(D[poly[x],x]/.x->#)<0&];rStar=If[Length[stableRoots]>0,First[stableRoots],None];(*3.DefinetheF-Isocline(GrowthBoundary)*)rIso=Sqrt[phi2/phi1];(*4.GeometricHelper:Findtheedgeintersectionforaliney=k*x*)(*Thisensuresraysarealwaysdrawnacrossthefullvisiblebox*)getEdge[k_]:=If[k<=1,{scale,scale*k},{scale/k,scale}];endPointIso=getEdge[rIso];endPointStar=If[NumberQ[rStar],getEdge[rStar],{0,0}];(*5.GeneratethePlot*)Show[StreamPlot[{mu1*(f/m)-mu2*(m/f),phi1*(f/m)-phi2*(m/f)},{m,0.1,scale},{f,0.1,scale},StreamPoints->density,StreamStyle->{Arrowheads[0.02],Thickness[0.002],GrayLevel[0.4]},Frame->True,FrameLabel->{Style["Male Population (m)",12,FontFamily->"Helvetica"],Style["Female Population (f)",12,FontFamily->"Helvetica"]},LabelStyle->{12,FontFamily->"Helvetica"},ImageSize->500,PlotRange->{{0,scale},{0,scale}},PlotRangePadding->None],(*Overlays*)Graphics[{(*ShadedRegion:FemaleDecline(BelowIsocline)*){Opacity[0.15],Orange,Polygon[{{0,0},{scale,0},endPointIso}]},(*GreenDottedLine:F-Isocline*){Thickness[0.005],Dotted,Darker[Green],Line[{{0,0},endPointIso}]},(*RedDashedLine:StableAttractor(Onlyifitexists)*)If[NumberQ[rStar],{Thickness[0.007],Dashed,Red,Line[{{0,0},endPointStar}]},{}]}],(*Legend*)PlotLegends->Placed[LineLegend[{Directive[Red,Dashed,Thickness[0.005]],Directive[Darker[Green],Dotted,Thickness[0.005]],Directive[Orange,Opacity[0.5]]},{"Stable Attractor","Growth Boundary","Decline Zone"},LegendFunction->Framed,LegendMargins->5],{Right,Top}]]],(*Controls*){{phi1,4.0,"Fem. Influx (ϕ1)"},0.1,10,Appearance->"Labeled"},{{phi2,1.0,"Fem. Exit (ϕ2)"},0.1,10,Appearance->"Labeled"},{{mu1,1.0,"Male Influx (μ1)"},0.1,10,Appearance->"Labeled"},{{mu2,1.0,"Male Exit (μ2)"},0.1,10,Appearance->"Labeled"},Delimiter,{{scale,10,"Max Population"},10,100,10,Appearance->"Labeled"},{{density,20,"Streamline Density"},5,40,1,Appearance->"Labeled"},ControlPlacement->Left,TrackedSymbols:>{phi1,phi2,mu1,mu2,scale,density}]
Out[]=

