next up previous contents
Next: TRANSPOSE Matrix Transpose Operator Up: Mathematical Operators Previous: RIGHTDIVIDE Matrix Equation Solver/Divide   Contents

Subsections

TIMES Matrix Multiply Operator

Usage

Multiplies two numerical arrays. This operator is really a combination of three operators, all of which have the same general syntax:

  y = a * b

where a and b are arrays of numerical type. The result y depends on which of the following three situations applies to the arguments a and b:

  1. a is a scalar, b is an arbitrary n-dimensional numerical array, in which case the output is the element-wise product of b with the scalar a.
  2. b is a scalar, a is an arbitrary n-dimensional numerical array, in which case the output is the element-wise product of a with the scalar b.
  3. a,b are conformant matrices, i.e., a is of size M x K, and b is of size K x N, in which case the output is of size M x N and is the matrix product of a, and b.
The output follows the standard type promotion rules, although in the first two cases, if a and b are integers, the output is an integer also, while in the third case if a and b are integers, ,the output is of type double.

Function Internals

There are three formulae for the times operator. For the first form

$\displaystyle y(m_1,\ldots,m_d) = a \times b(m_1,\ldots,m_d),
$

and the second form

$\displaystyle y(m_1,\ldots,m_d) = a(m_1,\ldots,m_d) \times b.
$

In the third form, the output is the matrix product of the arguments

$\displaystyle y(m,n) = \sum_{k=1}^{K} a(m,k) b(k,n)
$

Examples

Here are some examples of using the matrix multiplication operator. First, the scalar examples (types 1 and 2 from the list above):

--> a = [1,3,4;0,2,1]
a = 
  <int32>  - size: [2 3]
 
Columns 1 to 3
             1              3              4  
             0              2              1  
--> b = a * 2
b = 
  <int32>  - size: [2 3]
 
Columns 1 to 3
             2              6              8  
             0              4              2

The matrix form, where the first argument is 2 x 3, and the second argument is 3 x 1, so that the product is size 2 x 1.

--> a = [1,2,0;4,2,3]
a = 
  <int32>  - size: [2 3]
 
Columns 1 to 3
             1              2              0  
             4              2              3  
--> b = [5;3;1]
b = 
  <int32>  - size: [3 1]
 
Columns 1 to 1
             5  
             3  
             1  
--> c = a*b
c = 
  <double>  - size: [2 1]
 
Columns 1 to 1
   11.0000000000000        
   29.0000000000000

Note that the output is double precision.


next up previous contents
Next: TRANSPOSE Matrix Transpose Operator Up: Mathematical Operators Previous: RIGHTDIVIDE Matrix Equation Solver/Divide   Contents
2004-08-26