Esempio n. 1
0
File: LU.php Progetto: hoenirvili/cn
 /**
  * Calculate the determinant of the matrix with the given lu decomposition.
  *
  * @param   matrix  lu decomposition
  * @param   vector  permutation vector of the lu decomposition
  */
 public function getDeterminant()
 {
     // Calculate number of swapped rows.
     $swapped = 0;
     for ($i = 0; $i < $this->_permutation->size(); $i++) {
         if ($this->_permutation->get($i) != $i) {
             $swapped++;
         }
     }
     $determinant = pow(-1, $swapped);
     for ($i = 0; $i < $this->_matrix->rows(); $i++) {
         $determinant *= $this->_matrix->get($i, $i);
     }
     return $determinant;
 }
Esempio n. 2
0
 /**
  * Build the inner product of two vectors.
  *
  * @param	vector	$a
  * @param	vector	$b
  * @return	vector	inner product
  */
 public static function inner($a, $b)
 {
     new Assertion($a instanceof Vector, 'Given first vector not of class Vector.');
     new Assertion($b instanceof Vector, 'Given second vector not of class Vector.');
     new Assertion($a->size() == $b->size(), 'Dimensions do not match.');
     $size = $a->size();
     $result = 0;
     for ($i = 0; $i < $size; $i++) {
         $result += $a->get($i) * $b->get($i);
     }
     return $result;
 }