% Simulation of Niwa's model (Chapter 2, Box B) % Written by David Sumpter, corrections by Qi Ma % Number of sites s=2000; k=1; %Initialise sites, one individual per site. x=zeros(1,s); x(1,1:s)=1; %Split probability p=0.3; %Number of time steps maxt=2000; %Keeps track of how many individuals are at site 1. track=zeros(maxt,1); for t=1:maxt y=zeros(1,s); for site=1:s r=rand; if ((x(site)>0) & (r