예제 #1
0
파일: Cholesky.php 프로젝트: hoenirvili/cn
 /**
  * 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;
 }
예제 #2
0
파일: LU.php 프로젝트: hoenirvili/cn
 /**
  * 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;
 }
예제 #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;
 }
예제 #4
0
파일: QRGivens.php 프로젝트: hoenirvili/cn
 /**
  * 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);
 }
예제 #5
0
파일: Matrix.php 프로젝트: hoenirvili/cn
 /**
  * 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;
 }