GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rcond.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2015 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.h"
28 #include "error.h"
29 #include "gripes.h"
30 #include "oct-obj.h"
31 #include "utils.h"
32 
33 DEFUN (rcond, args, ,
34  "-*- texinfo -*-\n\
35 @deftypefn {Built-in Function} {@var{c} =} rcond (@var{A})\n\
36 Compute the 1-norm estimate of the reciprocal condition number as returned\n\
37 by @sc{lapack}.\n\
38 \n\
39 If the matrix is well-conditioned then @var{c} will be near 1 and if the\n\
40 matrix is poorly conditioned it will be close to 0.\n\
41 \n\
42 The matrix @var{A} must not be sparse. If the matrix is sparse then\n\
43 @code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used\n\
44 instead.\n\
45 @seealso{cond, condest}\n\
46 @end deftypefn")
47 {
48  octave_value retval;
49 
50  int nargin = args.length ();
51 
52  if (nargin != 1)
53  print_usage ();
54  else if (args(0).is_sparse_type ())
55  error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
56  else if (args(0).is_single_type ())
57  {
58  if (args(0).is_complex_type ())
59  {
60  FloatComplexMatrix m = args(0).float_complex_matrix_value ();
61  MatrixType mattyp;
62  retval = m.rcond (mattyp);
63  args(0).matrix_type (mattyp);
64  }
65  else
66  {
67  FloatMatrix m = args(0).float_matrix_value ();
68  MatrixType mattyp;
69  retval = m.rcond (mattyp);
70  args(0).matrix_type (mattyp);
71  }
72  }
73  else if (args(0).is_complex_type ())
74  {
75  ComplexMatrix m = args(0).complex_matrix_value ();
76  MatrixType mattyp;
77  retval = m.rcond (mattyp);
78  args(0).matrix_type (mattyp);
79  }
80  else
81  {
82  Matrix m = args(0).matrix_value ();
83  MatrixType mattyp;
84  retval = m.rcond (mattyp);
85  args(0).matrix_type (mattyp);
86  }
87 
88  return retval;
89 }
90 
91 /*
92 %!assert (rcond (eye (2)), 1)
93 %!assert (rcond (ones (2)), 0)
94 %!assert (rcond ([1 1; 2 1]), 1/9)
95 %!assert (rcond (magic (4)), 0, eps)
96 
97 %!shared x, sx
98 %! x = [-5.25, -2.25; -2.25, 1] * eps () + ones (2) / 2;
99 %! sx = [-5.25, -2.25; -2.25, 1] * eps ("single") + ones (2) / 2;
100 %!assert (rcond (x) < eps ());
101 %!assert (rcond (sx) < eps ('single'));
102 %!assert (rcond (x*i) < eps ());
103 %!assert (rcond (sx*i) < eps ('single'));
104 
105 */
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
void error(const char *fmt,...)
Definition: error.cc:476
double rcond(void) const
Definition: dMatrix.cc:1392
double rcond(void) const
Definition: CMatrix.cc:1750
octave_idx_type length(void) const
Definition: ov.cc:1525
Definition: dMatrix.h:35
float rcond(void) const
Definition: fMatrix.cc:1403
float rcond(void) const
Definition: fCMatrix.cc:1754