diff liboctave/CMatrix.cc @ 7400:f9df7f7520e7

[project @ 2008-01-18 08:25:24 by jwe]
author jwe
date Fri, 18 Jan 2008 08:25:24 +0000
parents 7da4a5262e2e
children a7a987b229b7
line wrap: on
line diff
--- a/liboctave/CMatrix.cc
+++ b/liboctave/CMatrix.cc
@@ -2750,6 +2750,14 @@
   1.9270852604185938e-9,
 };
 
+static void
+solve_singularity_warning (double rcond)
+{
+  (*current_liboctave_warning_handler) 
+    ("singular matrix encountered in expm calculation, rcond = %g",
+     rcond);
+}
+
 ComplexMatrix
 ComplexMatrix::expm (void) const
 {
@@ -2843,6 +2851,9 @@
 
   if (sqpow > 0)
     {
+      if (sqpow > 1023)
+	sqpow = 1023;
+
       double scale_factor = 1.0;
       for (octave_idx_type i = 0; i < sqpow; i++)
 	scale_factor *= 2.0;
@@ -2889,8 +2900,12 @@
 
   // Compute pade approximation = inverse (dpp) * npp.
 
-  retval = dpp.solve (npp);
-	
+  double rcond;
+  retval = dpp.solve (npp, info, rcond, solve_singularity_warning);
+
+  if (info < 0)
+    return retval;
+
   // Reverse preconditioning step 3: repeated squaring.
 
   while (sqpow)