MathPHP\LinearAlgebra\Matrix::add PHP Method

add() public method

Returns a new matrix. https://en.wikipedia.org/wiki/Matrix_addition#Entrywise_sum
public add ( Matrix $B ) : Matrix
$B Matrix Matrix to add to this matrix
return Matrix
    public function add(Matrix $B) : Matrix
    {
        if ($B->getM() !== $this->m) {
            throw new Exception\MatrixException('Matices have different number of rows');
        }
        if ($B->getN() !== $this->n) {
            throw new Exception\MatrixException('Matices have different number of columns');
        }
        $R = [];
        for ($i = 0; $i < $this->m; $i++) {
            for ($j = 0; $j < $this->n; $j++) {
                $R[$i][$j] = $this->A[$i][$j] + $B[$i][$j];
            }
        }
        return MatrixFactory::create($R);
    }