Subtraction

The table below describes the Subtraction operator.

- Scalar Row Vector Column Vector Matrix
Scalar Subtracts the second scalar value from the first scalar value. Subtracts each element in the row vector from the scalar. The resulting vector is the same size as the original vector. Subtracts each element in the column vector from the scalar. The resulting vector is the same size as the original vector. Subtracts each element in the matrix from the scalar. The resulting vector is the same size as the original matrix.
Row Vector Subtracts the scalar from each element in the row vector. The resulting vector is the same size as the original vector. Requires vectors to be the same size. Subtracts each element in operand 2 from the corresponding element in operand 1. 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 subtraction is then performed. The row vector is implicitly replicated until the two arguments have the same number of rows. Regular matrix subtraction is then performed.
Column Vector Subtracts the scalar from each element in the column vector. The resulting vector is the same size as the original vector. Each row/column vector is implicitly replicated until the two arguments have the same dimensions. Regular matrix subtraction is then performed. Requires vectors to be the same size. Subtracts each element in operand 2 from the corresponding element in operand 1. 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 subtraction is then performed.
Matrix Subtracts the scalar from 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 subtraction is then performed. The column vector is implicitly replicated until the two arguments have the same number of columns. Regular matrix subtraction is then performed. Requires matrices to be the same size. Subtracts each element in operand 1 from the corresponding element in operand 2. The resulting vector is the same size as the original matrices.

Examples

2 - 3
ans = -1 

[4 2 1] – 3
ans = [1 -1 -2]  

[4 2 1] - [5 3 2]
ans = [-1 -1 -1]
Invalid examples:
[3 6 5] – [4 3; 6 5]

Comments

Sparse matrices are supported for this operation. The difference of two sparse matrices will also be sparse. A difference involving a sparse matrix and a full matrix will produce 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.