function y1 = pend( t, y )
%
%   Usage:
%   y' = pend( t, y )   or   y0 = pend()   or  H = pend(y)
%
%   Nonlinear pendulum, first order formulation, y = [q p].
%
%   See pages 140-141  of
%   L.Brugnano, F.Iavernaro.
%   Line Integral Methods for Conservative Problems.
%   Chapman and Hall/CRC - 2015
%   Series: Monographs and Research Notes in Mathematics.
%
if nargin==0     % initial condition
    y1 = [0 1.99999]; 
elseif nargin==1 % Hamiltonian
    q = t(:,1);
    p = t(:,2);
    y1 = .5*p.^2 -cos(q);
else             % nargin==2 => vector field
    q = y(:,1);
    p = y(:,2);
    y1 = [p -sin(q)];
end
return