function varargout = code22a(t,y,flag)

%  this file modelled after "help odefile"

global epsil

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 epsil

dydt = zeros(size(y));

dydt(1) = y(2);
dydt(2) = -y(1) + epsil*sin(y(2));

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

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