Mercurial > hg > octave-nkf
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 +++ b/liboctave/fDiagMatrix.cc @@ -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) {