/**
  * 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;
 }
Beispiel #2
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;
 }