-

Subtraction operator.

Syntax

expr_1 - expr_2

Operands

expr_1, expr_2
A pair of valid scalar, vector, or matrix expressions.

Example

Expression Result
5 - 2 3
3 - {1, 2, 3} {2, 1, 0}
{1, 2, 3} - 1 {0, 1, 2}
{7, 8, 9} - {6, 6, 6} {1, 2, 3}
{ {1, 2, 3}, {4, 5, 6} } - 2 { {-1, 0, 1}, {2, 3, 4} }
{ {1, 2, 3}, {4, 5, 6} } - { {6, 5, 4}, {3, 2, 1} } { {-5, -3, -1}, {1, 3, 5} }

Comments

The subtraction operator subtracts expr_2 from expr_1 .

If expr_1 and expr_2 are scalars, the result is the difference of expr_1 and expr_2.

If a scalar is subtracted from a vector, the scalar is subtracted from each element of the vector. The result is a vector with the same number of elements as the original vector.

If a vector is subtracted from a scalar, each element of the vector is subtracted from the scalar. The result is a vector with the same number of elements as the original vector.

If a scalar is subtracted from a matrix, the scalar is subtracted from each element of the matrix. The result is a matrix with the same dimensions as the original matrix.

If a matrix is subtracted from a scalar, each element of the matrix is subtracted from the scalar. The result is a matrix with the same dimensions as the original matrix.

If expr_1 and expr_2 are vectors, the result is a vector containing the differences of the corresponding elements from each vector. Both vectors must have the same number of elements. The result contains the same number of elements as the two operands.

If expr_1 and expr_2 are matrices, the result is a matrix containing the differences of the corresponding element from each vector. Both matrices must have the same number of rows and columns. The result is a matrix with the same dimensions as the two matrices.