function dudt = allen_cahn_deriv ( t, u, x, xi, nu )

%*****************************************************************************80
%
%% allen_cahn_deriv returns the right hand side of the allen-cahn ODE.
%
%  Discussion:
%
%    This version of the equation has the form:
%
%      du/dt = nu * uxx - u * (u^2-1) / (2*xi)
%
%    uxx is the second derivative of u with respect to x;
%    nu is a positive diffusion coefficient;
%    xi is a positive parameter called the interface thickness.
%
%    Zero Neumann boundary conditions are assumed, and so we
%    set dudt(1) = dudt(2) and dudt(nx) = dudt(nx-1).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 June 2020
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Jian Zhang, Qiang Du,
%    Numerical studies of discrete approximations to the Allen-Cahn
%    equation in the sharp interface limit,
%    SIAM Journal on Scientific Computing,
%    Volume 31, Number 4, pages 3042-3063, 2009.
%
%  Input:
%
%    real T, the current time.
%
%    real U(*): the current state values.
%
%    real X(*): the node coordinates.
%
%    real XI: the interface thickness.
%
%    real NU: the diffusion coefficient.
%
%  Output:
%
%    real DUDT(*), the time derivatives of the current state values.
%
  uxx = laplacian_interval ( u, x );

  dudt = nu * uxx - u .* ( u.^2 - 1.0 ) / ( 2.0 * xi^2 );
%
%  Apply boundary conditions.
%
  dudt(1) = dudt(2);
  dudt(end) = dudt(end-1);
%
%  Moronic inconsistent MATLAB demands column vector output.
%
  dudt = dudt(:);

  return
end

