public function naiveMultiply(LL_Matrix $matrix) { if (is_array($matrix)) { $matrix = new LL_Matrix($matrix); } if ($this->columns() != $matrix->rows()) { // impossible operation. return false; } $result = array(); for ($a = 0; $a < $this->rows(); $a++) { for ($b = 0; $b < $matrix->columns(); $b++) { $result[$a][$b] = 0; for ($i = 0; $i < $this->columns(); $i++) { $result[$a][$b] += $this->get($a, $i) * $matrix->get($i, $b); } } } return new LL_Matrix($result); }