1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} null (@var{A})
21 ## @deftypefnx {Function File} {} null (@var{A}, @var{tol})
22 ## Return an orthonormal basis of the null space of @var{A}.
24 ## The dimension of the null space is taken as the number of singular
25 ## values of @var{A} not greater than @var{tol}. If the argument @var{tol}
26 ## is missing, it is computed as
29 ## max (size (@var{A})) * max (svd (@var{A})) * eps
34 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
35 ## Created: 24 December 1993.
38 function retval = null (A, tol)
45 [rows, cols] = size (A);
47 [S_nr, S_nc] = size (S);
49 if (S_nr == 1 || S_nc == 1)
56 if (isa (A, "single"))
57 tol = max (size (A)) * s (1) * eps ("single");
59 tol = max (size (A)) * s (1) * eps;
68 retval = V (:, rank+1:cols);
69 if (isa (A, "single"))
70 retval(abs (retval) < eps ("single")) = 0;
72 retval(abs (retval) < eps) = 0;
75 retval = zeros (cols, 0);
83 %! assert(null(A), 1);
87 %! assert(null(A), zeros(1,0))
91 %! assert(null(A), zeros(2,0));
95 %! assert(null(A), [0 1]')
99 %! assert(null(A), [-1/sqrt(2) 1/sqrt(2)]', eps)
103 %! A = [1 0; 0 tol-eps];
104 %! assert(null(A,tol), [0 1]')
108 %! A = [1 0; 0 tol+eps];
109 %! assert(null(A,tol), zeros(2,0));