public function testGetInvalidMatrixValue() { $matrix = new ezcGraphMatrix(); try { $matrix->get(1, 32); } catch (ezcGraphMatrixOutOfBoundingsException $e) { return true; } $this->fail('Expected ezcGraphMatrixOutOfBoundingsException.'); }
/** * Build LR decomposition from matrix * * Use Cholesky-Crout algorithm to get LR decomposition of the current * matrix. * * Will return an array with two matrices: * array( * 'l' => (ezcGraphMatrix) $left, * 'r' => (ezcGraphMatrix) $right, * ) * * @return array( ezcGraphMatrix ) */ public function LRdecomposition() { /** * Use Cholesky-Crout algorithm to get LR decomposition * * Input: Matrix A ($this) * * For i = 1 To n * For j = i To n * R(i,j)=A(i,j) * For k = 1 TO i-1 * R(i,j)-=L(i,k)*R(k,j) * end * end * For j=i+1 To n * L(j,i)= A(j,i) * For k = 1 TO i-1 * L(j,i)-=L(j,k)*R(k,i) * end * L(j,i)/=R(i,i) * end * end * * Output: matrices L,R */ $l = new ezcGraphMatrix($this->columns, $this->rows); $r = new ezcGraphMatrix($this->columns, $this->rows); for ($i = 0; $i < $this->columns; ++$i) { for ($j = $i; $j < $this->rows; ++$j) { $r->set($i, $j, $this->matrix[$i][$j]); for ($k = 0; $k <= $i - 1; ++$k) { $r->set($i, $j, $r->get($i, $j) - $l->get($i, $k) * $r->get($k, $j)); } } for ($j = $i + 1; $j < $this->rows; ++$j) { $l->set($j, $i, $this->matrix[$j][$i]); for ($k = 0; $k <= $i - 1; ++$k) { $l->set($j, $i, $l->get($j, $i) - $l->get($j, $k) * $r->get($k, $i)); } $l->set($j, $i, $l->get($j, $i) / $r->get($i, $i)); } } return array('l' => $l, 'r' => $r); }