Addition
The table below describes the Addition operator.
+ | Scalar | Row Vector | Column Vector | Matrix |
---|---|---|---|---|
Scalar | Adds the two scalar values. | Adds the scalar to each element in the row vector. The resulting vector is the same size as the original vector. | Adds the scalar to each element in the column vector. The resulting vector is the same size as the original vector. | Adds the scalar to each element in the matrix. The resulting vector is the same size as the original matrix. |
Row Vector | Adds the scalar to each element in the row vector. The resulting vector is the same size as the original vector. | Requires vectors to be the same size. Adds each element in operand 1 to the corresponding element in operand 2. The resulting vector is the same size as the original vectors. | Each row/column vector is implicitly replicated until the two arguments have the same dimensions. Regular matrix addition is then performed. | The row vector is implicitly replicated until the two arguments have the same number of rows. Regular matrix addition is then performed. |
Column Vector | Adds the scalar to each element in the column vector. The resulting vector is the same size as the original vector. | Each row/column is implicitly replicated until the two arguments have the same dimensions. Regular matrix addition is then performed. | Requires vectors to be the same size. Adds each element in operand 1 to the corresponding element in operand 2. The resulting vector is the same size as the original vectors. | The column vector is implicitly replicated until the two arguments have the same number of columns. Regular matrix addition is then performed. |
Matrix | Adds the scalar to each element in the matrix. The resulting vector is the same size as the original matrix. | The row vector is implicitly replicated until the two arguments have the same number of rows. Regular matrix addition is then performed. | The column vector is implicitly replicated until the two arguments have the same number of columns. Regular matrix addition is then performed. | Requires matrices to be the same size. Adds each element in operand 1 to the corresponding element in operand 2. The resulting vector is the same size as the original matrices. |
Examples
1 + 1
ans = 2
3 + [2 5 2]
ans = [5 8 5]
[2 5; 6 2] + [8 3; 6 7]
ans = [10 8; 12 9]
[5 4 2] + [4 3]
Comments
Sparse matrices are supported for this operation. The sum of two sparse matrices will also be sparse. The sum of a sparse matrix and a full matrix is a full matrix.
The implicit replication of a vector to fill other dimensions is a generalization of operating on a scalar/vector pair. This capability is not yet available for multidimensional and sparse matrices.