5.0

5.0 | 3 ratings Rate this file 39 downloads (last 30 days) File Size: 90.27 KB File ID: #8782

Vector algebra for arrays of any size, with array expansion enabled

by Paolo de Leva

 

21 Oct 2005 (Updated 26 Feb 2009)

Code covered by the BSD License  

Multiple dot, cross, and outer products, cross divisions, norms, normalizations, projections, etc.

Download Now | Watch this File

File Information
Description

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:

+ (generic operator usable to perform vector additions)
- (generic operator usable to perform vector subtractions)
DOT (specific function performing dot products)
CROSS (specific function performing cross products)

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.

Operation: MATLAB implementation
------------------------------------------------
Repeated addition: SUM
Binary addition: +
Subtraction: -
Dot product: DOT
Cross product: CROSS

Operation: ARRAYLAB implementation
----------------------------------------------------
Euclidean norm: MAGN
Normalization: UNIT
Dot product (AX enabled): DOT2
Cross product (AX enabled): CROSS2
Outer product (AX enabled): OUTER
Orthogonal cross division (AX enabled): OCD
Generalized cross division (AX enabled): CROSSDIV
Projection (AX enabled): PROJECTION
Rejection (AX enabled): REJECTION

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.

REFERENCES

de Leva P., 2008. Anticrossproducts and cross divisions. Journal of Biomechanics, 8, 1790-1800 (http://dx.doi.org/doi:10.1016/j.jbiomech.2007.09.030)

Weisstein E. W. Vector Division. From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/VectorDivision.html (Retreived on 2008 Dec 4)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Multiple matrix multiplications, with array expansion enabled, Binary array expansion function

MATLAB release MATLAB 7 (R14)
Other requirements You must install the toolbox engines, MULTIPROD and BAXFUN (files #8773 and #23084). MULTIPROD and BAXFUN call function BSXFUN, built-in in MATLAB R2007a. For earlier MATLAB releases, use Schwarz's BSXFUN replacement (MATLAB Central, file #23005).
Zip File Content  
Other Files
cross2.m,
crossdiv.m,
dot2.m,
magn.m,
ocd.m,
outer.m,
projection.m,
rejection.m,
Testing/rearrange.m,
Testing/testCROSS2.m,
Testing/testDOT2.m,
Testing/testOCD.m,
Testing/testOUTER.m,
Testing/testPROJECTION.m,
Testing/testREJECTION.m,
Testing/testUNIT.m,
Testing/testXDIV.m,
unit.m,
Vector Algebra Toolbox Manual.pdf
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
04 Dec 2006 Pietro Picerno

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

05 Dec 2006 Giuseppe Vannozzi

Excellent work, Paolo!

17 Mar 2007 rodolfo molina  
18 Nov 2008 Thomas Clark

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

Please login to add a comment or rating.
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.

03 Oct 2007

Function OUTER now uses the complex conjugate of its first input argument (MATLAB function DOT does the same). Thus, over the complex field, OUTER is not anymore equivalent to a (multiple) matrix multiplication.

04 Dec 2008

Added references, inserted figure about cross division in toolbox manual

05 Dec 2008

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.

Tag Activity for this File
Tag Applied By Date/Time
linear algebra Paolo de Leva 22 Oct 2008 08:03:42
outer product Paolo de Leva 22 Oct 2008 08:03:42
cross division Paolo de Leva 22 Oct 2008 08:03:42
unit vector Paolo de Leva 22 Oct 2008 08:03:42
norm Paolo de Leva 22 Oct 2008 08:03:42
linear algebra Cristina McIntire 05 Dec 2008 14:34:54
algebra Cristina McIntire 05 Dec 2008 14:34:54
linear Cristina McIntire 05 Dec 2008 14:34:54
projection Paolo de Leva 24 Feb 2009 04:27:26
rejection Paolo de Leva 24 Feb 2009 04:27:33
algebra Paolo de Leva 24 Feb 2009 04:28:29
magnitude Paolo de Leva 24 Feb 2009 04:29:12
vector Paolo de Leva 24 Feb 2009 04:29:20
vector algebra Paolo de Leva 24 Feb 2009 04:29:27
array Paolo de Leva 24 Feb 2009 04:50:29
multidimensional array Paolo de Leva 24 Feb 2009 04:50:57
replication Paolo de Leva 24 Feb 2009 05:00:31
expansion Paolo de Leva 24 Feb 2009 05:00:31
array expansion Paolo de Leva 24 Feb 2009 05:00:31
matrix expansion Paolo de Leva 24 Feb 2009 05:00:31
arraylab Paolo de Leva 24 Feb 2009 05:00:31
singleton expansion Paolo de Leva 24 Feb 2009 05:00:31
vector expansion Paolo de Leva 24 Feb 2009 05:00:31
product Paolo de Leva 24 Feb 2009 05:22:33
vector product Paolo de Leva 24 Feb 2009 05:22:33
scalar product Paolo de Leva 24 Feb 2009 05:22:33
inner product Paolo de Leva 24 Feb 2009 05:22:33
cross product Paolo de Leva 24 Feb 2009 05:22:33
dot product Paolo de Leva 24 Feb 2009 05:22:33
virtual replication Paolo de Leva 24 Feb 2009 08:22:35
virtual expansion Paolo de Leva 24 Feb 2009 08:22:35
dot2 Paolo de Leva 27 Feb 2009 12:12:18
unit Paolo de Leva 27 Feb 2009 12:12:18
magn Paolo de Leva 27 Feb 2009 12:12:18
ocd Paolo de Leva 27 Feb 2009 12:12:18
crossdiv Paolo de Leva 27 Feb 2009 12:12:18
outer Paolo de Leva 27 Feb 2009 12:12:18
cross2 Paolo de Leva 27 Feb 2009 12:12:18
division Paolo de Leva 27 Feb 2009 13:45:54
multiple operation Paolo de Leva 27 Feb 2009 13:45:54
vectorial operation Paolo de Leva 27 Feb 2009 13:45:54
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com