This toolbox was written to complete the incomplete set of vectorial operations provided with MATLAB, and to enhance the features of two of them (DOT and CROSS), by enabling virtual array expansion (AX). AX is enabled in all the binary operations included in this toolbox, and allows you, for instance, to multiply a single vector with an array of vectors, by virtually replicating the vector to match the size of the array.

All the functions in this toolbox can automatically operate on block arrays (arrays of any size containing vectors along one of their dimensions).

MATLAB includes four functions which can apply binary operations on the vectors contained in two block arrays:

They all perform multiple operations, but they cannot perform automatic AX. MATLAB also includes function SUM, which can be used to add together two or more vectors contained in a single matrix or N-D array. For instance, if A is a MN matrix, regarded as a concatenation of N column vectors, these vectors can be added together by using SUM(A, 2), which yields an M1 matrix.

DOT2 and CROSS2, included in this toolbox, enable AX for dot and cross products.

Outer products, orthogonal cross divisions, and generalized cross divisions with AX enabled, can be performed by calling functions OUTER, OCD, and CROSSDIV, included in this toolbox.

As for cross divisions (CDs), they were not invented until now (see Weisstein, 2008), but I needed them, so I defined and implemented them (de Leva, 2008). They determine one of the infinitely many anticrossproducts of the cross product a  b (see screenshot). They were not indispensable, but markedly simplified my equations and my code, and those who appreciate short symbolic equations are likely to love them. Without CDs, in some cases you are forced to write scalar equations, containing negative terms and operations involving various combinations of scalar components. In other cases, you need to write longer vectorial equations. Those equations are not complex, but they are certainly less simple than a CD. For instance, a typo is more likely to occur when you write scalar equations than when you write a CD. See CROSSDIV help for more detailed explanations.

A list of simple vectorial operations is given below. Only the first five are implemented in intrinsic MATLAB functions. The others are implemented in this toolbox. All of them can operate on N-D arrays of vectors. See the respective help texts for further details.

A detailed definition of AX is given in the manual of the MULTIPROD toolbox, published on MATLAB Central (file #8773).

The ARRAYLAB toolbox

The functions included in this toolbox comply with the ARRAYLAB philosophy, and are a part of the "ARRAYLAB toolbox" (see the manual of the MULTIPROD toolbox, MATLAB Central, file #8773).

Some of them call MULTIPROD. This function is a powerful generalization for N-D arrays of the MATLAB function MTIMES and the matrix multiplication operator (*).

MULTIPROD has a broad field of potential applications. For instance, it can use large arrays of 33 or 44 transformation matrices to perform, in a single step and with no loops, multiple geometrical transformations (rotations, roto-translations) on arrays of vectors. Thus, it deserves a separate introduction and I published it in a separate package on MATLAB Central (file #8773).

Some other functions of this toolbox call BAXFUN, another function which belongs to the ARRAYLAB toolbox and which is published separately on MATLAB Central (file #23084).

Output testing

The functions testDOT2, testCROSS2, testOUTER, testPROJECTION, testREJECTION, testUNIT, testXDIV, testOCD, stored in a separate folder "Testing", contain the code I used to test the output of the main functions. Since UNIT calls MAGN, testUNIT tests both UNIT and MAGN.

Dear Xiaodong, thank you for your offer, but I cannot include your function DOT3 in my package. The dot product requires the complex conjugate of its first operand to deal with complex vectors. Even the MATLAB function DOT applies it:

C = SUM(CONJ(A).*B, DIM)

Notice that, for real arrays,

CONJ(A) = A

hence, your function DOT3 will give correct results only when operating on real vectors, while DOT2, included in my package, is supposed to give correct results for both real and complex vectors.

Moreover, your function does nothing else than calling MULTIPROD. It would be more convenient to call it directly, using syntax 4b:

C = MULTIPROD(A, B, DA1, DB2)

For instance, if vectors are contained along dimension 2 of A and B, and you do not want to compute the conj(A), you can use

Paolo and users of this package: I made a code to do the dot product similar to dot2 but without applying complex conjugate of the first input array: http://www.mathworks.com/matlabcentral/fileexchange/41794-dot-product-of-two-n-dimensional-arrays

"...I have 2 sets of vectors where I want to get the inner product of each vector in the first set with each vector in the second. E.g. 24 10x1 vectors with 64 10x1 vectors... could you give me some suggestions for how I could do it?"

The Array expansion (AX) engine used by all the functions in this toolbox can solve this kind of problems quickly and efficiently.

DOT2 can perform the operation described by Mark Flynn with a single command, provided that you define the two block arrays as a 24x1x10 array A and a 1x64x10 array B. Both arrays contain 10-element vectors along dimension 3.

Hi Pablo, Would you mind re-submitting the MULTIPROD function please? I think it has become lost in the re-jig of The Mathworks' site.

Thanks!

Tom Clark

Comment only

17 Mar 2007

rodolfo molina

05 Dec 2006

Giuseppe Vannozzi

Excellent work, Paolo!

04 Dec 2006

Pietro Picerno

something new to write in Maths' books: the cross division. Excellent!

Updates

31 Oct 2005

Keyword list and Description were updated. The keyword list had been truncated arbitrarily to 70 characters. Some characters in the Description were not readable and some refinements were needed.

31 Oct 2005

With respect to my first update, submitted but not yet published, I updated here only the attached file, now containing new versions of PROJECTION and REJECTION, in which I added help text.

03 Nov 2005

For the sake of completeness, after working on my other two packages, I thoroughly revised also this Description, and added a "Manual" in the attached file.

22 Feb 2006

Updated function CROSSDIV to version 1.2.2. Revised manual.

30 Mar 2006

The code was optimized according to suggestions automatically generated by function M-Lint.

21 Nov 2006

The function CROSSDIV was generalized (v.2). Now it can automatically perform any kind of definite cross division. A function performing orthogonal cross divisions was added.

27 Nov 2006

Function CROSSDIV was generalized. The new version (2), compatible with the previous ones, can automatically perform any kind of definite cross division. A function performing orthogonal cross divisions was added. The manual was updated.

Removed two unnecessary and not commented files from the "Testing" folder

26 Feb 2009

Version 2.0. Includes two new functions (DOT2, CROSS2). Exploits quicker, more efficient, and more powerful engines. Introduces virtual array expansion, which allows you, for instance, to multiply a single vector by an array of vectors.