src/Malenki/Math/Matrix.php
public function add($matrix)
    {
        if (!($matrix instanceof Matrix)) {
            throw new \InvalidArgumentException('Given argument must be an instance of \Malenki\Math\Matrix');
        }

        if (!$this->sameSize($matrix)) {
            throw new \RuntimeException('Cannot adding given matrix: it has wrong size.');
        }

        $out = new self($this->size->rows, $this->size->cols);

        foreach ($this->arr as $k => $v) {
            $arrOther = $matrix->getRow($k);
            $arrNew = array();

            foreach ($v as $kk => $vv) {
                if ($arrOther[$kk] instanceof Complex) {
                    $arrNew[] = $arrOther[$kk]->add($vv);
                } elseif ($vv instanceof Complex) {
                    $arrNew[] = $vv->add($arrOther[$kk]);
                } else {
                    $arrNew[] = $arrOther[$kk] + $vv;
                }
            }

            $out->addRow($arrNew);
        }

        return $out;
    }
public function add($matrix)
    {
        if (!($matrix instanceof Matrix)) {
            throw new \InvalidArgumentException('Given argument must be an instance of \Malenki\Math\Matrix');
        }

        if (!$this->sameSize($matrix)) {
            throw new \RuntimeException('Cannot adding given matrix: it has wrong size.');
        }

        $out = new self($this->size->rows, $this->size->cols);

        foreach ($this->arr as $k => $v) {
            $arrOther = $matrix->getRow($k);
            $arrNew = array();

            foreach ($v as $kk => $vv) {
                if ($arrOther[$kk] instanceof Complex) {
                    $arrNew[] = $arrOther[$kk]->add($vv);
                } elseif ($vv instanceof Complex) {
                    $arrNew[] = $vv->add($arrOther[$kk]);
                } else {
                    $arrNew[] = $arrOther[$kk] + $vv;
                }
            }

            $out->addRow($arrNew);
        }

        return $out;
    }
Adds the given matrix with the current one to give another new matrix.

@throw \InvalidArgumentException If argument is not a Matrix
@throw \RuntimeException If given matrix has not the same size.
@param  Matrix $matrix Matrix to add
@access public
@return Matrix