Mercurial > hg > octave-nkf
diff liboctave/dDiagMatrix.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 | 445d27d79f4e |
children | e3c9102431a9 |
line wrap: on
line diff
--- a/liboctave/dDiagMatrix.cc +++ b/liboctave/dDiagMatrix.cc @@ -387,6 +387,32 @@ return d; } +DET +DiagMatrix::determinant (void) const +{ + DET det (1.0); + if (rows () != cols ()) + { + (*current_liboctave_error_handler) ("determinant requires square matrix"); + det = 0.0; + } + else + { + octave_idx_type len = length (); + for (octave_idx_type i = 0; i < len; i++) + det *= elem (i, i); + } + + return det; +} + +double +DiagMatrix::rcond (void) const +{ + ColumnVector av = diag (0).map (fabs); + double amx = av.max (), amn = av.min (); + return amx == 0 ? 0.0 : amn / amx; +} std::ostream& operator << (std::ostream& os, const DiagMatrix& a)