function varargout = XpendN(t,y,flag)
%
%  pendulum 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 eta No

dydt = zeros(size(y));

y1 = y(   1: No);
y2 = y(No+1:end);

dydt1 = y2;
dydt2 = - eta*y2 - sin(y1);

dydt(   1: No) = dydt1;
dydt(No+1:end) = dydt2;

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

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

