function h = kepler_conserved ( pq )

%*****************************************************************************80
%
%% kepler_conserved evaluates a conserved quantity of a Kepler ODE.
%
%  Discussion:
%
%    We consider a Kepler two-body gravitational problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    26 February 2020
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Ernst Hairer, Christian Lubich, Gerhard Wanner,
%    Geometric Numerical Integration:
%    Structure-Preserving Algorithms for Ordinary Differential Equations,
%    Springer, 2006,
%    ISSN: 0179-3632
%
%  Input:
%
%    real PQ(:,4): the current solution.
%
%  Output:
%
%    real H(:): the value of the conserved quantity.
%
  q1 = pq(:,1);
  q2 = pq(:,2);
  p1 = pq(:,3);
  p2 = pq(:,4);

  h = 0.5 * ( p1.^2 + p2.^2 ) - 1.0 ./ sqrt ( q1.^2 + q2.^2 );

  return
end
