diff src/DLD-FUNCTIONS/inv.cc @ 3808:885b296ef83a

[project @ 2001-03-27 19:12:58 by jwe]
author jwe
date Tue, 27 Mar 2001 19:12:59 +0000
parents ab7fa5a8f23f
children ccfdb55c8156
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/inv.cc	Thu Mar 08 21:21:33 2001 +0000
+++ b/src/DLD-FUNCTIONS/inv.cc	Tue Mar 27 19:12:59 2001 +0000
@@ -30,11 +30,13 @@
 #include "oct-obj.h"
 #include "utils.h"
 
-DEFUN_DLD (inv, args, ,
+DEFUN_DLD (inv, args, nargout,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} inv (@var{a})\n\
-@deftypefnx {Loadable Function} {} inverse (@var{a})\n\
-Compute the inverse of the square matrix @var{a}.\n\
+@deftypefn {Loadable Function} {[@var{x}, @var{rcond}] = } inv (@var{a})\n\
+@deftypefnx {Loadable Function} {[@var{x}, @var{rcond}] = } inverse (@var{a})\n\
+Compute the inverse of the square matrix @var{a}.  Return an estimate\n\
+of the reciprocal condition number if requested, otherwise warn of an\n\
+ill-conditioned matrix if the reciprocal condition number is small.\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -74,9 +76,14 @@
 	  int info;
 	  double rcond = 0.0;
 
-	  retval = m.inverse (info, rcond, 1);
+	  Matrix result = m.inverse (info, rcond, 1);
 
-	  if (info == -1)
+	  if (nargout > 1)
+	    retval(1) = rcond;
+
+	  retval(0) = result;
+
+	  if (nargout < 2 && info == -1)
 	    warning ("inverse: matrix singular to machine precision,\
  rcond = %g", rcond);
 	}
@@ -90,9 +97,14 @@
 	  int info;
 	  double rcond = 0.0;
 
-	  retval = m.inverse (info, rcond, 1);
+	  ComplexMatrix result = m.inverse (info, rcond, 1);
 
-	  if (info == -1)
+	  if (nargout > 1)
+	    retval(1) = rcond;
+
+	  retval(0) = result;
+
+	  if (nargout < 2 && info == -1)
 	    warning ("inverse: matrix singular to machine precision,\
  rcond = %g", rcond);
 	}