Language Reference

Addition Operator:   +

adds corresponding matrix elements

matrix1 + matrix2
matrix + scalar
matrix + vector

The addition infix operator (+) produces a new matrix containing elements that are the sums of the corresponding elements of matrix1 and matrix2. The element in the first row, first column of the first matrix is added to the element in the first row, first column of the second matrix, with the sum becoming the element in the first row, first column of the new matrix, and so on.

For example, the following statements produce the matrix c, as shown:

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

  
               C             2 rows      2 cols    (numeric) 
  
                                    2         3 
                                    4         5
 
In addition to adding conformable matrices, you can also use the addition operator to add a matrix and a scalar or row or column vector. When you use the matrix + scalar (or scalar + matrix) form, the scalar value is added to each element of the matrix to produce a new matrix. When you use the matrix + vector (or vector + matrix) form, the vector is added to each row or column of the matrix to produce a new matrix.

For example, you can obtain the same result as you did in the previous example with either of the following statements:

  
    c=a+1;
 
  
    c=a+{1 1};
 

When a missing value occurs in an operand, IML assigns a missing value for the corresponding element in the result.

You can also use the addition operator on character operands. In this case, the operator does elementwise concatenation exactly as the CONCAT function does.

Previous Page | Next Page | Top of Page