function varargout = code17b(t,y,flag)

%  this file modelled after "help odefile"

global ee

switch flag
case ''                      % Return dy/dt = f(t,y).
   varargout{1} = f(t,y);
case 'events'                % Return [value,isterminal,direction].
  [varargout{1:3}] = events(t,y);
otherwise
   error(['Unknown flag ''' flag '''.']);
end

% -------------------------------------------------------------

function dydt = f(t,y)

global ee

dydt = zeros(size(y));

k0 = 2 + cos(ee*t);
k1 = -ee*sin(ee*t);
k2 = -(ee^2)*cos(ee*t);

dydt(1) = k0;
dydt(2) = k0 + (3/8)*(k1.^2)/(k0^3) - (1/4)*(k2/(k0^2));

% -------------------------------------------------------------

function [value,isterminal,direction] = events(t,y)
   value = y(1);   isterminal = 1;   direction = -1;
