557
|
1 function retval = orth (A, tol) |
|
2 |
|
3 # usage: orth (A, tol) |
|
4 # orth (A) |
|
5 # |
|
6 # Returns an orthonormal basis of the range of A. |
|
7 # |
|
8 # The dimension of the range space is taken as the number of singular |
|
9 # values of A greater than tol; the default for tol is |
|
10 # max (size (A)) * sigma_max (A) * eps, where sigma_max (A) is the |
|
11 # maximal singular value of A. |
|
12 |
|
13 # written by KH (Kurt.Hornik@neuro.tuwien.ac.at) on Dec 24, 1993 |
|
14 # copyright Dept of Probability Theory and Statistics TU Wien |
|
15 |
|
16 [U, S, V] = svd (A); |
|
17 |
|
18 [rows, cols] = size (A); |
|
19 |
|
20 s = diag (S); |
|
21 |
|
22 if (nargin == 1) |
|
23 tol = max (size (A)) * s (1) * eps; |
|
24 else if (nargin != 2) |
|
25 error ("usage: orth (A [, tol])"); |
|
26 endif |
|
27 |
|
28 rank = sum (s > tol); |
|
29 |
|
30 if (rank > 0) |
|
31 retval = -U (:, 1:rank); |
|
32 else |
|
33 retval = zeros (rows, 0); |
|
34 endif |
|
35 |
|
36 endfunction |