Subtraction Operator:   –

matrix1 – matrix2 ;

matrix – scalar ;

matrix – vector ;

The subtraction operator ($-$) computes a new matrix that contains elements that are formed by subtracting the corresponding elements of matrix2 from those of matrix1.

In addition to subtracting conformable matrices, you can also use the subtraction operator to subtract a scalar from a matrix or subtract a vector from a matrix.

  • When either argument is a scalar, the subtraction is performed between the scalar and each element of the matrix argument. For example, when you use the matrix – scalar form, the scalar value is subtracted from each element of the matrix.

  • When you use the matrix – vector form, the vector is subtracted from each row or column of the $n\times p$ matrix.

    • If you subtract an $n\times 1$ column vector, each row of the vector is subtracted from each row of the matrix.

    • If you subtract a $1\times p$ row vector, each column of the vector is subtracted from each column of the matrix.

When an element of the matrix contains a missing value, the corresponding element of the result also contains a missing value.

For example, the following statements subtract two matrices and store the result in the matrix c, shown in Figure 24.30:

a = {1 2,
     3 4};
b = {1 1,
     1 1};
c = a-b;
print c;

Figure 24.30: Difference of Two Matrices

c
0 1
2 3