Mercurial > hg > octave-lyh
annotate scripts/linear-algebra/null.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} {} null (@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 null space of @var{A}. |
3426 | 22 ## |
2311 | 23 ## The dimension of the null 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} not greater than @var{tol}. If the argument @var{tol} |
3372 | 25 ## is 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{orth} |
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 = 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) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
55 if (isa (A, "single")) |
10549 | 56 tol = max (size (A)) * s (1) * eps ("single"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
57 else |
10549 | 58 tol = max (size (A)) * s (1) * eps; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
59 endif |
4371 | 60 elseif (nargin != 2) |
6046 | 61 print_usage (); |
4371 | 62 endif |
557 | 63 |
4371 | 64 rank = sum (s > tol); |
65 | |
66 if (rank < cols) | |
67 retval = V (:, rank+1:cols); | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
68 if (isa (A, "single")) |
10549 | 69 retval(abs (retval) < eps ("single")) = 0; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
70 else |
10549 | 71 retval(abs (retval) < eps) = 0; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
72 endif |
4371 | 73 else |
74 retval = zeros (cols, 0); | |
75 endif | |
557 | 76 endif |
77 | |
78 endfunction |