function A = least_squares_approximant_matrix ( n, x, m )

%*****************************************************************************80
%
%% least_squares_approximant_matrix() computes the LS approximant matrix.
%
%  Discussion:
%
%    We assume the least squares polynomial has the form
%
%      p(x) = c1 + c2 * x + c3 * x^2 + ... + cm * x^(m-1).
%
%    We have n data values (x(i),y(i)) to be approximated:
%
%      p(x(i)) = c1 + c2 * x(i) + c3 * x(i)^2 + ... + cm * x(i)^(m-1) = y(i)
%
%    This can be cast as an NxM linear system for the polynomial
%    coefficients:
%
%      [ 1 x1 x1^2 ... x1^(m-1) ] [  c1 ] = [  y1 ]
%      [ 1 x2 x2^2 ... x2^(m-1) ] [  c2 ] = [  y2 ]
%      [ ...................... ] [ ... ] = [ ... ]
%      [ 1 xn xn^2 ... xn^(m-1) ] [  cm ] = [  yn ]
%
%    and this system can be solved by:
%    * the normal equations;
%    * the QR factorization;
%    * the SVD factorization.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 July 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of data points.
%
%    real X(N,1), the data values.
%
%    integer M, the polynomial order.
%
%  Output:
%
%    real A(N,M), the least squares matrix for X.
% 
  A = ( x(:) * ones(1,m) ) .^ ( ones(n,1) * (0:m-1) );

  return
end
