/** * Get the L of the composition L^T*D*L. * * @return matrix L */ public function getL() { $L = $this->_matrix->copy(); // L is the lower triangular matrix. for ($i = 0; $i < $L->rows(); $i++) { for ($j = $i; $j < $L->columns(); $j++) { if ($j == $i) { $L->set($i, $j, 1); } else { $L->set($i, $j, 0); } } } return $L; }
/** * Get the U of the decomposition. * * @return matrix U */ public function getU() { $U = $this->_matrix->copy(); for ($i = 0; $i < $U->rows(); $i++) { for ($j = 0; $j < $i; $j++) { $U->set($i, $j, 0); } } return $U; }
/** * Gets the upper triangular matrix R. */ public function getR() { $R = $this->_matrix->copy(); $n = min($R->rows(), $R->columns()); for ($i = 0; $i < $R->rows(); $i++) { for ($j = 0; $j < $i and $j < $n; $j++) { $R->set($i, $j, 0); } } return $R; }
/** * Gets the upper triangular matrix R. */ public function getR() { $R = $this->_matrix->copy(); for ($i = 0; $i < $R->rows(); $i++) { for ($j = 0; $j < $i; $j++) { $R->set($i, $j, 0); } } // Resize R to a square matrix. $n = min($R->rows(), $R->columns()); return $R->resize($n, $n); }
/** * Add to matrices. * * @param matrix $a * @param matrix $b * @return matrix $a + $b */ public static function add($a, $b) { new Assertion($a instanceof Matrix, 'Given first matrix not of class Matrix.'); new Assertion($b instanceof Matrix, 'Given second matrix not of class Matrix.'); new Assertion($a->rows() == $b->rows(), 'Given dimensions are not compatible.'); new Assertion($a->columns() == $b->columns(), 'Given dimensions are not compatible.'); $rows = $a->rows(); $columns = $a->columns(); $matrix = $a->copy(); for ($i = 0; $i < $rows; $i++) { for ($j = 0; $j < $columns; $j++) { $matrix->set($i, $j, $matrix->get($i, $j) + $b->get($i, $j)); } } return $matrix; }