function [ u, values, avg ] = svd_vectors ( a, numvecs )

%*****************************************************************************80
%
%% svd_vectors() gets some SVD vectors.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 December 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A(M,N), an array of data.
%
%    integer NUMVECS, the number of vectors requested.
%    NUMVECS <= N.
%
%  Output:
%
%    real U(M,NUMVECS), the requested vectors.
%
%    real VALUES(N), all the singular values.
%
%    real AVG(M), the average vector.
%
  [ m, n ] = size ( a );
%
%  Compute the average.
%
  avg = mean ( a' )';
%
%  Subtract the average from each column of A.
%
  for j = 1 : n
    a(:,j) = a(:,j) - avg;
  end
%
%  Compute the economic SVD:
%
  [ u, d, v ] = svd ( a, 'econ' );
%
%  Cut U down to length NUMVECS.
%
  u = u(:,1:numvecs);
%
%  Return singular values as a vector.
%
  values = diag ( d );

  return
end
