Mercurial > hg > octave-nkf
changeset 16952:3c20fb2aa419
doc: Add example to rank docstring.
* scripts/linear-algebra/rank.m: Add example to docstring. Add %!test
for empty matrix and for row and column vectors.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 11 Jul 2013 10:31:32 -0700 |
parents | a7c9be4a2c0f |
children | eb6fb224bda5 |
files | scripts/linear-algebra/rank.m |
diffstat | 1 files changed, 29 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/linear-algebra/rank.m +++ b/scripts/linear-algebra/rank.m @@ -19,7 +19,8 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} rank (@var{A}) ## @deftypefnx {Function File} {} rank (@var{A}, @var{tol}) -## Compute the rank of @var{A}, using the singular value decomposition. +## Compute the rank of matrix @var{A}, using the singular value decomposition. +## ## The rank is taken to be the number of singular values of @var{A} that ## are greater than the specified tolerance @var{tol}. If the second ## argument is omitted, it is taken to be @@ -31,6 +32,29 @@ ## @noindent ## where @code{eps} is machine precision and @code{sigma(1)} is the largest ## singular value of @var{A}. +## +## The rank of a matrix is the number of linearly independent rows or +## columns and determines how many particular solutions exist to a system +## of equations. Use @code{null} for finding the remaining homogenous +## solutions. +## +## Example: +## +## @example +## @group +## x = [1 2 3 +## 4 5 6 +## 7 8 9]; +## rank (x) +## @result{} 2 +## @end group +## @end example +## +## @noindent +## The number of linearly independent rows is only 2 because the final row +## is a linear combination of -1*row1 + 2*row2. +## +## @seealso{null, sprank, svd} ## @end deftypefn ## Author: jwe @@ -104,6 +128,10 @@ %! A = eye (100); %! assert (rank (A), 100); +%!assert (rank ([]), 0) +%!assert (rank ([1:9]), 1) +%!assert (rank ([1:9]'), 1) + %!test %! A = [1, 2, 3; 1, 2.001, 3; 1, 2, 3.0000001]; %! assert (rank (A), 3);