Пример #1
0
 /**
  *   Check to see if matrix is square: m by m
  *
  *   @access protected
  *   @param Matrix $matrix
  */
 public function checkSquare(Matrix $matrix)
 {
     if ($matrix->getColumns() != $matrix->getRows()) {
         throw new MatrixException('Matrices is not square: ' . $matrix->getRows() . ' by ' . $matrix->getColumns());
     }
     return true;
 }
Пример #2
0
 /**
  * Transpose function
  * 
  * Returns the transpose of the matrix
  *
  * @param Matrix $matrix
  * @return matrix The matrix's transpose
  */
 public function transpose(Matrix $matrix)
 {
     $rows = $matrix->getRows();
     $columns = $matrix->getColumns();
     $newMatrix = $this->zero($columns, $rows);
     for ($i = 1; $i <= $rows; $i++) {
         for ($j = 1; $j <= $columns; $j++) {
             $newMatrix->setElement($j, $i, $matrix->getElement($i, $j));
         }
     }
     return $newMatrix;
 }
Пример #3
0
 /**
  * Scalar Multiply function
  * 
  * Multiplies this matrix against a scalar value
  *
  * @param Matrix $matrix
  * @param float $scalar The scalar value
  * @return matrix The multiplied matrix
  */
 public function scalarMultiply(Matrix $matrix, $scalar)
 {
     $rows = $matrix->getRows();
     $columns = $matrix->getColumns();
     $newMatrix = $this->builder->zero($rows, $columns);
     for ($i = 1; $i <= $rows; $i++) {
         for ($j = 1; $j <= $columns; $j++) {
             $newMatrix->setElement($i, $j, $matrix->getElement($i, $j) * $scalar);
         }
     }
     return $newMatrix;
 }