Examples used during the lectures

Day 1

Demographic model and invasion fitness example

Clear["Global`*"]

demographics in monomorphic pop

(* demographics in monomorphic pop *)

Nt1 ==( s + ((f[x])/(1+γ Nt))) Nt ;
soln = Flatten@Solve[ ( s + ((f[x])/(1+γ Nt)))  ==1, Nt]

Nt == (1/γ)(((f[x])/(1-s ))-1) /. soln //Simplify

invasion fitness example

s + ((f[y])/(1+γ Nt))  /.  soln  //Simplify ;
% ==  s + (1-s) ((f[y])/(f[x])) //Simplify

Asocial model

Clear["Global`*"]

f = fmax Exp[-((y^2)/(2((σg)^2)))] ; 
w = (f/((f /. y-> x)))  ;

S = D[w,y] /. y-> x

sing = Flatten@Solve[S ==0,x]

J = D[S,x] /.sing

H = D[w,y,y] /. y-> x   ;
%  /.sing

D[w,x,y] /. y-> x  /.sing

Social model

Clear["Global`*"]

Wright - Fisher model in large population where fecundity is determined by the amount of resources obtained under trait matching competition where resources are Normaly distributed

(* Integrate[((Exp[-((((y-θ))^2)/(2((σg)^2)))])/(n Exp[-((((x-θ))^2)/(2((σg)^2)))]))PDF[NormalDistribution[0,σr],θ],{θ,-∞,∞}]  ; 
Assuming[σr>0,Simplify[%]] *)

PDF[NormalDistribution[0,σr],θ]

((E^(((x-y) ((x+y) ((σg)^2)+(x-y) ((σr)^2)))/(2 ((σg)^4))))/n) == (1/n)(E^((( (x^2)-(y^2) +(((x-y))^2) (((σr)^2)/((σg)^2)))/(2 ((σg)^2))) ))//Simplify

R =(1/n)(E^((( ((x^2)-(y^2)) +(((x-y))^2) (((σr)^2)/((σg)^2)))/(2 ((σg)^2))) )) ; 
f = n R ; 
w = f

D[w,y]

S = D[w,y] /. y-> x

sing = Flatten@Solve[S ==0,x]

J = D[S,x] /.sing

H = D[w,y,y] /. y-> x  ;
%  /.sing //Simplify  ;
% ==(1/((σg)^4)) (((σr)^2)-((σg)^2) )

p1 = Plot[PDF[NormalDistribution[0,σr],θ]/. σr-> 1 ,{θ,-4,4} ,PlotStyle->Gray] ;
p2 = Plot[Exp[-((((y/(2 ((σg)^2) ))))^2)] /. σg-> 0.5 ,{y,-4,4} ,PlotStyle->Black ] ;
Show[p1,p2]

Social and survival model -- with evolutionary suicide

Clear["Global`*"]

Survival with model in large population where fecundity is determined by fecundity

w = s + ((f[y,x])/(1+γ n[x])) ;
soln = Flatten@Solve[w ==1/.y->x, n[x]]

n[x] == (1/γ)(((f[x,x])/(1-s ))-1) /. soln //Simplify

w = s + ((f[y,x])/(1+γ n[x])) ;
w =w/.soln  //Simplify  ;
% == s + (1-s) ((f[y,x])/(f[x,x])) //Simplify

f[y_,x_] :=  R[x](y/x) Exp[-((y^2)/(2 (σ^2)))] ; 
(* where R[x] is the equilibrium amount of resources in a x population and y/x is the amount of resources a y mutant gets *)

S = D[w,y] /. y-> x  //Simplify

sing =Solve[S==0,x]

sing = sing[[2]] ;

J = D[S,x] /.sing  //FullSimplify

H = D[w,y,y]  /. y-> x   //FullSimplify;
%  /.sing

(* observe that selection is independent of resource levels. What if those decline with the trait ? e.g. due to interference as predation decreases birth rate ?   *)

with resource birth rate declining with consumer trait in density independent way

((d R)/dt) == ( b(1-x) - d R ) R ;    
Solve[ ( b(1-x) - d R ) R  == 0 ,R ] /. b -> r0 d  //Simplify

(1/γ)(((f[x,x])/(1-s ))-1)   /.R -> Function[x,r0(1-x) ] /. soln /.sing  //Simplify  ; 

% ==(1/γ) (((r0 (1-σ))/((Sqrt[E]) (1-s)))-1 )//Simplify

Plot[Evaluate[Clip[((-1+((r0 (-1+σ))/((Sqrt[E]) (-1+s))))/γ)/. γ->.001 /.s->0/.σ-> {0.1,0.2,0.3},{0,∞}]],{r0,0,10},AxesOrigin->{0,0}]

with resource birth rate declining with consumer trait in density dependent way

((d R)/dt) == ( b(1-x)n[x] - d R ) R ;    
Solve[ ( b(1-x)n[x] - d R ) R  == 0 ,R ]/. b -> r0 d  //Simplify

soln

Solve[{R[x]== -r0 (-1+x) n[x],n[x] == ((1-s-(E^(-(x^2))) R[x])/((-1+s) γ))},{R[x],n[x]}] //FullSimplify

(1/γ)(((f[x,x])/(1-s ))-1)   /.R -> Function[x,(1/(-((E^(-(x^2)))/(-1+s))+(γ/(r0 (-1+x))))) ] /. soln /.sing  //Simplify

Plot[Evaluate[Clip[-((2 (Sqrt[E]) (-1+s))/(-((-2+(Sqrt[2])) r0)+2 (Sqrt[E]) (-1+s) γ))/. γ->.001 /.s-> {0,0.1,0.2},{0,∞}]],{r0,0,10},AxesOrigin->{0,0}]

Clear["Global`*"]

D[w[x,x,n[x]],x]

n'[x] == - ((Derivative[0,1,0][w][x,x,n[x]]+Derivative[1,0,0][w][x,x,n[x]])/(Derivative[0,0,1][w][x,x,n[x]]))

n'[x] ==  ((Derivative[0,1,0][w][x,x,n[x]])/(- Derivative[0,0,1][w][x,x,n[x]]))