function C = chebyshev_interpolation_matrix ( n )

%*****************************************************************************80
%
%% chebyshev_interpolation_matrix() computes Chebyshev interpolation matrix.
%
%  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 C(n,n): the Chebyshev interpolation matrix.
%
  for i = 1 : n

    if ( i == 1 || i == n )
      qi = 2.0;
    else
      qi = 1.0;
    end

    for j = 1 : n

      if ( j == 1 | j == n )
        qj = 2.0;
      else
        qj = 1.0;
      end

      C(i,j) = 2.0 / qi / qj / ( n - 1 ) ...
        * cos ( ( i - 1 ) * ( j - 1 ) * pi / ( n - 1 ) );
 
    end

  end

