GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
rcond.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "defun.h"
28 #include "error.h"
29 #include "errwarn.h"
30 #include "ovl.h"
31 #include "utils.h"
32 
33 DEFUN (rcond, args, ,
34  doc: /* -*- texinfo -*-
35 @deftypefn {} {@var{c} =} rcond (@var{A})
36 Compute the 1-norm estimate of the reciprocal condition number as returned
37 by @sc{lapack}.
38 
39 If the matrix is well-conditioned then @var{c} will be near 1 and if the
40 matrix is poorly conditioned it will be close to 0.
41 
42 The matrix @var{A} must not be sparse. If the matrix is sparse then
43 @code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used
44 instead.
45 @seealso{cond, condest}
46 @end deftypefn */)
47 {
48  if (args.length () != 1)
49  print_usage ();
50 
52 
53  if (args(0).issparse ())
54  error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
55 
56  if (args(0).is_single_type ())
57  {
58  if (args(0).iscomplex ())
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).iscomplex ())
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:54
float rcond(void) const
Definition: fMatrix.cc:1209
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:53
void error(const char *fmt,...)
Definition: error.cc:578
float rcond(void) const
Definition: fCMatrix.cc:1517
double rcond(void) const
Definition: dMatrix.cc:1202
octave_value retval
Definition: data.cc:6246
double rcond(void) const
Definition: CMatrix.cc:1516
Definition: dMatrix.h:36