The addition operator (+) computes a new matrix that contains elements that are the sums of the corresponding elements of matrix1 and matrix2. If matrix1 and matrix2 are both matrices, then the addition operator adds the element in the ith row and jth column of the first matrix to the element in the ith row and jth column of the second matrix, for .
For example, the following statements add two matrices and store the result in the matrix c
, shown in Figure 24.1:
a = {1 2, 3 4}; b = {1 1, 1 1}; c = a+b; print c;
You can also use the addition operator to conveniently add a value to each element of a matrix, to each column of a matrix, or to each row of a matrix.
When you use the matrix + scalar form, the scalar value is added to each element of the matrix.
When you use the matrix + vector form, the vector is added to each row or column of the matrix.
If you add an column vector, each row of the vector is added to each row of the matrix.
If you add a row vector, each column of the vector is added to each column of the matrix.
For example, you can obtain the same result as the previous example with any of the following statements:
c = a+1; c = a+{1 1}; c = a+{1,1};
When an element of a matrix contains a missing value, the corresponding element of the sum is also a missing value.
You can also use the addition operator on character operands. In this case, the operator implements elementwise concatenation exactly as the CONCAT function .