
function [val,isterminal,dir] = epiend(t,y)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  function [val,isterminal,dir] = epi1end(t,y,z)        %
%  Solution to CSE Your Homework Assignment Project 6    %
%  More Models of Infection: It's Epidemic               %
%  epiend.m Dianne P. O'Leary   11/03                    %
%                                                        %
%  This program tests whether the integration should be  %
%  terminated in Problem 5 because the epidemic has      %
%  run its course and either left no infected or no      %
%  susceptible.                                          %
%  The y vector has 3*myN components:                    %
%        infected, susceptible, and recovered.           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global myN mythreshhold

ninfect = sum(y(1:myN,1))/myN;
nsuscep = sum(y(myN+1:2*myN,1))/myN;
val = min(ninfect,nsuscep) - mythreshhold;
isterminal = 1;    % This tells the integrator to stop when val=0.
dir = 0;           % This says it doesn't matter whether val
                   % is increasing or decreasing.




