function x = chebyshev_lobatto_grid ( n )

%*****************************************************************************80
%
%% chebyshev_lobatto_grid(): n point Chebyshev Lobatto grid in [-1,+1].
%
%  Discussion:
%
%    The points are returned from left to right.
%
%    The rule is defined on [-1,1].
%
%    If n = 1, x = -0
%    If n = 2, x = [ -1, +1]
%    For 2 <= n, the first point is always = -1, the last is always +1.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 February 2024
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John Boyd,
%    Finding the Zeros of a Univariate Equation: Proxy Rootfinders,
%    Chebyshev Interpolation, and the Compation Matrix,
%    SIAM Review,
%    Volume 55, Number 2, pages 375-396, June 2013.
%
%  Input:
%
%    integer n: the order of the rule.  1 <= n
%
%  Output:
%
%    real x(n,1): the Chebyshev Lobatto grid points.
%
  x = zeros ( n, 1 );

  if ( n < 1 )

    fprintf ( 1, '\n' );
    fprintf ( 1, 'chebyshev_lobatto_grid: Fatal error!\n' );
    fprintf ( 1, '  n < 1\n' );

    error ( 'chebyshev_lobatto_grid: Fatal error!' );
  
  elseif ( n == 1 )

    x(1) = 0.0;

  else

    x = cos ( linspace ( pi, 0.0, n ) );

    x(1) = -1.0;
    if ( mod ( n, 2 ) == 1 )
      x((n+1)/2) = 0.0;
    end
    x(n) = +1.0;

  end

  return
end

