7788
|
1 /* |
|
2 |
|
3 Copyright (C) 2008 David Bateman |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "defun-dld.h" |
|
28 #include "error.h" |
|
29 #include "gripes.h" |
|
30 #include "oct-obj.h" |
|
31 #include "utils.h" |
|
32 |
|
33 DEFUN_DLD (rcond, args, , |
|
34 "-*- texinfo -*-\n\ |
|
35 @deftypefn {Loadable Function} {@var{c} =} rcond (@var{a})\n\ |
|
36 Compute the 1-norm estimate of the reciprocal condition as returned\n\ |
|
37 by LAPACK. If the matrix is well-conditioned then @var{c} will be near\n\ |
|
38 1 and if the matrix is poorly conditioned it will be close to zero.\n\ |
|
39 \n\ |
|
40 The matrix @var{a} must not be sparse. If the matrix is sparse then\n\ |
|
41 @code{condest (@var{a})} or @code{rcond (full (@var{a}))} should be used\n\ |
|
42 instead.\n\ |
|
43 @seealso{inv, mldivide}\n\ |
|
44 @end deftypefn") |
|
45 { |
|
46 octave_value retval; |
|
47 |
|
48 int nargin = args.length (); |
|
49 |
|
50 if (nargin != 1) |
|
51 print_usage (); |
|
52 else if (args(0).is_sparse_type ()) |
|
53 error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead"); |
|
54 else if (args(0).is_complex_type ()) |
|
55 { |
|
56 ComplexMatrix m = args(0).complex_matrix_value (); |
|
57 MatrixType mattyp; |
|
58 retval = m.rcond (mattyp); |
|
59 args(0).matrix_type (mattyp); |
|
60 } |
|
61 else |
|
62 { |
|
63 Matrix m = args(0).matrix_value (); |
|
64 MatrixType mattyp; |
|
65 retval = m.rcond (mattyp); |
|
66 args(0).matrix_type (mattyp); |
|
67 } |
|
68 |
|
69 return retval; |
|
70 } |