1function Nexp = spqr_explicit_basis (N, type) 2%SPQR_EXPLICIT_BASIS converts a null space basis to an explicit matrix 3% 4% Convert a orthonormal null space bases stored implicitly and created 5% by spqr_basic, spqr_null, spqr_pinv, or spqr_cod to an an explicit 6% sparse, or optionally full, matrix. If the input is not a implicit null 7% space bases the input is returned unchanged. 8% 9% Examples: 10% A = sparse(gallery('kahan',100)); 11% N = spqr_null(A); % creates an implicit null space basis 12% Nexp = spqr_explicit_basis (N) ; % converts to a sparse matrix 13% Nexp = spqr_explicit_basis (N,'full') ; % converts to a dense matrix 14% 15% Note that the dense matrix basis will require less memory than the implicit 16% basis if whos_N.bytes > ( prod(size(N.X)) * 8 ) where whos_N = whos('N'). 17% 18% See also spqr_basic, spqr_null, spqr_cod, spqr_pinv, spqr_null_mult. 19 20% Copyright 2012, Leslie Foster and Timothy A. Davis 21 22is_implicit_basis = ... 23 isstruct(N) && isfield(N,'Q') && isfield(N,'X') ; 24 25if is_implicit_basis && nargin == 1 26 Nexp = spqr_null_mult(N,speye(size(N.X,2)),1) ; 27elseif is_implicit_basis && nargin == 2 && strcmp(type,'full') 28 % Nexp = spqr_null_mult(N,eye(size(N.X,2)),1) ; % slow for large nullity 29 Nexp = spqr_null_mult(N,speye(size(N.X,2)),1) ; 30 Nexp = full(Nexp) ; 31else 32 Nexp = N ; 33end 34 35