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