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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1026
|
19 |
3372
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} null (@var{a}, @var{tol}) |
|
22 ## Return an orthonormal basis of the null space of @var{a}. |
3426
|
23 ## |
2311
|
24 ## The dimension of the null space is taken as the number of singular |
3372
|
25 ## values of @var{a} not greater than @var{tol}. If the argument @var{tol} |
|
26 ## is 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 = null (A, tol) |
557
|
38 |
4371
|
39 if (isempty (A)) |
|
40 retval = []; |
|
41 else |
|
42 [U, S, V] = svd (A); |
1065
|
43 |
4371
|
44 [rows, cols] = size (A); |
|
45 |
|
46 [S_nr, S_nc] = size (S); |
557
|
47 |
4371
|
48 if (S_nr == 1 || S_nc == 1) |
|
49 s = S(1); |
|
50 else |
|
51 s = diag (S); |
|
52 endif |
557
|
53 |
4371
|
54 if (nargin == 1) |
|
55 tol = max (size (A)) * s (1) * eps; |
|
56 elseif (nargin != 2) |
|
57 usage ("null (A, tol)"); |
|
58 endif |
557
|
59 |
4371
|
60 rank = sum (s > tol); |
|
61 |
|
62 if (rank < cols) |
|
63 retval = V (:, rank+1:cols); |
|
64 else |
|
65 retval = zeros (cols, 0); |
|
66 endif |
557
|
67 endif |
|
68 |
|
69 endfunction |