% File: popGrowth.m
% Description: model of population growth based upon work of RM May (1974)
% Author: Emily G. Allen
% Date: January 2008

% Inputs: 
%       rate: rate of growth (0 to +infinity)
%       numGens: number of generations over which model should be run
%       initialX: initial population size (0 to 1.0)
%       FIG: flag indicating whether a plot should be generate (0 no, 1
%       yes)

% note: X is a fractional value (0 to 1.0) representing the proportion of
% the total capacity currently occupied; i.e. it is proportional to current
% size / max possible size

function [X] = popGrowth(rate, numGens, initialX, FIG)
  
    oldX = initialX; %  start the model at the initial population size
  
    gen = [0]; % initial generation is zero; gen is an array that saves the generation count
    X = [oldX]; % X is an array that savees all calculated population sizes
  
    % for each generation
    for ng = 1:numGens  
        % calculate the new pop size
        nextX = rate * oldX * (1 - oldX);
        
        % save results
        gen = [gen; ng];
        X = [X; nextX];
        
        % update prior state
        oldX  = nextX;
    end

    % plot simulation results
    if (FIG)
       plot(gen, X, '-o');
       xlabel('Generation');
       ylabel('Proportion Capacity Filled');
       title(strcat('rate = ',num2str(rate)));
    end