function [ nf, xf, wf, vf ] = line_fekete_legendre ( m, a, b, n, x )

%*****************************************************************************80
%
%% line_fekete_legendre() computes approximate Fekete points in an interval [A,B].
%
%  Discussion:
%
%    We use the uniform weight and the Legendre basis:
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 October 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Len Bos, Norm Levenberg,
%    On the calculation of approximate Fekete points: the univariate case,
%    Electronic Transactions on Numerical Analysis, 
%    Volume 30, pages 377-397, 2008.
%    
%  Input:
%
%    integer M, the number of basis polynomials.
%
%    real A, B, the endpoints of the interval.
%
%    integer N, the number of sample points.
%    M <= N.
%
%    real X(N), the coordinates of the sample points.
%
%  Output:
%
%    integer NF, the number of Fekete points.
%    If the computation is successful, NF = M.
%
%    real XF(NF), the coordinates of the Fekete points.
%
%    real WF(NF), the weights of the Fekete points.
%
%    real VF(NF,N), the nonsingular Vandermonde submatrix.
%
  if ( n < m )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'LINE_FEKETE_LEGENDRE - Fatal error!\n' );
    fprintf ( 1, '  N < M.\n' );
    error ( 'LINE_FEKETE_LEGENDRE - Fatal error!' );
  end
%
%  Compute the Legendre-Vandermonde matrix.
%
  v = legendre_van ( m, a, b, n, x );
%
%  "Moments" of shifted scaled Legendre polynomials, 
%    MOM(i) = integral ( A <= X <= B ) Lab(A,B,I;X) dx
%
  mom = zeros ( m, 1 );
  mom(1) = b - a;
%
%  Solve for weights.
%
% w = v \ mom;
  w = qr_factor_solve ( m, n, v, mom );

  ind = find ( w ~= 0.0 )

  nf = length ( ind );
  xf = x(ind);
  wf = w(ind);
  vf = ( v(:,ind) )';

  return
end

