GNU Octave  4.2.1
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-2017 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 #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).is_sparse_type ())
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).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:52
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
double rcond(void) const
Definition: dMatrix.cc:1154
JNIEnv void * args
Definition: ov-java.cc:67
double rcond(void) const
Definition: CMatrix.cc:1459
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_value retval
Definition: data.cc:6294
Definition: dMatrix.h:37
float rcond(void) const
Definition: fMatrix.cc:1160
float rcond(void) const
Definition: fCMatrix.cc:1458