comparison scripts/linear-algebra/rank.m @ 4:b4df021f796c

[project @ 1993-08-08 01:26:08 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:26:08 +0000
parents
children 16a24e76d6e0
comparison
equal deleted inserted replaced
3:9a4c07481e61 4:b4df021f796c
1 function retval = rank (A, tol)
2
3 # usage: rand (a, tol)
4 #
5 # Return the rank of the matrix a. The rank is taken to be the number
6 # of singular values of a that are greater than tol.
7 #
8 # If the second argument is omitted, it is taken to be
9 #
10 # tol = max (size (a)) * sigma (1) * eps;
11 #
12 # where eps is machine precision and sigma is the largest singular
13 # value of a.
14
15 if (nargin == 1)
16 sigma = svd (A);
17 tolerance = max (size (A)) * sigma (1) * eps;
18 elseif (nargin == 2)
19 tolerance = tol;
20 else
21 error ("usage: rank (A)");
22 endif
23 retval = sum (sigma > tolerance);
24
25 endfunction