cvs: pear /Math_Matrix Matrix.php
| From: | Jesus M. Castagnetto | Date: | Tue, 28 May 2002 09:27:07 +0000 |
| Subject: | cvs: pear /Math_Matrix Matrix.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4199@lists.php.net to get a copy of this message | ||
jmcastagnetto Tue May 28 05:27:07 2002 EDT
Modified files:
/pear/Math_Matrix Matrix.php
Log:
Added trace() method.
TODO: add Gauss-Jordan determinant algorithm, good for big matrices.
Index: pear/Math_Matrix/Matrix.php
diff -u pear/Math_Matrix/Matrix.php:1.3 pear/Math_Matrix/Matrix.php:1.4
--- pear/Math_Matrix/Matrix.php:1.3 Tue May 28 05:12:53 2002
+++ pear/Math_Matrix/Matrix.php Tue May 28 05:27:07 2002
@@ -18,7 +18,7 @@
//
// Matrix definition and manipulation package
//
-// $Id: Matrix.php,v 1.3 2002/05/28 09:12:53 jmcastagnetto Exp $
+// $Id: Matrix.php,v 1.4 2002/05/28 09:27:07 jmcastagnetto Exp $
//
require_once 'PEAR.php';
@@ -201,6 +201,17 @@
return $this->_data[$row][$col];
}/*}}}*/
+ function trace() {
+ if ($this->isEmpty())
+ return PEAR::raiseError('Matrix has not been populated');
+ if (!$this->isSquare())
+ return PEAR::raiseError('Trace undefined for non-square matrices');
+ $trace = 0;
+ for ($i=0; $i < $this->_nrows; $i++)
+ $trace += $this->getElement($i, $i);
+ return $trace;
+ }
+
function determinant() {
if ($this->isEmpty())
return PEAR::raiseError('Matrix has not been populated');