INNER PRODUCT

Syntax: vout = v1 <> v2

The inner product operator, <>, operating on two vectors produces a scalar; operating on a vector and a matrix produces a vector; and operating on two matrices produces a matrix.

Operating on two vectors

The inner product operating on two vectors produces a scalar, whose value is equal to the sum of the products of the vectors' elements. The two vectors must be the same length. Suppose X and Y are vectors of length N. Then x<>y = x[1]*y[1] + x[2]y[2] + ... + x[N]*y[N].

Example

Suppose you have two vectors: X = [1;3;5] and Y = [2;4;6]

Then: X<>Y = 1*2 + 3*4 + 5*6 = 44

Operating on a vector and a matrix

The inner product operating on a vector and a matrix produces a vector. If the vector is the first operand, its length must be equal to the number of rows of the matrix. The resultant vector length will be the number of columns of the second operand matrix.

If X is a vector of length N, and A is a matrix with N rows and M columns, then X<>A is a vector where (X<>A)[i] = X[1]*A[1,i] + X[2]*A[2,i] + ... + X[N]*A[N,i]. The vector X<>A will have M elements.

Example

The inner product of a vector and a matrix:

X = [1;3;5] and

     | 1 4 |
 M = | 2 5 |
     | 3 6 |
 

Then: X<>M = [22;49]

Operating on a matrix and a vector

The inner product operating on a matrix and a vector produces a vector. If the vector is the second operand, its length must be equal to the number of columns of the matrix, and the resultant vector length will be the number of rows of the first operand matrix.

If A is a matrix with N rows and M columns, and X is a vector of length M, then A<>X is a vector where (A<>X)[i] = A[i,1]*X[1] + A[i,2]*X[2] + ... + A[i,M]*X[M]. The vector X<>A will have N elements.

Example

The inner product of a matrix and a vector:

X = [1;3;5]

 M = | 1 3 5 |
     | 2 4 6 |
 

Then: M<>X = [35;44]

Operating on two matrices

The inner product operating on two matrices produces a matrix. The number of columns of the first operand matrix must be equal to the number of rows of the second operand matrix. The resultant matrix will be a square matrix with the number of rows and the number of columns equal to the number of rows of the first operand.

If A is an N by M matrix and B is an M by N matrix, then A<>B is an N by N matrix, where (A<>B)[i,j] = A[i,1]*B[1,j] + A[i,2]*B[2,j] + ... + A[i,M]*B[M,j] for i = [1;2;...;N] and j = [1;2;...;N]

Example

The inner product of two matrices:

Let

     | 11 12 13 |
 A = | 21 22 23 |
     | 31 32 33 |
 
and
     | 1 2 3 |
 B = | 2 4 6 |
     | 3 6 9 |
 
then
        |  74 148 222 |
 A<>B = | 134 268 402 |
        | 194 388 582 |
 

  outer product