%
%   HW9_DEMO1.M  Find population of city versus time (HW9_DEMO1)
%
%   This sample problem was derived from Prob. 6 pg. 76 of Edwards and Penny 
%   (Prentice Hall, 1996).  It addresses the NUMERICAL solution of a 
%   paricular Population Model that approximates the population of a city 
%   with a constant annual growth rate and a constant immigration rate.  
%
%   The population balance equation for this problem is
%       dP/dt = k*P + imr   
%   where k is the constant growth rate and imr is the constant immigration rate.
%   
%   We will solve the problem for a range of ir's (just for fun).
%
%   Calls HW9_DEMO1_EQN.M to evaluate desired function f(t,P).
%
%   File prepared by J. R. White, UMass-Lowell (March. 1998)
%    --> changed names for consistency (Jan. 2000)
%    --> minor changes (March 2002)
%
      
%
%   getting started
      clear all;   close all;   nfig = 0;
      global kk ir
%
%   define integration variables and initial condition
      to = 0;   tf = 25;   Po = 1.5;  % time in years and Po in millions of people
      kk = 0.04;                      % normalized growth rate
%
%   let's define 4 values of imr to study its affect on the population
      imr = [.01 .05 .1 .2];   % immigration rate (units of millions/year)
      cols = ['r- ';'g: ';'b-.';'m--'];
%
%   Evaluate P(t) for each value of imr
      Nir = length(imr);
      for n = 1:Nir
        ir = imr(n);  [t,P] = ode23('hw9_demo1_eqn',[to tf],Po);
        plot(t,P,cols(n,:),'LineWidth',2),hold on
        gtext(['ir = ',num2str(ir)])
      end
      hold off
      grid,title('Population of City Versus Time (HW9 DEMO1)')
      xlabel('Time (years)'),ylabel('Number of People (millions)')
%
%   end of problem
%
