Order of Operations in Matrix Multiplication

Matlab implements matrix multiplication differently on Mac OS X, Linux, and Windows.

You are now following this Submission

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 (2026). Order of Operations in Matrix Multiplication (https://www.mathworks.com/matlabcentral/fileexchange/53549-order-of-operations-in-matrix-multiplication), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0