Sporth

sporth is a function that computes an orthonormal basis for the range 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 orth(full(S)). This function is useful in particular for computing the rank of a sparse matrix without having to use the (slow) rank(full(S)) or the (often inaccurate) sprank(S).

Syntax

 * Q = sporth(S)
 * Q = sporth(S,TOL)
 * [Q,r] = sporth(S,TOL)

Input arguments

 * S: The matrix to have its range computed.
 * TOL</tt> (optional, default norm(S,'fro') * eps(class(S))</tt>): The numerical tolerance used.

Output arguments

 * Q</tt>: A matrix whose columns form an orthonormal basis for the range of S</tt>.
 * r</tt> (optional): The rank of S</tt>.

Examples
The following example gives a 4-by-4 matrix whose range is spanned by the two vectors $[1,0,0,0]^T$ and $[0,0,1,0]^T$:

Note that the output is sparse because S</tt> is sparse. If the input is full then the output will be full as well:

If we just want to compute the rank of S</tt>, we can do the following: