function varargout = code17a(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));

k = 2 + cos(ee*t);

dydt(1) = y(2);
dydt(2) = -(2+cos(ee*t))^2*y(1);

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

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