Britannica Sources used in this answer

Why does the order of matrix multiplication matter?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

In linear algebra, the order of matrix multiplication matters because matrix multiplication is not commutative. Unlike the multiplication of ordinary numbers, where ab=ba always holds true, the product of two matrices A and B generally results in different outcomes depending on whether you calculate AB or BA.1

The definition of matrix multiplication requires that the number of columns in the first matrix must equal the number of rows in the second. Consequently, if the dimensions of A and B are not compatible in both directions, one product may be mathematically defined while the other is not. Even when both AB and BA are defined—such as with square matrices of the same order—the resulting elements are determined by the sum of products of specific rows and columns, which change entirely when the order of the matrices is swapped.1

While matrix multiplication is associative and distributive, the failure of the commutative law is a fundamental characteristic of matrix algebra.1