function dudt = schroedinger_nonlinear_deriv ( t, u, x )

%*****************************************************************************80
%
%% schroedinger_nonlinear_deriv(): right hand side of NLSE.
%
%  Discussion:
%
%    In order to get this problem to exhibit the behavior described by
%    Hundsdorfer, we had to use the negative of the derivative.  We are
%    currently at a loss to explain why this should be so.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 March 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Willem Hundsdorfer, Jan Verwer,
%    Numerical solution of time-dependent advection-diffusion-reaction equations,
%    Springer, 2003, page 128, page 209.
%    ISBN: 978-3-662-09017-6
%
%  Input:
%
%    real T: the current time.
%
%    complex U(NX): the current solution.
%
%    real X(NX): the spatial coordinates of the nodes.
%
%  Output:
%
%    complex DUDT(NX), the right hand sides of the ODEs.
%
  nx = length ( x );
%
%  Get parameter values:
%
  [ alpha, c1, c2, delta, gamma, t0, xmin, xmax ] = ...
    schroedinger_nonlinear_parameters ( );
%
%  Setting up im1, i, ip1 allows us to define the centered spatial difference
%  with zero Neumann boundary conditions.
%
  Im1 = [ 2,  1:nx-2, nx-1 ];
  I   = [ 1,  2:nx-1, nx   ];
  Ip1 = [ 2,  3:nx,   nx-1 ];
  
  dx = ( xmax - xmin ) / ( nx - 1 );
  uxx = ( u(Ip1) - 2.0 * u(I) + u(Im1) ) / dx^2;
%
%  Form the right hand side of the system of ODEs.
%
  dudt = i * uxx + i * gamma * ( abs ( u ) ).^2 .* u;
%
%  Force dudt to be a column vector.
%
  dudt = dudt ( : );

  return
end

