Order of Operations in Matrix Multiplication

Matlab implements matrix multiplication differently on Mac OS X, Linux, and Windows.
43 Downloads
Updated 15 Oct 2015

View License

The main goal of this script is to illustrate the fact that:
Matlab implements matrix multiplication differently
on Mac OS X, Linux, and Windows.

The differences can sometimes lead to unexpected outcomes.

Background: We've encountered a situation where the same Matlab
script yields vastly different results when run on Mac, Linux,
and Windows. Our investigation reveals that the root causes are:

(1) The associative property of addition:

(A + B) + C = A + (B + C)

does NOT hold when we are dealing with finite precision
arithmetic (due to rounding errors).

(2) Matlab implements matrix multiplication differently on
Mac OS X, Linux, and Windows. Specifically, in Mac OS X,
the elements of the inner product are added from the
lowest index to the highest index (1,2,...,N). In Linux
and Windows, it adds the odd indices first, then the even
indices, then the two sums are added together

I've tested this on R2014b, but I believe it applies to R2015b, R2015a, and earlier releases as well.

Cite As

Nam Phamdo (2024). Order of Operations in Matrix Multiplication (https://www.mathworks.com/matlabcentral/fileexchange/53549-order-of-operations-in-matrix-multiplication), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Operating on Diagonal Matrices in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0