public static function add(Matrix $matrix, Matrix $matrix2) : Matrix {
        $type  = get_class($matrix);
        $type2 = get_class($matrix2);

        if ($type !== $type2) {
            throw new InvalidArgumentException("Can only add matrices of same size.");
        }

        $result = new $type();

        for ($i=0;$i<$type::ROWS;$i++) {
            for ($j=0;$j<$type::COLUMNS;$j++) {
                $result[$i][$j] = $matrix[$i][$j] + $matrix2[$i][$j];
            }
        }

        return $result;
    }