function c = t_polynomial_project_data ( a, b, m, n, x, d )

%*****************************************************************************80
%
%% t_polynomial_project_data(): Chebyshev coefficients from data values.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 March 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A, B, the domain of definition.
%
%    integer M, the number of data values.
%
%    integer N, the desired order of the Chebyshev expansion.
%
%    real X(M,1), the data abscissas.  These need not be sorted.
%    It must be the case that A <= X() <= B.
%
%    real D(M,1), the data values.
%
%  Output:
%
%    real C(N+1,1), the approximate Chebshev coefficients.
%
  x = x(:);
  d = d(:);

  if ( ~ r8vec_is_in_ab ( m, x, a, b ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'T_POLYNOMIAL_PROJECT_DATA- Fatal error!\n' );
    fprintf ( 1, '  Some X not in [A,B].\n' );
    error ( 'T_POLYNOMIAL_PROJECT_DATA - Fatal error!' )
  end
%
%  Compute the M by N+1 Chebyshev Vandermonde matrix.
%
  a = t_polynomial_ab ( a, b, m, n, x );
%
%  Compute the least-squares solution.
%
  c = a \ d;

  return
end
