# Multiplying two N-D arrays of matrices 1.0

OS : Windows / Linux / Mac OS / BSD / Solaris

Script Licensing : Freeware

Created : Aug 29, 2007

Downloads : 3

Thank you for voting...

## MULTIPROD is a powerful generalization for N-D arrays ...

multiprod is a powerful generalization for N-D arrays of the MATLAB matrix multiplication operator (*). While the latter works only with 2-D arrays, MULTIPROD works also with multidimensional arrays.

Besides the element-wise multiplication operator (. *), MATLAB 7 includes only two functions which can perform products between N-D arrays: DOT and CROSS. However, these functions can only perform two kinds of product: the dot product and the cross product, respectively. MULTIPROD can perform any kind of linear algebraic and vectorial products,

2) Arrays of scalars by arrays of scalars, vectors or matrices

3) Arrays of vectors by arrays of scalars, vectors or matrices

4) Arrays of matrices by arrays of scalars, vectors or matrices

Synthetically, it can be stated that, with MULTIPROD, the "matrix laboratory" MATLAB evolves becoming ARRAYLAB, an "array laboratory".

Multidimensional arrays may contain matrices or vectors or even scalars along one or two of their dimensions. For instance, a 2x5x6 array A contains six 2x5 matrices along its first and second dimension. Thus, array A can be described as a block array of matrices, and its size can be indicated as follows: (2x5)x6.

B is (5x3)x6

C is (2x3)x6

With MULTIPROD,

Any multidimensional array can be described as a block array.

B is a 2x5x(3x4) array containing matrices along dim. 3 and 4

C is a 2x5x(1x1) array containing scalars along dim. 3 and 4

D is a 2x5x(6) array containing vectors along dim. 3

E is a 2x5x(3) array containing vectors along dim. 3

F is a 2x5x(1) array containing scalars along dim. 3

For instance,

or scalars occupying the same position in B, C, E, or F

- Multi-multiply D by A

- Multi-multiply the arrays of scalars C and F

by any of the other arrays

- Perform multiple outer products between D and E

MULTIPROD has a broad field of potential applications. By calling MULTIPROD, multiple geometrical transformations such as rotations or roto-translations can be performed on large arrays of vectors in a single step and with no loops. Multiple operations such as normalizing an array of vectors, or finding their projection along the axes indicated by another array of vectors can be performed easily, with no loops and with two or three rows of code.

Sample functions performing some of these tasks by calling MULTIPROD or by using parts of its code are included in the separate toolbox "Matlab Central > File Exchange > Vector algebra for multidimensional arrays of vectors".

A sample function (LOC2LOC) performing a multiple roto-translation by calling MULTIPROD is included in this package. This function uses 3-element translation vectors and 3x3 rotation matrices. If you prefer to work with homogeneous coordinates and 4x4 roto-translation matrices, you can obtain the same result just by calling MULTIPROD twice.

If you have a single matrix R, and you want to multiply it by an array of vectors MultiV,

MATEXP is included in this package.

MULTIPROD calls, in some cases, the function MULTITRANSP, performing matrix transpositions in arrays of matrices. I wrote it as a separate function because I discovered it can be useful for several different purposes. MULTITRANSP is included in this package.

A document written with MS Word and explaining in detail and schematically the meaning of the implemented syntaxes is included, for those who want to understand the code. The help text in the function was written with extreme care, and should be enough for those who just want to use the function.

Since I wanted to be of service to as many people as possible, MULTIPROD itself was written, debugged, refined and in several parts even optimized for speed with extreme care. I hope it or a future version of it, modified according to your suggestions, will be included in the next version of MATLAB. The code ("testMULTIPROD. m") I used to test the function output is included in this package.

and B is a 5x(3x4)x2 array,

C = MULTIPROD(A, B, [2 3]) is a 5x(6x4)x2 array.

2) If A is a 5x(6x3)x2 array,

and B is a 5x(1x1)x2 array,

C = MULTIPROD(A, B, [2 3]) is a 5x(6x3)x2 array.

Besides the element-wise multiplication operator (. *), MATLAB 7 includes only two functions which can perform products between N-D arrays: DOT and CROSS. However, these functions can only perform two kinds of product: the dot product and the cross product, respectively. MULTIPROD can perform any kind of linear algebraic and vectorial products,

**except for cross products:**

1) Both outer and inner products between arrays of vectors2) Arrays of scalars by arrays of scalars, vectors or matrices

3) Arrays of vectors by arrays of scalars, vectors or matrices

4) Arrays of matrices by arrays of scalars, vectors or matrices

Synthetically, it can be stated that, with MULTIPROD, the "matrix laboratory" MATLAB evolves becoming ARRAYLAB, an "array laboratory".

Multidimensional arrays may contain matrices or vectors or even scalars along one or two of their dimensions. For instance, a 2x5x6 array A contains six 2x5 matrices along its first and second dimension. Thus, array A can be described as a block array of matrices, and its size can be indicated as follows: (2x5)x6.

**Let's say that:**

A is (2x5)x6B is (5x3)x6

C is (2x3)x6

With MULTIPROD,

**the six matrices in A can be multiplied by the six matrices in B in a single step:**

C = MULTIPROD(A, B)Any multidimensional array can be described as a block array.

**Here are a few examples:**

A is a 2x5x(6x3) array containing matrices along dim. 3 and 4B is a 2x5x(3x4) array containing matrices along dim. 3 and 4

C is a 2x5x(1x1) array containing scalars along dim. 3 and 4

D is a 2x5x(6) array containing vectors along dim. 3

E is a 2x5x(3) array containing vectors along dim. 3

F is a 2x5x(1) array containing scalars along dim. 3

For instance,

**MULTIPROD can:**

- Multiply the 10 matrices in A by the 10 matrices, vectorsor scalars occupying the same position in B, C, E, or F

- Multi-multiply D by A

- Multi-multiply the arrays of scalars C and F

by any of the other arrays

- Perform multiple outer products between D and E

MULTIPROD has a broad field of potential applications. By calling MULTIPROD, multiple geometrical transformations such as rotations or roto-translations can be performed on large arrays of vectors in a single step and with no loops. Multiple operations such as normalizing an array of vectors, or finding their projection along the axes indicated by another array of vectors can be performed easily, with no loops and with two or three rows of code.

Sample functions performing some of these tasks by calling MULTIPROD or by using parts of its code are included in the separate toolbox "Matlab Central > File Exchange > Vector algebra for multidimensional arrays of vectors".

A sample function (LOC2LOC) performing a multiple roto-translation by calling MULTIPROD is included in this package. This function uses 3-element translation vectors and 3x3 rotation matrices. If you prefer to work with homogeneous coordinates and 4x4 roto-translation matrices, you can obtain the same result just by calling MULTIPROD twice.

If you have a single matrix R, and you want to multiply it by an array of vectors MultiV,

**you need to use the function MATEXP to replicate R and create an array of matrices MultiR which can be multi-multiplied by MultiV with MULTIPROD:**

MultiV2 = MULTIPROD(MultiR, MultiV, . . . )MATEXP is included in this package.

MULTIPROD calls, in some cases, the function MULTITRANSP, performing matrix transpositions in arrays of matrices. I wrote it as a separate function because I discovered it can be useful for several different purposes. MULTITRANSP is included in this package.

A document written with MS Word and explaining in detail and schematically the meaning of the implemented syntaxes is included, for those who want to understand the code. The help text in the function was written with extreme care, and should be enough for those who just want to use the function.

Since I wanted to be of service to as many people as possible, MULTIPROD itself was written, debugged, refined and in several parts even optimized for speed with extreme care. I hope it or a future version of it, modified according to your suggestions, will be included in the next version of MATLAB. The code ("testMULTIPROD. m") I used to test the function output is included in this package.

**Examples:**

1) If A is a 5x(6x3)x2 array,and B is a 5x(3x4)x2 array,

C = MULTIPROD(A, B, [2 3]) is a 5x(6x4)x2 array.

2) If A is a 5x(6x3)x2 array,

and B is a 5x(1x1)x2 array,

C = MULTIPROD(A, B, [2 3]) is a 5x(6x3)x2 array.

**• MATLAB Release: R14**

**Demands:****Multiplying two N-D arrays of matrices 1.0 scripting tags:**multiplying arrays, vectors, matrices, matlab mathematics, multiprod, matrices vectors.

**What is new in Multiplying two N-D arrays of matrices 1.0 software script?**- Unable to find Multiplying two N-D arrays of matrices 1.0 news.

**What is improvements are expecting?**Newly-made Multiplying two N-D arrays of matrices 1.1 will be downloaded from here. You may download directly. Please write the reviews of the Multiplying two N-D arrays of matrices. License limitations are unspecified.