function varargout = Xduff(t,y,flag)
%
%  duffing ODE forcings
%    this file modelled after "help odefile"

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

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

function dydt = Xf(t,y)

global epsi

dydt = zeros(size(y));

dydt(1) = y(2);
dydt(2) = - epsi*y(1)^3 - y(1);

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

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

