function t = chebyshev_polynomial ( m, n, x )

%*****************************************************************************80
%
%% chebyshev_polynomial() evaluates Chebyshev polynomials T(N,X).
%
%  First terms:
%
%    T(0,X) =  1
%    T(1,X) =  1 X
%    T(2,X) =  2 X^2 -   1
%    T(3,X) =  4 X^3 -   3 X
%    T(4,X) =  8 X^4 -   8 X^2 +  1
%    T(5,X) = 16 X^5 -  20 X^3 +  5 X
%    T(6,X) = 32 X^6 -  48 X^4 + 18 X^2 - 1
%    T(7,X) = 64 X^7 - 112 X^5 + 56 X^3 - 7 X
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 February 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, the number of evaluation points.
%
%    integer N, the order of the polynomial.
%
%    real X(M), the evaluation points.
%
%  Output:
%
%    real V(M), the values of the Chebyshev polynomial at X.
%
  t = zeros ( m, 1 );

  if ( n < 0 )
    return
  end

  v = zeros ( m, n + 1 );

  v(1:m,1) = 1.0;

  if ( n < 1 )
    t = ones ( m, 1 );
    return
  end

  x = x(:);

  v(1:m,2) = x(1:m,1);
 
  for i = 2 : n
    v(1:m,i+1) = 2.0 * x(1:m,1) .* v(1:m,i) - v(1:m,i-1);
  end
 
  t(1:m,1) = v(1:m,n+1);

  return
end
