function h = wave_conserved ( w )

%*****************************************************************************80
%
%% wave_conserved() returns a conserved quantity for the wave PDE.
%
%  Discussion:
%
%    This conserved quantity can be regarded as the total energy of
%    the system.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 December 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real w(nx*2): the current solution.
%
%  Output:
%
%    real h: the value of the conserved quantity.
%
  [ xmin, xmax, nx, dx, c, t0 ] = wave_parameters ( );

  u = w(:,   1:  nx);
  v = w(:,nx+1:2*nx);

  ux = dbydx_pp ( u, dx ); 

  uxsq = integral_pp ( ux.^2, dx );
  utsq = integral_pp ( v.^2, dx );

  h = 0.5 * ( c^2 * uxsq + utsq );

  return
end

