Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/orth.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | eb9e0b597d61 |
children | 7ef7e20057fa |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 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 -*- |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
20 ## @deftypefn {Function File} {} orth (@var{A}, @var{tol}) |
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
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 |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
24 ## values of @var{A} greater than @var{tol}. If the argument @var{tol} is |
3372 | 25 ## missing, it is computed as |
3426 | 26 ## |
3372 | 27 ## @example |
11470
eb9e0b597d61
Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
28 ## max (size (@var{A})) * max (svd (@var{A})) * eps |
3372 | 29 ## @end example |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
30 ## @seealso{null} |
3372 | 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) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
54 if (isa (A, "single")) |
10549 | 55 tol = max (size (A)) * s (1) * eps ("single"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
56 else |
10549 | 57 tol = max (size (A)) * s (1) * eps; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
58 endif |
3141 | 59 endif |
60 | |
61 rank = sum (s > tol); | |
557 | 62 |
3141 | 63 if (rank > 0) |
64 retval = -U (:, 1:rank); | |
65 else | |
66 retval = zeros (rows, 0); | |
67 endif | |
557 | 68 |
69 else | |
3141 | 70 |
6046 | 71 print_usage (); |
3141 | 72 |
557 | 73 endif |
74 | |
75 endfunction |