Difference between revisions of "Sporth"

From QETLAB
Jump to navigation Jump to search
(Uploaded v1.01)
 
Line 3: Line 3:
 
|desc=Returns a sparse orthonormal basis for the range
 
|desc=Returns a sparse orthonormal basis for the range
 
|upd=December 13, 2012
 
|upd=December 13, 2012
|v=1.01
+
|v=0.50
 
|rel=[[spnull]]
 
|rel=[[spnull]]
 +
|cat=[[List of functions#Helper_functions|Helper functions]]
 
|lic=1
 
|lic=1
 
|helper=1}}
 
|helper=1}}
Line 25: Line 26:
 
==Examples==
 
==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$:
 
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$:
<pre>
+
<syntaxhighlight>
 
>> S = sparse(4,4);
 
>> S = sparse(4,4);
 
>> S(1,1) = 1; S(3,2) = 1;
 
>> S(1,1) = 1; S(3,2) = 1;
Line 34: Line 35:
 
   (1,1)        1
 
   (1,1)        1
 
   (3,2)        1
 
   (3,2)        1
</pre>
+
</syntaxhighlight>
  
 
Note that the output is sparse because <tt>S</tt> is sparse. If the input is full then the output will be full as well:
 
Note that the output is sparse because <tt>S</tt> is sparse. If the input is full then the output will be full as well:
<pre>
+
<syntaxhighlight>
 
>> sporth(full(S))
 
>> sporth(full(S))
  
Line 46: Line 47:
 
     0    -1
 
     0    -1
 
     0    0
 
     0    0
</pre>
+
</syntaxhighlight>
  
 
If we just want to compute the rank of <tt>S</tt>, we can do the following:
 
If we just want to compute the rank of <tt>S</tt>, we can do the following:
<pre>
+
<syntaxhighlight>
 
>> [~,r] = sporth(S)
 
>> [~,r] = sporth(S)
  
Line 55: Line 56:
  
 
     2
 
     2
</pre>
+
</syntaxhighlight>
 +
 
 +
{{SourceCode|name=sporth|helper=1}}
  
 
==External links==
 
==External links==
 
* [http://www.mathworks.com/matlabcentral/fileexchange/27550-sparse-null-space-and-orthogonal Sparse null space and orthogonal]: The source of this file on MATLAB File Exchange
 
* [http://www.mathworks.com/matlabcentral/fileexchange/27550-sparse-null-space-and-orthogonal Sparse null space and orthogonal]: The source of this file on MATLAB File Exchange

Latest revision as of 16:30, 29 September 2014

sporth
Returns a sparse orthonormal basis for the range

Other toolboxes required none
Related functions spnull
Function category Helper functions
License license_sporth.txt
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.

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)

Argument descriptions

Input arguments

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

Output arguments

  • Q: A matrix whose columns form an orthonormal basis for the range of S.
  • r (optional): The rank of S.

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$:

>> S = sparse(4,4);
>> S(1,1) = 1; S(3,2) = 1;
>> sporth(S)

ans =

   (1,1)        1
   (3,2)        1

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

>> sporth(full(S))

ans =

     1     0
     0     0
     0    -1
     0     0

If we just want to compute the rank of S, we can do the following:

>> [~,r] = sporth(S)

r =

     2

Source code

Click here to view this function's source code on github.

External links