% =========================================================================
%  Biological_Models_Malthus.m
% 
%  Continuous and Discrete Malthus Models  
%
%  This is an m-file solving the Malthus model for: 
%  A) The continuous model for various growth rates.
%  B) The discrete model for various growth rates.
% 
% Note the differences between the two models, and the qualitatively
% different behavior predicted for growth rates < 1
%
% =========================================================================
 
% Clears history and command window 
close all; clear all;
 
% Malthus model
% Predicts exponential growth

% -- time period to be examined
tmin = 0;
tmax = 2;

% -- various growth rates
r1 = 1.0;
r2 = 1.3;
r3 = 0.7;
 
% Continuous Malthus Model
y0 = 1; % initial value of population
y1 = @(x) y0*exp(r1*x);
y2 = @(x) y0*exp(r2*x);
y3 = @(x) y0*exp(r3*x);
 
figure (1);
hold on;
fplot (y1, [tmin, tmax], 'b');
fplot (y2, [tmin, tmax], 'r'); 
fplot (y3, [tmin, tmax], 'g'); 
legend('r=1.0','r=1.3','r=0.7');
xlabel('Time');
ylabel('Population');
%title('Population using the continuous Malthus model')
hold off;
 
% Discrete Malthus Model
x = linspace(tmin,tmax,11);
q = zeros(1,11)
q(1:3,1) = 1; % initial value of population
for i = 2:11
  q(1,i) = r1*q(1,i-1);   
  q(2,i) = r2*q(2,i-1);   
  q(3,i) = r3*q(3,i-1);   
end
 
figure (2);
hold on;
plot (x,q(1,:),'b',x,q(2,:),'r',x,q(3,:),'g'); 
legend('r=1.0','r=1.3','r=0.7');
xlabel('Time Steps');
ylabel('Population');
hold off;
