rcond.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 David Bateman
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "defun-dld.h"
00028 #include "error.h"
00029 #include "gripes.h"
00030 #include "oct-obj.h"
00031 #include "utils.h"
00032 
00033 DEFUN_DLD (rcond, args, ,
00034   "-*- texinfo -*-\n\
00035 @deftypefn {Loadable Function} {@var{c} =} rcond (@var{A})\n\
00036 Compute the 1-norm estimate of the reciprocal condition number as returned\n\
00037 by @sc{lapack}.  If the matrix is well-conditioned then @var{c} will be near\n\
00038 1 and if the matrix is poorly conditioned it will be close to zero.\n\
00039 \n\
00040 The matrix @var{A} must not be sparse.  If the matrix is sparse then\n\
00041 @code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used\n\
00042 instead.\n\
00043 @seealso{cond, condest}\n\
00044 @end deftypefn")
00045 {
00046   octave_value retval;
00047 
00048   int nargin = args.length ();
00049 
00050   if (nargin != 1)
00051     print_usage ();
00052   else if (args(0).is_sparse_type ())
00053     error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
00054   else if (args(0).is_single_type ())
00055     {
00056       if (args(0).is_complex_type ())
00057         {
00058           FloatComplexMatrix m = args(0).float_complex_matrix_value ();
00059           MatrixType mattyp;
00060           retval = m.rcond (mattyp);
00061           args(0).matrix_type (mattyp);
00062         }
00063       else
00064         {
00065           FloatMatrix m = args(0).float_matrix_value ();
00066           MatrixType mattyp;
00067           retval = m.rcond (mattyp);
00068           args(0).matrix_type (mattyp);
00069         }
00070     }
00071   else if (args(0).is_complex_type ())
00072     {
00073       ComplexMatrix m = args(0).complex_matrix_value ();
00074       MatrixType mattyp;
00075       retval = m.rcond (mattyp);
00076       args(0).matrix_type (mattyp);
00077     }
00078   else
00079     {
00080       Matrix m = args(0).matrix_value ();
00081       MatrixType mattyp;
00082       retval = m.rcond (mattyp);
00083       args(0).matrix_type (mattyp);
00084     }
00085 
00086   return retval;
00087 }
00088 
00089 /*
00090 
00091 %!assert( rcond (eye (2)), 1)
00092 %!assert( rcond (ones (2)), 0)
00093 %!assert( rcond ([1 1; 2 1]), 1/9)
00094 %!assert( rcond (magic (4)), 0, eps)
00095 
00096 %!shared x, sx
00097 %! x = [-5.25, -2.25; -2.25, 1] * eps () + ones (2) / 2;
00098 %! sx = [-5.25, -2.25; -2.25, 1] * eps ("single") + ones (2) / 2;
00099 %!assert (rcond (x) < eps ());
00100 %!assert (rcond (sx) < eps ('single'));
00101 %!assert (rcond (x*i) < eps ());
00102 %!assert (rcond (sx*i) < eps ('single'));
00103 
00104 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines