function [out1, out2, out3] = fdchain(t,y,flag,zeta,eps,b1,b2,d1,d2)
% Deng Equations for a food chain dynamics. 
% Use 'ode15s' or 'ode23s' to find solutions to the equation.
%   
% 
% with initial(end)=0, there is a limit cycle.
%
a=1;s1=.25;s2=.25;
if nargin < 3 | isempty(flag)
   out1 = [a*abs(y(1))*(1-y(1)-s1*y(2)/(b1+y(1)))/(zeta);
           a*abs(y(2))*(y(1)/(b1+y(1))-d1-s2*y(3)/(b2+s1*y(2)));
           a*eps*abs(y(3))*(s1*y(2)/(b2+s1*y(2))-d2)];
else
   switch(flag)
   case 'init'
     out1 = [0; 50];
     out2 = [1,1,1];
     out3 = []; %odeset('Vectorized', 1);
     case 'events' 
     sec1 = y(2)-1.4;
     %sec2 = y(2)-.5;   
     out1 = [sec1];
     out2 = [0];
     out3 = [-1];
   otherwise
      error(['Unknown flag ''' flag ''.']);
   end
end; 
