function n = metapop(imi,ext,ini,alfa,dim,iffig, nostep) % This function simulates the proportion of occupied islands % imi - immigration rate % ext - extinction rate % ini - proportion of habitats initially occupied (0 - one individual in the centre) % dim - number of rows of cells (dim^2 is the number of habitats) % iffig - whether to draw a spatial figure % nostep - number of simulation steps if ini > 0 a = rand(dim,dim) < ini; else a=zeros(dim,dim); a(dim/2,dim/2)=1; end n = []; for t=1:nostep nact = sum(sum(a>0)) ./ dim^2; n = [n nact]; %anew = anew .* (rand(dim,dim) > ext); a = a .* (rand(dim,dim) > ext/(1+alfa*ext*nact)); anew = a + (rand(dim,dim) < (imi .* nact)); a = anew > 0; %plotting colour=['w','g']; if iffig hold on; axis([1,dim+1 1 dim+1]); for (i=1:dim) for (j=1:dim) fill([i,i,i+1,i+1],[j,j+1,j+1,j],colour(a(i,j)+1)) end end pause(0.1); clf end end