/** * @param \Wandu\Math\LinearAlgebra\Matrix $other * @return \Wandu\Math\LinearAlgebra\Matrix */ public function multiplyWithMatrix(Matrix $other) { if ($this->colSize !== $other->rowSize) { throw new InvalidArgumentException('cannot calculate, because of size.'); } $newRowSize = $this->rowSize; $newColSize = $other->colSize; $newItems = []; for ($rowIndex = 0; $rowIndex < $newRowSize; $rowIndex++) { for ($colIndex = 0; $colIndex < $newColSize; $colIndex++) { $newItems[$rowIndex][$colIndex] = $this->getRowVector($rowIndex)->dot($other->getColVector($colIndex)); } } return new static($this->rowSize, $other->colSize, $newItems); }
public function testEqual() { $this->assertEquals(matrix([[0, 0], [0, 0]]), Matrix::zeros(2, 2)); }