September 20, 2017, Wednesday
University of Colorado at Boulder Search A to Z Campus Map University of Colorado at Boulder CU 
Search Links


Leslie3.m

From MathBio

Jump to: navigation, search

Leslie3.m

The Leslie3 function is a modified version of leslie2.m and outputs the slope of the population growth

function ans = leslie3(max, prob, growth, stationary)
x = 0:1:max;
P = log(x+1)/log(max+1); %Logarithmic function
% P = sqrt(x)/sqrt(max); %Square root function
% plot(x,P) %Plot of a probability function
% title('Probability of Breakage vs. Position')
% xlabel('Distance from wall (x10^-6)m')
% ylabel('Probability of Breaking')
% if growth + stationary <= 1 && growth>0 && stationary>0
%     display('The growth and stationary rates are acceptable')
% elseif growth < 0
%     display('The growth cannot be negative')
% elseif stationary < 0
%     display('The stationary growth cannot be negative')
% else
%     display('growth + stationary cannot add to more than 1')
% end   
L = zeros(max); %creating the matrix of size max by max
for i = 1:1:max 
   L(1, i) = prob; %Adding the birth rates on the top row of the matrix
end
for i = 1:1:max-1;
   L(i + 1,i) = (1 - P(i+1))*growth; %Growth (lower diagonal)
   L(i + 1, i + 1) = (1 - P(i+1))*stationary; %Stationary (diagonal)
end
for i = 1:1:max-2;
   L(i + 1, i + 2) = (1 - P(i+1))*(1-(growth + stationary)); %Collapse (upper diagonal)
end
n = zeros(max,1); %Initial population state
for i = 1:1:4
   n(i,1) = 1; %Initial population is <1, 1, 1, 1, 0, 0...>
end
x = zeros(50,1);
t = 1:1:50; %for a 50 second time period
for i = t;
   n = L*n; %calculating the population by multiplying the matrix by the initial population
   x(i) = sum(n);
end
% figure(2)
% semilogy(t, x); %Log plot of the population trends
% xlabel('time');
% ylabel('log(population)');
% title('population vs. time');
ans = (x(50)-x(1))/49; %The approximate slope of the data
end