function varargout = Xsteady(t,y,flag)

%  this file modelled after "help odefile"

global A B

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));

dydt(1) = y(2);
dydt(2) = -A*y(1) + B*y(1)^3;

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

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