|Returns a sparse orthonormal basis for the null space|
|Other toolboxes required||none|
|Function category||Helper functions|
|This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.|
spnull is a function that computes an orthonormal basis for the null space of a full or sparse matrix. When the matrix is sparse, this computation is performed via the QR decomposition and is typically much faster than using null(full(S)).
- Z = spnull(S)
- Z = spnull(S,varargin)
- S: The matrix to have its null space computed.
- varargin (optional): Extra arguments that, if S is full, will be passed to MATLAB's null function.
The following example gives a 4-by-4 matrix whose null space is spanned by the two vectors $[0,0,1,0]^T$ and $[0,0,0,1]^T$:
Note that the output is sparse because S is sparse. If the input is full then the output will be full as well:
Click on "expand" to the right to view the MATLAB source code for this function.
% Z = SPNULL(S)
% returns a sparse orthonormal basis for the null space of S, that is,
% S*Z has negligible elements, and Z'*Z = I
% If S is sparse, Z is obtained from the QR decomposition.
% Otherwise, Z is obtained from the SVD decomposition
% Bruno Luong <firstname.lastname@example.org>
% 10-May-2010: original version
% See also SPORTH, NULL, QR, SVD, ORTH, RANK
[m n] = size(S);
[Q R E] = qr(S.'); %#ok %full QR
if m > 1
s = diag(R);
elseif m == 1
s = R(1);
s = 0;
s = abs(s);
r = sum(s > tol);
Z = Q(:,r+1:n);
% sparse QR is not available on old Matlab versions
err = lasterror(); %#ok
if strcmp(err.identifier, 'MATLAB:maxlhs')
else % Full matrix
- Sparse null space and orthogonal: The source of this file on MATLAB File Exchange