function varargout = X3e(t,y,flag)

%  this file modelled after "help odefile"

global A

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 A B

dydt = zeros(size(y));

Fx = 4*(y(1)^3)/(6^4) + A ...
   - 2*y(1)*exp(-(y(1)^2 + y(2)^2)).*(y(2)^3 - y(1)^3) ...
   - exp(-(y(1)^2 + y(2)^2)).*(3*y(1)^2);
Fy = 4*(y(2)^3)/(6^4) + ...
   - 2*y(2)*exp(-(y(1)^2 + y(2)^2)).*(y(2)^3 - y(1)^3) ...
   + exp(-(y(1)^2 + y(2)^2)).*(3*y(2)^2);

dydt(1) = -Fx;
dydt(2) = -Fy;

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

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