function x = compressed_solve ( A, b )

%*****************************************************************************80
%
%% compressed_solve() seeks a maximally-zero solution of an underdetermined system.
%
%  Discussion:
%
  [ m, n ] = size ( A );
%
%  Get the QR factorization, with pivoting: A(:,P) = Q * R
%  The 'vector' option in the qr command returns P as a permutation vector.
%  P is a reordering of the columns of A which reduces fillin in R.
%
  [ Q, R, p ] = qr ( A, 'vector' );
%
%  Form and solve the reduced system:
%
  r = rank ( A );
  y = Q(:,1:r)' * b;
  X = R(1:r,1:r);
%
%  Start with a full vector of zeros.
%  Compute the solution of the reduced system and patch it into the full vector.
%
  x = zeros ( n, 1 );
  x(p(1:r)) = R(1:r,1:r) \ y;

  return
end

