function c = t_project_coefficients2 ( n, f )

%*****************************************************************************80
%
%% t_project_coefficients2(): function projected onto Chebyshev polynomials T(n,x).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 March 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the highest order polynomial to compute.
%
%    function handle F, of the form
%      function v = f ( x )
%
%  Output:
%
%    real C(N+1,1), projection coefficients for T(0,x) through T(n,x).
%
  bma = 1.0;
  bpa = 0.0;
  for k = 1 : n + 1
    y = cos ( pi * ( k - 0.5 ) / ( n + 1 ) );
    d(k) = f ( y );
  end

  fac = 2.0 / ( n + 1 );
  for j = 1 : ( n + 1 )
    sum = 0.0;
    for k = 1 : ( n + 1 )
      sum = sum + d(k) * cos ( ( pi * ( j - 1 ) ) * ( ( k - 0.5 ) / ( n + 1 ) ) );
    end
    c(j) = fac * sum;
  end

  c(1) = c(1) / 2.0;

  return
end

