Order of Operations in Matrix Multiplication
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 (2023). 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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |