MATHEMATICAL EVOLUTIONARY THEORY - MATH 583plotsetup(default):plotsetup(window):Haploid populationsDynamics of allele frequencies in a one-locus k-allele haploid population with constant fitnessesk:=5: t_max:=100: number of alleles and maximum timef[1]:=.2: f[2]:=.2: f[3]:=.2: f[4]:=.2: f[5]:=.2: initial allele frequenciesw[1]:=.92: w[2]:=.94: w[3]:=.96: w[4]:=.98: w[5]:=1: fitnesseswmean:=sum( 'f[i]*w[i]^t', 'i'=1..k): Wmean:=sum( 'f[i]*w[i]^(t+1)', 'i'=1..k):wbar:= Wmean/wmean: mean fitness of the population in generation tfor i from 1 to k do p[i]:=f[i]*w[i]^t/wmean od: compute allele frequencies at generation tplot( {p[1],p[2],p[3],p[4],p[5],wbar}, t=0..t_max, title=`Allele frequencies and mean fitness\n in 1-locus k-allele haploid population with constant fitnesses`, labels=[generation_number,p_i],titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]); plot Technical notesSolving a system of two linear ODEA system of two linear ODE: x' = ax + by, y' = cx + dy.Its solutions depend on the eigenvalues of the stability matrix [ a b] S = [ c d].S := linalg[matrix](2,2,[a,b,c,d]); define a 2x2 matrix Seq := [ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)]; with(DEtools):Several cases to consider.Both eigenvalues real and positive.a := 1: b := 0: c := 1: d := 1.5: evalf(Eigenvals(S)); phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]},stepsize=.2,x=-1..1,y=-1..1,title=`Unstable node\n (eigenvalues real and positive)`,arrows=THICK,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);Both eigenvalues real and negativea := -.9: b := 0: c := 1: d := -1.5: evalf(Eigenvals(S));phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]},stepsize=.2,x=-1..1,y=-1..1,title=`Stable node\n (eigenvlues real and negative)`,arrows=THICK,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);One positive eigenvalue and one negative eigenvaluea := 1: b := 0: c := 1: d := -1.5: evalf(Eigenvals(S)); phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]}, stepsize=.2,x=-1..1,y=-1..1, title=`Saddle\n (one negative, one positive eigenvalue)`, arrows=THICK, titlefont=[TIMES,BOLD,12], font=[TIMES,BOLD,12]);Complex eigenvalues, Re(l)>0a := .1: b := 1: c := -1: d := .5: evalf(Eigenvals(S));phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]},stepsize=.2,x=-1..1,y=-1..1,title=`Unstable focus\n (complex eigenvalues, Re(l)>0)`,arrows=THICK,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);Complex eigenvalues, Re(l)<0a :=- .5: b := 1: c := -1: d := -.5: evalf(Eigenvals(S));phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]},stepsize=.2,x=-1..1,y=-1..1,title=`Stable focus\n (complex eigenvalues, Re(l)<0)`,arrows=THICK,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);Complex eigenvalues, Re(l)=0a :=0: b := 1: c := -1: d := .0: evalf(Eigenvals(S)); phaseportrait([ diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t) = c*x(t)+d*y(t)],[x(t),y(t)],-2..1,{[0,.5,.5],[0,.5,-.5],[0,-.5,-.5],[0,-.5,.5]},stepsize=.2,x=-1..1,y=-1..1,title=`center (complex, Re(l)=0)`,arrows=THICK,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);?plotStability analysis for systems of two non-linear ODEThe following system will be used as an examplerestart: f1:=x*(a-b*x-c*y); specify f1(x,y) f2:=y*(d*x-e-f*y); specify f2(x,y) with(linalg): load librariessols:=solve({f1,f2},{x,y});S:=array([[diff(f1,x),diff(f1,y)],[diff(f2,x),diff(f2,y)]]); define stability matrixS0:=subs( [x=0,y=0],evalm(S)); substitute equilibrium values (0,0) in Slambda0:=eigenvals(evalm(S0)); find eigenvaluesS1:=subs( [x=a/b,y=0], evalm(S)); substitute equilibrium values (a/b,0) in Slambda1:=eigenvals( evalm(S1)); find eigevnaluesnontriv:=solve( {a-b*x-c*y=0,d*x-e-f*y=0},{x,y}); find nontrivial equilibriumS2:=subs( nontriv, evalm(S)); substitute into Slambda2:=eigenvals( evalm(S2)); find eigenvaluesdet(S2); find determinantfactor( trace(S2)); find traceDiploid populationsOne-locus two-allele viability selectiong:=x-> x * (wAA*x+wAa*(1-x)) / (wAA*x^2 +2*wAa*x*(1-x)+waa*(1-x)^2 ): dynamic equationT:=1000: Z:=array[0..T]: Z[0]:= .00001: wAA:=1: wAa:=.95: waa:=.9: parameters and initial conditionfor i from 1 to T do y:=g(Z[i-1]): Z[i]:=y od: iterate dynamic equationplot( [seq([i,Z[i]],i=0..T)], style=point, labels=[ `generation number `, `x` ], title=`1-locus 2-allele model`,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]); plot graphrestart:f:=p*q*(w[A]-w[a])/wmean;w[A]:=w[AA]*p+w[Aa]*q;w[a]:=w[Aa]*p+w[aa]*q;wmean:=w[A]*p+w[a]*q;q:=1-p;factor(f);sols:=solve(f,p);S:=diff(f,p);subs(p=sols[1],S);subs(p=sols[2],S);subs(p=sols[3],S);
simplify(%);One-locus multiallele viability selectionrestart:Two fitness matrices in one-locus three-allele systems illustrating that heterosis is neither a mathematically
necessary nor sufficient condition for a stable feasible equilibrium with more than two alleles
(Lewontin et al., 1978, 88, 149-170).with(linalg):z:=1-x-y:w:=array(1..3,1..3,[[.66,.75,.89],[.75,.28,.77],[.89,.77,.61]]);W1:=w[1,1]*x+w[1,2]*y+w[1,3]*z: induced fitness of allele 1W2:=w[2,1]*x+w[2,2]*y+w[2,3]*z: induced fitness of allele 2W3:=w[3,1]*x+w[3,2]*y+w[3,3]*z: induced fitness of allele 3solve({W2-W1=0,W3-W1=0},{x,y}); no feasible polymorphic solutionw:=array(1..3,1..3,[[.2358,.8457,.7482],[.8457,.1837,.3927],[.7482,.3927,.3964]]);W1:=w[1,1]*x+w[1,2]*y+w[1,3]*z: induced fitness of allele1 W2:=w[2,1]*x+w[2,2]*y+w[2,3]*z: induced fitness of allele 2W3:=w[3,1]*x+w[3,2]*y+w[3,3]*z: induced fitness of allele 3solve({W2-W1=0,W3-W1=0},{x,y}); polymorphic equilibrium is feasibleeigenvals(w); and is stableFertility selection: symmetric modelrestart:g:=x-> 1 / (1 + epsilon * x^2 ); 1-locus 2-allele modelT:=200: Z:=array[0..T]: Z[0]:= .4: epsilon:=4.1: parameters and initial conditionfor i from 1 to T do y:=g(Z[i-1]): Z[i]:=y od: iterate dynamic equationplot( [seq([i,Z[i]],i=0..T)], style=point, labels=[ `generation number `, `x` ], title=`1-locus 2-allele model`,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]); plotg(x);factor(g(g(x))-x);fsolve(subs(e=4,e*x^3+x-1),x);Frequency-dependent selectionFrequency-dependent selection in one-locus two-allele diploid model (Gavrilets and Hastings, 1995, Proc.R.Soc.Lond.B, 261: 233-238).
i) Derivation of the dynamics equation;
ii) Analyses of conditions for existance and stability of equilibria;
iii) Numerical solutions - intermittency and transient chaos
restart:with(linalg): loading librariesF:=array(1..3,1..3,[[1,beta,alpha],[g,eta,g],[alpha,beta,1]]); matrix of coefficientswAA:=F[1,1]*p^2+F[1,2]*2*p*q+F[1,3]*q^2; fitness of AAwAa:=F[2,1]*p^2+F[2,2]*2*p*q+F[2,3]*q^2; fitness of Aawaa:=F[3,1]*p^2+F[3,2]*2*p*q+F[3,3]*q^2; fitness of aawmean:=wAA*p^2+wAa*2*p*q+waa*q^2; mean fitness of the populationwA:=wAA*p+wAa*q: wa:=wAa*p+waa*q: induced allele fitnessq:=1-p: f:=p*(wA-wmean)/wmean; allele frequency in the next generationfactor(%);numer(%)/(p*(2*p-1)*(p-1));factor(%+1-g);f:= p+var(p)*(p-q)*(1-g-Omega*var(p))/(1-2*(2-beta-g)*var(p)+2*Omega*(var(p))^2);allele frequency in the next generationS:=diff(f,p): eigenvaluesvar(p):=p*q;subs(p=0,S); eigenvalues at p=0subs(p=1,S); eigenvalues at p=1subs(p=1/2,S); eigenvalues at p=1/2factor(%);var(p):='var(p)':S;subs({diff(var(p),p)=q-p,var(p)=(1-g)/Omega},%);f:=x->x+x*(1-x)*(2*x-1)*(1-g-Omega*x*(1-x))/(1-2*(2-beta-g)*x*(1-x)+2*Omega*x^2*(1-x)^2);Omega:=C-4*g+(1-beta)^2: new parameter CT:=200: X:=array[0..T]: parameters and initial conditionsX[0]:= .551: C:=.1; g:=1.1; beta:=-2;for i from 1 to T do Y:=f(X[i-1]): X[i]:=Y od: plot( [seq([i,X[i]],i=0..T)], 0..T,0..1,style=point, labels=[ `generation number `, `p` ], title=`Frequency-dependent selection`, titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);