function g = gram_polynomial_evaluate ( n, m, x )

%*****************************************************************************80
%
%% gram_polynomial_evaluate evaluates a Gram polynomial.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 June 2019
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Germund Dahlquist, Ake Bjorck,
%    Numerical Methods in Scientific Computing,
%    Volume 1,
%    SIAM, 2008,
%    ISBN: 978-0-898716-44-3,
%    LC: QA297.D335 2008.
%    
%  Input:
%
%    integer n, the index of the polynomial.
%    n < m.
%
%    integer m, the number of points used in defining the polynomials.
%
%    real x(*), the evaluation points.
%
%  Output:
%
%    real g(*), the value of the polynomial at the points.
%
  x = x(:);
  k = length ( x );
  pnp1 = zeros ( k, 1 );

  for step = 0 : n
    if ( step == 0 )
      pn = zeros ( k, 1 );
      pnp1 = ones ( k, 1 );
    else
      pnm1 = pn;
      pn   = pnp1;
      pnp1 = x .* pn(:) - gram_beta ( step - 1, m ) * pnm1(:);
    end
  end 

  g = pnp1;

  return
end

