diff liboctave/fDiagMatrix.cc @ 8371:c3f7e2549abb

make det & inv aware of diagonal & permutation matrices
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 04 Dec 2008 12:03:45 +0100
parents 8b1a2555c4e2
children e3c9102431a9
line wrap: on
line diff
--- a/liboctave/fDiagMatrix.cc	Thu Dec 04 09:52:30 2008 +0100
+++ b/liboctave/fDiagMatrix.cc	Thu Dec 04 12:03:45 2008 +0100
@@ -394,6 +394,33 @@
   return d;
 }
 
+FloatDET
+FloatDiagMatrix::determinant (void) const
+{
+  FloatDET det (1.0f);
+  if (rows () != cols ())
+    {
+      (*current_liboctave_error_handler) ("determinant requires square matrix");
+      det = 0.0f;
+    }
+  else
+    {
+      octave_idx_type len = length ();
+      for (octave_idx_type i = 0; i < len; i++)
+        det *= elem (i, i);
+    }
+
+  return det;
+}
+
+float
+FloatDiagMatrix::rcond (void) const
+{
+  FloatColumnVector av = diag (0).map (fabsf);
+  float amx = av.max (), amn = av.min ();
+  return amx == 0 ? 0.0f : amn / amx;
+}
+
 std::ostream&
 operator << (std::ostream& os, const FloatDiagMatrix& a)
 {