diff liboctave/dMatrix.cc @ 7788:45f5faba05a2

Add the rcond function
author David Bateman <dbateman@free.fr>
date Wed, 14 May 2008 18:09:56 +0200
parents 36594d5bbe13
children 82be108cc558
line wrap: on
line diff
--- a/liboctave/dMatrix.cc	Tue May 13 21:12:12 2008 +0200
+++ b/liboctave/dMatrix.cc	Wed May 14 18:09:56 2008 +0200
@@ -651,44 +651,44 @@
 Matrix::inverse (void) const
 {
   octave_idx_type info;
-  double rcond;
+  double rcon;
   MatrixType mattype (*this);
-  return inverse (mattype, info, rcond, 0, 0);
+  return inverse (mattype, info, rcon, 0, 0);
 }
 
 Matrix
 Matrix::inverse (octave_idx_type& info) const
 {
-  double rcond;
+  double rcon;
   MatrixType mattype (*this);
-  return inverse (mattype, info, rcond, 0, 0);
+  return inverse (mattype, info, rcon, 0, 0);
 }
 
 Matrix
-Matrix::inverse (octave_idx_type& info, double& rcond, int force,
+Matrix::inverse (octave_idx_type& info, double& rcon, int force,
 		 int calc_cond) const
 {
   MatrixType mattype (*this);
-  return inverse (mattype, info, rcond, force, calc_cond);
+  return inverse (mattype, info, rcon, force, calc_cond);
 }
 
 Matrix
 Matrix::inverse (MatrixType& mattype) const
 {
   octave_idx_type info;
-  double rcond;
-  return inverse (mattype, info, rcond, 0, 0);
+  double rcon;
+  return inverse (mattype, info, rcon, 0, 0);
 }
 
 Matrix
 Matrix::inverse (MatrixType &mattype, octave_idx_type& info) const
 {
-  double rcond;
-  return inverse (mattype, info, rcond, 0, 0);
+  double rcon;
+  return inverse (mattype, info, rcon, 0, 0);
 }
 
 Matrix
-Matrix::tinverse (MatrixType &mattype, octave_idx_type& info, double& rcond, 
+Matrix::tinverse (MatrixType &mattype, octave_idx_type& info, double& rcon, 
 		  int force, int calc_cond) const
 {
   Matrix retval;
@@ -713,7 +713,7 @@
 				 F77_CHAR_ARG_LEN (1)));
 
       // Throw-away extra info LAPACK gives so as to not change output.
-      rcond = 0.0;
+      rcon = 0.0;
       if (info != 0) 
 	info = -1;
       else if (calc_cond) 
@@ -727,7 +727,7 @@
 	  F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&job, 1),
 				     F77_CONST_CHAR_ARG2 (&uplo, 1),
 				     F77_CONST_CHAR_ARG2 (&udiag, 1),
-				     nr, tmp_data, nr, rcond, 
+				     nr, tmp_data, nr, rcon, 
 				     work, iwork, dtrcon_info 
 				     F77_CHAR_ARG_LEN (1)
 				     F77_CHAR_ARG_LEN (1)
@@ -746,7 +746,7 @@
 
 
 Matrix
-Matrix::finverse (MatrixType &mattype, octave_idx_type& info, double& rcond, 
+Matrix::finverse (MatrixType &mattype, octave_idx_type& info, double& rcon, 
 		  int force, int calc_cond) const
 {
   Matrix retval;
@@ -786,7 +786,7 @@
       F77_XFCN (dgetrf, DGETRF, (nc, nc, tmp_data, nr, pipvt, info));
 
       // Throw-away extra info LAPACK gives so as to not change output.
-      rcond = 0.0;
+      rcon = 0.0;
       if (info != 0) 
 	info = -1;
       else if (calc_cond) 
@@ -799,7 +799,7 @@
 	  octave_idx_type *piz = iz.fortran_vec ();
 	  F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
 				     nc, tmp_data, nr, anorm, 
-				     rcond, pz, piz, dgecon_info
+				     rcon, pz, piz, dgecon_info
 				     F77_CHAR_ARG_LEN (1)));
 
 	  if (dgecon_info != 0) 
@@ -827,7 +827,7 @@
 }
 
 Matrix
-Matrix::inverse (MatrixType &mattype, octave_idx_type& info, double& rcond, 
+Matrix::inverse (MatrixType &mattype, octave_idx_type& info, double& rcon, 
 		 int force, int calc_cond) const
 {
   int typ = mattype.type (false);
@@ -837,7 +837,7 @@
     typ = mattype.type (*this);
 
   if (typ == MatrixType::Upper || typ == MatrixType::Lower)
-    ret = tinverse (mattype, info, rcond, force, calc_cond);
+    ret = tinverse (mattype, info, rcon, force, calc_cond);
   else
     {
       if (mattype.is_hermitian ())
@@ -846,9 +846,9 @@
 	  if (info == 0)
 	    {
 	      if (calc_cond)
-		rcond = chol.rcond ();
+		rcon = chol.rcond ();
 	      else
-		rcond = 1.0;
+		rcon = 1.0;
 	      ret = chol.inverse ();
 	    }
 	  else
@@ -856,9 +856,9 @@
 	}
 
       if (!mattype.is_hermitian ())
-	ret = finverse(mattype, info, rcond, force, calc_cond);
-
-      if ((mattype.is_hermitian () || calc_cond) && rcond == 0.)
+	ret = finverse(mattype, info, rcon, force, calc_cond);
+
+      if ((mattype.is_hermitian () || calc_cond) && rcon == 0.)
 	ret = Matrix (rows (), columns (), octave_Inf);
     }
 
@@ -1216,19 +1216,19 @@
 Matrix::determinant (void) const
 {
   octave_idx_type info;
-  double rcond;
-  return determinant (info, rcond, 0);
+  double rcon;
+  return determinant (info, rcon, 0);
 }
 
 DET
 Matrix::determinant (octave_idx_type& info) const
 {
-  double rcond;
-  return determinant (info, rcond, 0);
+  double rcon;
+  return determinant (info, rcon, 0);
 }
 
 DET
-Matrix::determinant (octave_idx_type& info, double& rcond, int calc_cond) const
+Matrix::determinant (octave_idx_type& info, double& rcon, int calc_cond) const
 {
   DET retval;
 
@@ -1257,7 +1257,7 @@
       F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info));
 
       // Throw-away extra info LAPACK gives so as to not change output.
-      rcond = 0.0;
+      rcon = 0.0;
       if (info != 0) 
 	{
 	  info = -1;
@@ -1276,7 +1276,7 @@
 
 	      F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
 					 nc, tmp_data, nr, anorm, 
-					 rcond, pz, piz, info
+					 rcon, pz, piz, info
 					 F77_CHAR_ARG_LEN (1)));
 	    }
 
@@ -1321,9 +1321,174 @@
   return retval;
 }
 
+double
+Matrix::rcond (void) const
+{
+  MatrixType mattype (*this);
+  return rcond (mattype);
+}
+
+double
+Matrix::rcond (MatrixType &mattype) const
+{
+  double rcon;
+  octave_idx_type nr = rows ();
+  octave_idx_type nc = cols ();
+
+  if (nr != nc)
+    (*current_liboctave_error_handler) ("matrix must be square");
+  else if (nr == 0 || nc == 0)
+    rcon = octave_Inf;
+  else
+    {
+      int typ = mattype.type ();
+
+      if (typ == MatrixType::Unknown)
+	typ = mattype.type (*this);
+
+      // Only calculate the condition number for LU/Cholesky
+      if (typ == MatrixType::Upper)
+	{
+	  const double *tmp_data = fortran_vec ();
+	  octave_idx_type info = 0;
+	  char norm = '1';
+	  char uplo = 'U';
+	  char dia = 'N';
+
+	  Array<double> z (3 * nc);
+	  double *pz = z.fortran_vec ();
+	  Array<octave_idx_type> iz (nc);
+	  octave_idx_type *piz = iz.fortran_vec ();
+
+	  F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
+				     F77_CONST_CHAR_ARG2 (&uplo, 1), 
+				     F77_CONST_CHAR_ARG2 (&dia, 1), 
+				     nr, tmp_data, nr, rcon,
+				     pz, piz, info
+				     F77_CHAR_ARG_LEN (1)
+				     F77_CHAR_ARG_LEN (1)
+				     F77_CHAR_ARG_LEN (1)));
+
+	  if (info != 0) 
+	    rcon = 0.0;
+	}
+      else if  (typ == MatrixType::Permuted_Upper)
+	(*current_liboctave_error_handler)
+	  ("permuted triangular matrix not implemented");
+      else if (typ == MatrixType::Lower)
+	{
+	  const double *tmp_data = fortran_vec ();
+	  octave_idx_type info = 0;
+	  char norm = '1';
+	  char uplo = 'L';
+	  char dia = 'N';
+
+	  Array<double> z (3 * nc);
+	  double *pz = z.fortran_vec ();
+	  Array<octave_idx_type> iz (nc);
+	  octave_idx_type *piz = iz.fortran_vec ();
+
+	  F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
+				     F77_CONST_CHAR_ARG2 (&uplo, 1), 
+				     F77_CONST_CHAR_ARG2 (&dia, 1), 
+				     nr, tmp_data, nr, rcon,
+				     pz, piz, info
+				     F77_CHAR_ARG_LEN (1)
+				     F77_CHAR_ARG_LEN (1)
+				     F77_CHAR_ARG_LEN (1)));
+
+	  if (info != 0) 
+	    rcon = 0.0;
+	}
+      else if (typ == MatrixType::Permuted_Lower)
+	(*current_liboctave_error_handler)
+	  ("permuted triangular matrix not implemented");
+      else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
+	{
+	  double anorm = -1.0;
+	  Matrix atmp = *this;
+	  double *tmp_data = atmp.fortran_vec ();
+
+	  if (typ == MatrixType::Hermitian)
+	    {
+	      octave_idx_type info = 0;
+	      char job = 'L';
+	      anorm = atmp.abs().sum().
+		row(static_cast<octave_idx_type>(0)).max();
+
+	      F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, 
+					 tmp_data, nr, info
+					 F77_CHAR_ARG_LEN (1)));
+
+	      if (info != 0) 
+		{
+		  rcon = 0.0;
+		  mattype.mark_as_unsymmetric ();
+		  typ = MatrixType::Full;
+		}
+	      else 
+		{
+		  Array<double> z (3 * nc);
+		  double *pz = z.fortran_vec ();
+		  Array<octave_idx_type> iz (nc);
+		  octave_idx_type *piz = iz.fortran_vec ();
+
+		  F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
+					     nr, tmp_data, nr, anorm,
+					     rcon, pz, piz, info
+					     F77_CHAR_ARG_LEN (1)));
+
+		  if (info != 0) 
+		    rcon = 0.0;
+		}
+	    }
+
+	  if (typ == MatrixType::Full)
+	    {
+	      octave_idx_type info = 0;
+
+	      Array<octave_idx_type> ipvt (nr);
+	      octave_idx_type *pipvt = ipvt.fortran_vec ();
+
+	      if(anorm < 0.)
+		anorm = atmp.abs().sum().
+		  row(static_cast<octave_idx_type>(0)).max();
+
+	      Array<double> z (4 * nc);
+	      double *pz = z.fortran_vec ();
+	      Array<octave_idx_type> iz (nc);
+	      octave_idx_type *piz = iz.fortran_vec ();
+
+	      F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info));
+
+	      if (info != 0) 
+		{
+		  rcon = 0.0;
+		  mattype.mark_as_rectangular ();
+		}
+	      else 
+		{
+		  char job = '1';
+		  F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
+					     nc, tmp_data, nr, anorm, 
+					     rcon, pz, piz, info
+					     F77_CHAR_ARG_LEN (1)));
+
+		  if (info != 0) 
+		    rcon = 0.0;
+		}
+	    }
+	}
+      else
+	rcon = 0.0;
+    }
+
+  return rcon;
+}
+
 Matrix
 Matrix::utsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info,
-		double& rcond, solve_singularity_handler sing_handler,
+		double& rcon, solve_singularity_handler sing_handler,
 		bool calc_cond) const
 {
   Matrix retval;
@@ -1344,7 +1509,7 @@
 	  typ == MatrixType::Upper)
 	{
 	  octave_idx_type b_nc = b.cols ();
-	  rcond = 1.;
+	  rcon = 1.;
 	  info = 0;
 
 	  if (typ == MatrixType::Permuted_Upper)
@@ -1370,7 +1535,7 @@
 		  F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
 					     F77_CONST_CHAR_ARG2 (&uplo, 1), 
 					     F77_CONST_CHAR_ARG2 (&dia, 1), 
-					     nr, tmp_data, nr, rcond,
+					     nr, tmp_data, nr, rcon,
 					     pz, piz, info
 					     F77_CHAR_ARG_LEN (1)
 					     F77_CHAR_ARG_LEN (1)
@@ -1379,18 +1544,18 @@
 		  if (info != 0) 
 		    info = -2;
 
-		  volatile double rcond_plus_one = rcond + 1.0;
-
-		  if (rcond_plus_one == 1.0 || xisnan (rcond))
+		  volatile double rcond_plus_one = rcon + 1.0;
+
+		  if (rcond_plus_one == 1.0 || xisnan (rcon))
 		    {
 		      info = -2;
 
 		      if (sing_handler)
-			sing_handler (rcond);
+			sing_handler (rcon);
 		      else
 			(*current_liboctave_error_handler)
 			  ("matrix singular to machine precision, rcond = %g",
-			   rcond);
+			   rcon);
 		    }
 		}
 
@@ -1423,7 +1588,7 @@
 
 Matrix
 Matrix::ltsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info,
-		double& rcond, solve_singularity_handler sing_handler,
+		double& rcon, solve_singularity_handler sing_handler,
 		bool calc_cond) const
 {
   Matrix retval;
@@ -1444,7 +1609,7 @@
 	  typ == MatrixType::Lower)
 	{
 	  octave_idx_type b_nc = b.cols ();
-	  rcond = 1.;
+	  rcon = 1.;
 	  info = 0;
 
 	  if (typ == MatrixType::Permuted_Lower)
@@ -1470,7 +1635,7 @@
 		  F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), 
 					     F77_CONST_CHAR_ARG2 (&uplo, 1), 
 					     F77_CONST_CHAR_ARG2 (&dia, 1), 
-					     nr, tmp_data, nr, rcond,
+					     nr, tmp_data, nr, rcon,
 					     pz, piz, info
 					     F77_CHAR_ARG_LEN (1)
 					     F77_CHAR_ARG_LEN (1)
@@ -1479,18 +1644,18 @@
 		  if (info != 0) 
 		    info = -2;
 
-		  volatile double rcond_plus_one = rcond + 1.0;
-
-		  if (rcond_plus_one == 1.0 || xisnan (rcond))
+		  volatile double rcond_plus_one = rcon + 1.0;
+
+		  if (rcond_plus_one == 1.0 || xisnan (rcon))
 		    {
 		      info = -2;
 
 		      if (sing_handler)
-			sing_handler (rcond);
+			sing_handler (rcon);
 		      else
 			(*current_liboctave_error_handler)
 			  ("matrix singular to machine precision, rcond = %g",
-			   rcond);
+			   rcon);
 		    }
 		}
 
@@ -1523,7 +1688,7 @@
 
 Matrix
 Matrix::fsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info,
-		double& rcond, solve_singularity_handler sing_handler,
+		double& rcon, solve_singularity_handler sing_handler,
 		bool calc_cond) const
 {
   Matrix retval;
@@ -1556,7 +1721,7 @@
 				     F77_CHAR_ARG_LEN (1)));
 
 	  // Throw-away extra info LAPACK gives so as to not change output.
-	  rcond = 0.0;
+	  rcon = 0.0;
 	  if (info != 0) 
 	    {
 	      info = -2;
@@ -1575,24 +1740,24 @@
 
 		  F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
 					     nr, tmp_data, nr, anorm,
-					     rcond, pz, piz, info
+					     rcon, pz, piz, info
 					     F77_CHAR_ARG_LEN (1)));
 
 		  if (info != 0) 
 		    info = -2;
 
-		  volatile double rcond_plus_one = rcond + 1.0;
-
-		  if (rcond_plus_one == 1.0 || xisnan (rcond))
+		  volatile double rcond_plus_one = rcon + 1.0;
+
+		  if (rcond_plus_one == 1.0 || xisnan (rcon))
 		    {
 		      info = -2;
 
 		      if (sing_handler)
-			sing_handler (rcond);
+			sing_handler (rcon);
 		      else
 			(*current_liboctave_error_handler)
 			  ("matrix singular to machine precision, rcond = %g",
-			   rcond);
+			   rcon);
 		    }
 		}
 
@@ -1636,13 +1801,13 @@
 	  F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info));
 
 	  // Throw-away extra info LAPACK gives so as to not change output.
-	  rcond = 0.0;
+	  rcon = 0.0;
 	  if (info != 0) 
 	    {
 	      info = -2;
 
 	      if (sing_handler)
-		sing_handler (rcond);
+		sing_handler (rcon);
 	      else
 		(*current_liboctave_error_handler)
 		  ("matrix singular to machine precision");
@@ -1658,24 +1823,24 @@
 		  char job = '1';
 		  F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
 					     nc, tmp_data, nr, anorm, 
-					     rcond, pz, piz, info
+					     rcon, pz, piz, info
 					     F77_CHAR_ARG_LEN (1)));
 
 		  if (info != 0) 
 		    info = -2;
 
-		  volatile double rcond_plus_one = rcond + 1.0;
-
-		  if (rcond_plus_one == 1.0 || xisnan (rcond))
+		  volatile double rcond_plus_one = rcon + 1.0;
+
+		  if (rcond_plus_one == 1.0 || xisnan (rcon))
 		    {
 		      info = -2;
 
 		      if (sing_handler)
-			sing_handler (rcond);
+			sing_handler (rcon);
 		      else
 			(*current_liboctave_error_handler)
 			  ("matrix singular to machine precision, rcond = %g",
-			   rcond);
+			   rcon);
 		    }
 		}
 
@@ -1707,20 +1872,20 @@
 Matrix::solve (MatrixType &typ, const Matrix& b) const
 {
   octave_idx_type info;
-  double rcond;
-  return solve (typ, b, info, rcond, 0);
+  double rcon;
+  return solve (typ, b, info, rcon, 0);
 }
 
 Matrix
 Matrix::solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, 
-	       double& rcond) const
+	       double& rcon) const
 {
-  return solve (typ, b, info, rcond, 0);
+  return solve (typ, b, info, rcon, 0);
 }
 
 Matrix
 Matrix::solve (MatrixType &mattype, const Matrix& b, octave_idx_type& info,
-	       double& rcond, solve_singularity_handler sing_handler,
+	       double& rcon, solve_singularity_handler sing_handler,
 	       bool singular_fallback) const
 {
   Matrix retval;
@@ -1731,11 +1896,11 @@
 
   // Only calculate the condition number for LU/Cholesky
   if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
-    retval = utsolve (mattype, b, info, rcond, sing_handler, false);
+    retval = utsolve (mattype, b, info, rcon, sing_handler, false);
   else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
-    retval = ltsolve (mattype, b, info, rcond, sing_handler, false);
+    retval = ltsolve (mattype, b, info, rcon, sing_handler, false);
   else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
-    retval = fsolve (mattype, b, info, rcond, sing_handler, true);
+    retval = fsolve (mattype, b, info, rcon, sing_handler, true);
   else if (typ != MatrixType::Rectangular)
     {
       (*current_liboctave_error_handler) ("unknown matrix type");
@@ -1746,7 +1911,7 @@
   if (singular_fallback && mattype.type () == MatrixType::Rectangular)
     {
       octave_idx_type rank;
-      retval = lssolve (b, info, rank, rcond);
+      retval = lssolve (b, info, rank, rcon);
     }
 
   return retval;
@@ -1769,49 +1934,49 @@
 
 ComplexMatrix
 Matrix::solve (MatrixType &typ, const ComplexMatrix& b, octave_idx_type& info,
-	       double& rcond) const
+	       double& rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (typ, b, info, rcond);
+  return tmp.solve (typ, b, info, rcon);
 }
 
 ComplexMatrix
 Matrix::solve (MatrixType &typ, const ComplexMatrix& b, octave_idx_type& info,
-	       double& rcond, solve_singularity_handler sing_handler,
+	       double& rcon, solve_singularity_handler sing_handler,
 	       bool singular_fallback) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (typ, b, info, rcond, sing_handler, singular_fallback);
+  return tmp.solve (typ, b, info, rcon, sing_handler, singular_fallback);
 }
 
 ColumnVector
 Matrix::solve (MatrixType &typ, const ColumnVector& b) const
 {
-  octave_idx_type info; double rcond;
-  return solve (typ, b, info, rcond);
+  octave_idx_type info; double rcon;
+  return solve (typ, b, info, rcon);
 }
 
 ColumnVector
 Matrix::solve (MatrixType &typ, const ColumnVector& b, 
 	       octave_idx_type& info) const
 {
-  double rcond;
-  return solve (typ, b, info, rcond);
+  double rcon;
+  return solve (typ, b, info, rcon);
 }
 
 ColumnVector
 Matrix::solve (MatrixType &typ, const ColumnVector& b, octave_idx_type& info,
-	       double& rcond) const
+	       double& rcon) const
 {
-  return solve (typ, b, info, rcond, 0);
+  return solve (typ, b, info, rcon, 0);
 }
 
 ColumnVector
 Matrix::solve (MatrixType &typ, const ColumnVector& b, octave_idx_type& info,
-	       double& rcond, solve_singularity_handler sing_handler) const
+	       double& rcon, solve_singularity_handler sing_handler) const
 {
   Matrix tmp (b);
-  return solve (typ, tmp, info, rcond, sing_handler).column(static_cast<octave_idx_type> (0));
+  return solve (typ, tmp, info, rcon, sing_handler).column(static_cast<octave_idx_type> (0));
 }
 
 ComplexColumnVector
@@ -1831,48 +1996,48 @@
 
 ComplexColumnVector
 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b, 
-	       octave_idx_type& info, double& rcond) const
+	       octave_idx_type& info, double& rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (typ, b, info, rcond);
+  return tmp.solve (typ, b, info, rcon);
 }
 
 ComplexColumnVector
 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b, 
-	       octave_idx_type& info, double& rcond,
+	       octave_idx_type& info, double& rcon,
 	       solve_singularity_handler sing_handler) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve(typ, b, info, rcond, sing_handler);
+  return tmp.solve(typ, b, info, rcon, sing_handler);
 }
 
 Matrix
 Matrix::solve (const Matrix& b) const
 {
   octave_idx_type info;
-  double rcond;
-  return solve (b, info, rcond, 0);
+  double rcon;
+  return solve (b, info, rcon, 0);
 }
 
 Matrix
 Matrix::solve (const Matrix& b, octave_idx_type& info) const
 {
-  double rcond;
-  return solve (b, info, rcond, 0);
+  double rcon;
+  return solve (b, info, rcon, 0);
 }
 
 Matrix
-Matrix::solve (const Matrix& b, octave_idx_type& info, double& rcond) const
+Matrix::solve (const Matrix& b, octave_idx_type& info, double& rcon) const
 {
-  return solve (b, info, rcond, 0);
+  return solve (b, info, rcon, 0);
 }
 
 Matrix
 Matrix::solve (const Matrix& b, octave_idx_type& info,
-	       double& rcond, solve_singularity_handler sing_handler) const
+	       double& rcon, solve_singularity_handler sing_handler) const
 {
   MatrixType mattype (*this);
-  return solve (mattype, b, info, rcond, sing_handler);
+  return solve (mattype, b, info, rcon, sing_handler);
 }
 
 ComplexMatrix
@@ -1890,46 +2055,46 @@
 }
 
 ComplexMatrix
-Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const
+Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (b, info, rcond);
+  return tmp.solve (b, info, rcon);
 }
 
 ComplexMatrix
-Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond,
+Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon,
 	       solve_singularity_handler sing_handler) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (b, info, rcond, sing_handler);
+  return tmp.solve (b, info, rcon, sing_handler);
 }
 
 ColumnVector
 Matrix::solve (const ColumnVector& b) const
 {
-  octave_idx_type info; double rcond;
-  return solve (b, info, rcond);
+  octave_idx_type info; double rcon;
+  return solve (b, info, rcon);
 }
 
 ColumnVector
 Matrix::solve (const ColumnVector& b, octave_idx_type& info) const
 {
-  double rcond;
-  return solve (b, info, rcond);
+  double rcon;
+  return solve (b, info, rcon);
 }
 
 ColumnVector
-Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcond) const
+Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const
 {
-  return solve (b, info, rcond, 0);
+  return solve (b, info, rcon, 0);
 }
 
 ColumnVector
-Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcond,
+Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon,
 	       solve_singularity_handler sing_handler) const
 {
   MatrixType mattype (*this);
-  return solve (mattype, b, info, rcond, sing_handler);
+  return solve (mattype, b, info, rcon, sing_handler);
 }
 
 ComplexColumnVector
@@ -1947,18 +2112,18 @@
 }
 
 ComplexColumnVector
-Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcond) const
+Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (b, info, rcond);
+  return tmp.solve (b, info, rcon);
 }
 
 ComplexColumnVector
-Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcond,
+Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcon,
 	       solve_singularity_handler sing_handler) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.solve (b, info, rcond, sing_handler);
+  return tmp.solve (b, info, rcon, sing_handler);
 }
 
 Matrix
@@ -1966,29 +2131,29 @@
 {
   octave_idx_type info;
   octave_idx_type rank;
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 Matrix
 Matrix::lssolve (const Matrix& b, octave_idx_type& info) const
 {
   octave_idx_type rank;
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 Matrix
 Matrix::lssolve (const Matrix& b, octave_idx_type& info,
 		 octave_idx_type& rank) const
 {
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 Matrix
 Matrix::lssolve (const Matrix& b, octave_idx_type& info,
-		 octave_idx_type& rank, double &rcond) const
+		 octave_idx_type& rank, double &rcon) const
 {
   Matrix retval;
 
@@ -2006,7 +2171,7 @@
     {
       volatile octave_idx_type minmn = (m < n ? m : n);
       octave_idx_type maxmn = m > n ? m : n;
-      rcond = -1.0;
+      rcon = -1.0;
       if (m != n)
 	{
 	  retval = Matrix (maxmn, nrhs, 0.0);
@@ -2064,7 +2229,7 @@
       octave_idx_type* piwork = iwork.fortran_vec ();
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
-				 ps, rcond, rank, work.fortran_vec (),
+				 ps, rcon, rank, work.fortran_vec (),
 				 lwork, piwork, info));
 
       // The workspace query is broken in at least LAPACK 3.0.0
@@ -2108,7 +2273,7 @@
       work.resize (lwork);
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval,
-				 maxmn, ps, rcond, rank,
+				 maxmn, ps, rcon, rank,
 				 work.fortran_vec (), lwork, 
 				 piwork, info));
 
@@ -2116,9 +2281,9 @@
 	(*current_liboctave_warning_handler) 
 	  ("dgelsd: rank deficient %dx%d matrix, rank = %d", m, n, rank);
       if (s.elem (0) == 0.0)
-	rcond = 0.0;
+	rcon = 0.0;
       else
-	rcond = s.elem (minmn - 1) / s.elem (0);
+	rcon = s.elem (minmn - 1) / s.elem (0);
 
       retval.resize (n, nrhs);
     }
@@ -2132,8 +2297,8 @@
   ComplexMatrix tmp (*this);
   octave_idx_type info;
   octave_idx_type rank;
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexMatrix
@@ -2141,8 +2306,8 @@
 {
   ComplexMatrix tmp (*this);
   octave_idx_type rank;
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexMatrix
@@ -2150,16 +2315,16 @@
 		 octave_idx_type& rank) const
 {
   ComplexMatrix tmp (*this);
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexMatrix
 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, 
-		 octave_idx_type& rank, double& rcond) const
+		 octave_idx_type& rank, double& rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.lssolve (b, info, rank, rcond);
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ColumnVector
@@ -2167,29 +2332,29 @@
 {
   octave_idx_type info;
   octave_idx_type rank;
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 ColumnVector
 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info) const
 {
   octave_idx_type rank;
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 ColumnVector
 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info,
 		 octave_idx_type& rank) const
 {
-  double rcond;
-  return lssolve (b, info, rank, rcond);
+  double rcon;
+  return lssolve (b, info, rank, rcon);
 }
 
 ColumnVector
 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info,
-		 octave_idx_type& rank, double &rcond) const
+		 octave_idx_type& rank, double &rcon) const
 {
   ColumnVector retval;
 
@@ -2207,7 +2372,7 @@
     {
       volatile octave_idx_type minmn = (m < n ? m : n);
       octave_idx_type maxmn = m > n ? m : n;
-      rcond = -1.0;
+      rcon = -1.0;
  
       if (m != n)
 	{
@@ -2258,14 +2423,14 @@
       octave_idx_type* piwork = iwork.fortran_vec ();
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
-				 ps, rcond, rank, work.fortran_vec (),
+				 ps, rcon, rank, work.fortran_vec (),
 				 lwork, piwork, info));
 
       lwork = static_cast<octave_idx_type> (work(0));
       work.resize (lwork);
 
       F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval,
-				 maxmn, ps, rcond, rank,
+				 maxmn, ps, rcon, rank,
 				 work.fortran_vec (), lwork, 
 				 piwork, info));
 
@@ -2275,9 +2440,9 @@
 	    (*current_liboctave_warning_handler) 
 	      ("dgelsd: rank deficient %dx%d matrix, rank = %d", m, n, rank);
 	  if (s.elem (0) == 0.0)
-	    rcond = 0.0;
+	    rcon = 0.0;
 	  else
-	    rcond = s.elem (minmn - 1) / s.elem (0);
+	    rcon = s.elem (minmn - 1) / s.elem (0);
 	}
 
       retval.resize (n, nrhs);
@@ -2292,8 +2457,8 @@
   ComplexMatrix tmp (*this);
   octave_idx_type info;
   octave_idx_type rank;
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexColumnVector
@@ -2301,8 +2466,8 @@
 {
   ComplexMatrix tmp (*this);
   octave_idx_type rank;
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexColumnVector
@@ -2310,16 +2475,16 @@
 		 octave_idx_type& rank) const
 {
   ComplexMatrix tmp (*this);
-  double rcond;
-  return tmp.lssolve (b, info, rank, rcond);
+  double rcon;
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 ComplexColumnVector
 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, 
-		 octave_idx_type& rank, double &rcond) const
+		 octave_idx_type& rank, double &rcon) const
 {
   ComplexMatrix tmp (*this);
-  return tmp.lssolve (b, info, rank, rcond);
+  return tmp.lssolve (b, info, rank, rcon);
 }
 
 // Constants for matrix exponential calculation.
@@ -2337,11 +2502,11 @@
 };
 
 static void
-solve_singularity_warning (double rcond)
+solve_singularity_warning (double rcon)
 {
   (*current_liboctave_warning_handler) 
     ("singular matrix encountered in expm calculation, rcond = %g",
-     rcond);
+     rcon);
 }
 
 Matrix
@@ -2466,8 +2631,8 @@
   
   // Compute pade approximation = inverse (dpp) * npp.
 
-  double rcond;
-  retval = dpp.solve (npp, info, rcond, solve_singularity_warning);
+  double rcon;
+  retval = dpp.solve (npp, info, rcon, solve_singularity_warning);
 
   if (info < 0)
     return retval;