function l = laplacian3_interval_uneven ( u, x )

%*****************************************************************************80
%
%% laplacian3_interval_uneven() approximates the laplacian on a 1D interval.
%
%  Discussion:
%
%    The domain is represented by nx unequally spaced points.
%
%    The laplacian is computed for the interior points, but a value
%    of 0 is returned for the first and last points.
%
%    It is up to the user to decide whether to reset l(1) and l(nx)
%    to nonzero values.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 September 2024
%
%  Input:
%
%    real u(nx): the values of a function on a grid of points.
%
%    real x(nx): the coordinates of each point.
%
%  Output:
%
%    real l(nx): the estimate for the laplacian.
%
  nx = length ( u );

  l = zeros ( size ( u ) );

  for i = 2 : nx - 1

    dxl = x(i)   - x(i-1);
    dxr = x(i+1) - x(i);

    alpha =  2.0 *   dxr         / dxl / ( dxl + dxr ) / dxr;
    beta = - 2.0 * ( dxr + dxl ) / dxl / ( dxl + dxr ) / dxr;
    gamma =  2.0 *         dxl   / dxl / ( dxl + dxr ) / dxr;

    l(i) = alpha * u(i-1) + beta * u(i) + gamma * u(i+1);

  end

  return
end

