Hi, I am stuck on a point where the 's' value needs to be changed to 0.51 in the next generation (t+1) when Ns>100, otherwise it has to be default (0.5). Can you please help with this. Thanks in advance.
Show older comments
e=0.98;%hatchability
Mc=1.1;%minimum critical body mass
delta=0.15;%adult density sensitivity
x1=2.5;%scaling constant
highgammayeastedHH=107;
highF=2.8;%high larval food
x2=1;%scaling constant
x3=0.009;%scaling constant
x4=2;%scaling constant
x5=1.7;%scaling constant
gen=1:50;%number of generations
Nt=20;%number of eggs laid by first females
Adults=zeros(50,1); %pre-allocating adults
Ns=zeros(50,1);Ns(1)=Nt;
Nt=20;%number of eggs for first generation
s =.51;
for t=1:20%iterating the loop
Nl=floor(e*Nt);%number of larvae survived
if Nl==0
Nl=8;%condition for extinction, when a pop goes extinct, I start it with 15 larvae
end
mean=x1*(1-(1/(x2+exp(-x3*Nl+highF))));%mean (body weight)
L=normrnd(mean,0.45,[1 Nl]);%randomly extracting Nl individuals from a normal distribution
Na=L(L>=Mc);%picking individuals with body weight greater or equal to minimum critical weight
Ns=numel(Na);%summing the number of individuals who crossed the critical weight
if Adults>=100
R=binornd(Ns,s,1);
else
R=binornd(Ns,.5,1);
end
fem=randsample(Na,R);%number of females
Fem=numel(fem);
Ssi=log(x4+x5*(fem));%allocating some propotion of body wieght to fecundity
NA=Ns;%adult density realized by each individual
G=1/(1+delta*NA);%effect of adult density on fecundity
ni=highgammayeastedHH*Ssi*G;%fecundity of an ith individual
Nt=sum(ni);%summing the number of eggs laid by females
N(t)=Nt;%number of eggs for the next generation
Adults(t)=Ns;%adults
end
Answers (1)
Geoff Hayes
on 6 Dec 2015
Neha - since Ns is defined to be
Ns=numel(Na);
then why not do something similar to what you have already
if Ns >= 100
s = 0.51;
else
s = 0.5;
end
R=binornd(Ns,s,1);
Try implementing the above and see what happens!
2 Comments
neha p
on 6 Dec 2015
Geoff Hayes
on 7 Dec 2015
If you don't want this to affect the current iteration, then put this code
if Ns >= 100
s = 0.51;
else
s = 0.5;
end
at the end of the loop (so that is the last thing to execute before the next iteration begins).
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!