function h = schroedinger_nonlinear_conserved ( x, u )

%*****************************************************************************80
%
%% schroedinger_nonlinear_conserved evaluates the conserved quantity.
%
%  Discussion:
%
%    The integral of |U|^2 over the region should be conserved.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    03 February 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Willem Hundsdorfer, Jan Verwer,
%    Numerical solution of time-dependent advection-diffusion-reaction equations,
%    Springer, 2003
%    ISBN: 978-3-662-09017-6
%
%  Input:
%
%    real X(1,NX), the coordinates of the nodes.
%
%    real U(1,NX), the current solution.
%
%  Output:
%
%    real H, the value of the conserved quantity.
%
  nx = size ( x, 2 );
  dx = ( max ( x ) - min ( x ) ) / ( nx - 1 );
  y = ( abs ( u ) ).^2;
%
%  Apply trapezoid rule to estimate integral.
%
  h = ( - 0.5 * y(i) + sum ( y ) - 0.5 * y(nx) ) * dx;

  return
end

