Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * 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);
 }
Beispiel #5
0
 /**
  * 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;
 }