2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
1026
|
18 |
3372
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} orth (@var{a}, @var{tol}) |
|
21 ## Return an orthonormal basis of the range space of @var{a}. |
3426
|
22 ## |
2311
|
23 ## The dimension of the range space is taken as the number of singular |
3372
|
24 ## values of @var{a} greater than @var{tol}. If the argument @var{tol} is |
|
25 ## missing, it is computed as |
3426
|
26 ## |
3372
|
27 ## @example |
|
28 ## max (size (@var{a})) * max (svd (@var{a})) * eps |
|
29 ## @end example |
|
30 ## @end deftypefn |
557
|
31 |
5428
|
32 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312
|
33 ## Created: 24 December 1993. |
|
34 ## Adapted-By: jwe |
557
|
35 |
2312
|
36 function retval = orth (A, tol) |
557
|
37 |
3141
|
38 if (nargin == 1 || nargin == 2) |
557
|
39 |
3141
|
40 [U, S, V] = svd (A); |
557
|
41 |
3141
|
42 [rows, cols] = size (A); |
1065
|
43 |
3141
|
44 [S_nr, S_nc] = size (S); |
|
45 |
|
46 if (S_nr == 1 || S_nc == 1) |
|
47 s = S(1); |
|
48 else |
|
49 s = diag (S); |
|
50 endif |
557
|
51 |
3141
|
52 if (nargin == 1) |
|
53 tol = max (size (A)) * s (1) * eps; |
|
54 endif |
|
55 |
|
56 rank = sum (s > tol); |
557
|
57 |
3141
|
58 if (rank > 0) |
|
59 retval = -U (:, 1:rank); |
|
60 else |
|
61 retval = zeros (rows, 0); |
|
62 endif |
557
|
63 |
|
64 else |
3141
|
65 |
6046
|
66 print_usage (); |
3141
|
67 |
557
|
68 endif |
|
69 |
|
70 endfunction |