annotate scripts/linear-algebra/orth.m @ 3372:f16c2ce14886

[project @ 1999-11-23 19:07:09 by jwe]
author jwe
date Tue, 23 Nov 1999 19:07:18 +0000
parents 292ff0bf484b
children f8dde1807dee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2325
diff changeset
1 ## Copyright (C) 1996, 1997 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
8 ## any later version.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
18 ## 02111-1307, USA.
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 1022
diff changeset
19
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
20 ## -*- texinfo -*-
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
21 ## @deftypefn {Function File} {} orth (@var{a}, @var{tol})
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
22 ## Return an orthonormal basis of the range space of @var{a}.
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
23 ##
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
24 ## The dimension of the range space is taken as the number of singular
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
25 ## values of @var{a} greater than @var{tol}. If the argument @var{tol} is
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
26 ## missing, it is computed as
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
27 ##
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
28 ## @example
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
29 ## max (size (@var{a})) * max (svd (@var{a})) * eps
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
30 ## @end example
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3141
diff changeset
31 ## @end deftypefn
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
32
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
33 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
34 ## Created: 24 December 1993.
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
35 ## Adapted-By: jwe
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
36
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
37 function retval = orth (A, tol)
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
38
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
39 if (nargin == 1 || nargin == 2)
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
40
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
41 [U, S, V] = svd (A);
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
42
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
43 [rows, cols] = size (A);
1065
5eeb61cac52e [project @ 1995-01-25 14:04:13 by jwe]
jwe
parents: 1026
diff changeset
44
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
45 [S_nr, S_nc] = size (S);
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
46
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
47 if (S_nr == 1 || S_nc == 1)
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
48 s = S(1);
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
49 else
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
50 s = diag (S);
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
51 endif
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
52
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
53 if (nargin == 1)
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
54 tol = max (size (A)) * s (1) * eps;
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
55 endif
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
56
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
57 rank = sum (s > tol);
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
58
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
59 if (rank > 0)
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
60 retval = -U (:, 1:rank);
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
61 else
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
62 retval = zeros (rows, 0);
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
63 endif
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
64
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
65 else
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
66
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
67 usage ("orth (a [, tol]");
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 2847
diff changeset
68
557
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
69 endif
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
70
e6ae50d8d4eb [project @ 1994-07-25 20:23:22 by jwe]
jwe
parents:
diff changeset
71 endfunction