% This is an example of code similar to what would be appropriate to 
% do Project #5 part 2 

%
% Set the number of simulations to run as N
%
N=100;

% set a counter for the number of simulations that are extinct
% using E to count them

E=0;

% set the initial conditions

v0=[42; 0; 45];

% This loop is for the number of simulations

for i=1:N

% initialize the population structure

v=v0;

% Project the population forward in time to time 200

for t=1:200

% set the adult fecundity according to the random distribution 
% at each time

F=1.7*rand(1);

% Set the bison matrix up with this variable adult fecundity F

A=[0 0 F; 0.6 0 0; 0 0.75 .6];


% project the population forward one time step and call it v

v=A*v;

end

% at the end of each 200 year simulation check to see if the 
% population size is less than 1 in total 
% and if so increment the variable E to count this as an extinction

if sum(round(v))==0, E=E+1; end;

end;

% calculate the fraction of the simulations that go extinct

ext=E/N
