function h = henon_heiles_conserved ( y )

%*****************************************************************************80
%
%% henon_heiles_conserved(): conserved quantities for henon_heiles_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Michel Henon, Carl Heiles,
%    The applicability of the third integral of motion: 
%    Some numerical experiments,
%    The Astronomical Journal,
%    Volume 69, pages 73-79, 1964.
%
%  Input:
%
%    real Y(N,4): the current coordinates.
%
%  Output:
%
%    real H(N): the conserved quantities.
%
  [ e, lam, t0, y0, tstop ] = henon_heiles_parameters ( );

  u =  y(:,1);
  up = y(:,2);
  v =  y(:,3);
  vp = y(:,4);

  h = 0.5 * ( up.^2 + vp.^2 ) + 0.5 * ( u.^2 + v.^2 ) ...
    + lam * ( u.^2 .* v - v.^3 / 3.0 );

  return
end

