Language Reference

Multiplication Operator, Elementwise:   #

performs elementwise multiplication

matrix1#matrix2
matrix#scalar
matrix#vector

The elementwise multiplication operator (#) produces a new matrix with elements that are the products of the corresponding elements of matrix1 and matrix2.

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

  
    a={1 2, 
       3 4}; 
    b={4 8, 
       0 5}; 
    c=a#b;
 

  
                C             2 rows      2 cols    (numeric) 
  
                                   4        16 
                                   0        20
 
In addition to multiplying conformable matrices, you can use the elementwise multiplication operator to multiply a matrix and a scalar. When either argument is a scalar, the scalar value is multiplied by each element in matrix to form the new matrix.

You can also multiply vectors by matrices. If either operand is a row or column vector, then the operation is performed using that vector on each of the rows or columns of the matrix.

You can multiply matrices as long as they either conform in each dimension or one operand has dimension value 1. For example, a 2 x 3 matrix can be multiplied on either side by a 2 x 3, 1 x 3, 2 x 1, or 1 x 1 matrix. The following statements multiply the 2 x 2 matrix a by the column vector d:

  
    d={10,100}; 
    ad=a#d;
 
These statements produce the following matrix:
  
                AD            2 rows      2 cols    (numeric) 
  
                                  10        20 
                                 300       400
 
Now, consider the following statements:
  
    d={10 100}; 
    ad=a#d;
 
These statements produce the following matrix:
  
                AD            2 rows      2 cols    (numeric) 
  
                                  10       200 
                                  30       400
 

The result of elementwise multiplication is also known as the Schur or Hadamard product. Element multiplication (using the # operator) should not be confused with matrix multiplication (using the * operator).

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

Previous Page | Next Page | Top of Page