% Simulation of bird feeding (Chapter 3, Box C) % Written by David Sumpter clear close all % Spontaneous arrival in absence of other chickens. Aspon=0.01; % Maximum probability of arrival. Amax=0.4; % Threshold response level. AT=2.3; % Steepness of response, must be greater than 1. Ak=4; %Probability per individual of leaving Pleave = 0.2; %Plot the response function figure(10) a=[0:0.05:5]; f=(5-a).*(Aspon+(Amax-Aspon)*(a.^Ak./(AT^Ak +a.^Ak)))-Pleave*a; plot(a,f) ylabel('Probability of arrival in next 5 seconds'); xlabel('Average number at feeder') %This is the simple simulation where there is only one site with unlimited capacity. spaces=1; simtime=10000; %Number of chickens feeding. c=zeros(simtime,1); %Number of chickens not feeding. out=zeros(simtime,1); out(1)=7; for t=2:simtime c(t)=c(t-1); out(t)=out(t-1); onnow=c(t); Parrive=(Aspon+(Amax-Aspon)*(onnow.^Ak./(AT^Ak +onnow.^Ak))); %Arrival? if out(t-1)>0 r=sum(rand(out(t-1),1)0 r=sum(rand(c(t-1),1)