% Modeling the phenomenon of spruce budworm epidemics

% This demo just graphs the solution to the differential equation for
%    various initial conditions
% by Gavin LaRose, 8/9/2012

% (c)2012 Regents of the University of Michigan
% This work is licensed under the
% Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
% To view a copy of this license, visit
% http://creativecommons.org/licenses/by-nc-sa/3.0/
% or send a letter to
% Creative Commons,
% 444 Castro Street, Suite 900,
% Mountain View, CA, 94041, USA.

%----------------------------------------------------------------------
% configuration variables

% values of q to use
interestingQ=[10 9 8 7.3878 7 6];

% the corresponding colors we use for these solutions
colorvec={'w','m','y','c','g','b','k'};

% the initial condition
ic = 3;

% the value of r
r = 0.5;

%----------------------------------------------------------------------
% generate the plot (we pause after the first graph)

figure();
axes('Color',[0.5 0.5 0.5]);
xlab = xlabel( 't', 'FontSize', 16 );
ylab = xlabel( 'u', 'FontSize', 16 );
titl = title( ['Solutions to u'' = r u (1 - u/q) - u^2/(1 + u^2)'],...
	      'FontSize', 16 );
hold on;
pause on;
for j=1:length(interestingQ)
    q = interestingQ(j);
    [t,u] = ode45( @(t,u) r.*u.*(1-u/q)-((u.^2)./(1+u.^2)), [0,200], ic );
    
    plot( t, u, [colorvec{j} '-'], 'LineWidth', 2 );

    legendCell{j} = ['q = ' num2str(q)]; % Building up the legend

    if j==1
      lh = legend( ['q = ' num2str(q)], 'Location', 'SouthEast' );
        pause;
    end
end
legend( legendCell, 'Location', 'SouthEast' );

% all done
%----------------------------------------------------------------------
