function varargout = code20a(t,y,flag)

%  this file modelled after "help odefile"

global kk

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 kk

dydt = zeros(size(y));

dydt(1) = y(2);
dydt(2) = (1/(y(1)^4) - kk^2)*y(1);
dydt(3) = 1/(y(1)^2);

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

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


