function y1 = pend2( t, q )
%
%   Usage:
%   q'' = M*pend( t, q )   or  H = pend([q p])   or   M = pend()  == 1
%
%   Nonlinear pendulum, second order form.
%
%   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     % M
    y1 = 1; 
elseif nargin==1 % Hamiltonian
    q = t(:,1);
    p = t(:,2);
    y1 = .5*p.^2 -cos(q);
else             % nargin==2 => vector field
    y1 = -sin(q);
end
return