No, swapping the order can change the result, because each product applies a different chain of actions.
Matrix multiplication looks familiar at first. You see symbols that resemble ordinary multiplication, you line up two arrays of numbers, and you get another array. Then you try the move that works with numbers: you flip the order. That’s when matrices push back.
This article explains what “commutative” means for matrices, shows a clean counterexample, and builds an intuition you can reuse in homework, coding, and proofs. You’ll also see the main situations where matrices do commute, plus practical checks that save time.
What Commutative Means In One Line
A multiplication rule is commutative when switching the order never changes the product. With numbers, 3×5 equals 5×3. With matrices, the comparable statement would be:
- If the products exist, AB equals BA for all compatible matrices A and B.
That statement fails. Two matrices can both be square of the same size, both products can exist, and the results can still differ.
Why Order Matters With Matrices
A matrix is more than a bag of numbers. It often stands for an action: a rotation, a stretch, a shear, a projection, or a change of coordinates. Multiplying matrices composes actions. The product AB means “do B first, then do A.”
Once you read AB as a sequence, swapping order stops feeling harmless. Doing “rotate then project” is not the same as “project then rotate.” Even if both steps are linear, the end result depends on which step happens first.
Composition Is The Real Engine
Think of functions. If f(g(x)) is your output, swapping the order gives g(f(x)). Those are rarely equal. Matrices inherit that same behavior because they encode linear functions.
Even Size Can Block The Swap
Sometimes the “not commutative” message shows up before you even compute. If A is 2×3 and B is 3×2, then AB is 2×2 and BA is 3×3. One can’t equal the other because they don’t even live in the same space.
A Quick Counterexample You Can Reuse
To show a rule is not commutative, you only need one pair where the swap changes the result. Here is a standard pair of 2×2 matrices:
Let
A = [[0, 0], [1, 0]] and B = [[1, 0], [0, 0]].
Multiply in one order and you get back A. Multiply in the other order and you get the zero matrix. Same ingredients, different outcome. That single fact is enough to settle the general question.
What That Example Is Telling You
Those two matrices represent actions that erase parts of a vector in different ways. When B goes first, it wipes out information that A would have used. When A goes first, it moves information into a slot that survives the wipe. The swap changes what gets preserved.
Is Matrix Multiplication Commutative? What To Know Before You Swap Order
So the rule is clear: you can’t assume AB equals BA. Still, you’ll often see people flip order in algebra with matrices. Some moves remain legal, and some don’t. The trick is learning which patterns are safe.
Moves That Stay Safe
- Associative regrouping: (AB)C equals A(BC) when the sizes match.
- Distributive expansion: A(B+C) equals AB+AC, and (A+B)C equals AC+BC.
- Identity behavior: AI equals IA equals A when I is the right size.
Moves That Break When You Swap
- Canceling by order-blind division: From AB=AC you can’t “divide by A” unless A is invertible and you multiply by A⁻¹ on the left in the right way.
- Reordering factors: ABC is not the same as BAC, ACB, or CBA in general.
If you want a clean list of these properties with short explanations, Khan Academy’s properties of matrix multiplication lays them out in a student-friendly way.
Where The Noncommutativity Shows Up In Geometry
It helps to tie the algebra back to pictures. In 2D, linear transformations act on shapes and vectors. Multiply two transformation matrices and you get the combined transformation. The order tells you which transformation happens first.
Rotation And Stretch Do Not Usually Commute
Pick a stretch that pulls only in the x-direction. Pair it with a 90° rotation. Stretching a vector and then rotating sends the “long” direction somewhere new. Rotating first and then stretching pulls along a different axis. You end up in different places, even with the same two steps.
Projection Is A Classic Order Trap
Projecting onto a line collapses a whole plane onto that line. Do that first and you lose the component that a later rotation would have used. Rotate first and you change which component survives the projection. In code, this shows up as “my pipeline changed” when you reorder matrix multiplications.
Table Of Matrix Multiplication Rules You Can Trust
| Rule Or Pattern | Works For Matrices? | Plain-Language Note |
|---|---|---|
| AB = BA (commutative) | No, not in general | Order changes the composed action. |
| (AB)C = A(BC) (associative) | Yes | You can regroup without changing order. |
| A(B+C) = AB + AC | Yes | Left factor distributes across a sum. |
| (A+B)C = AC + BC | Yes | Right factor distributes across a sum. |
| AI = IA = A | Yes | Identity matrix acts like “do nothing.” |
| (AB)⁻¹ = B⁻¹A⁻¹ | Yes, when A and B invertible | Inverse reverses order, like undoing steps. |
| AB = 0 implies A = 0 or B = 0 | No | Nonzero matrices can multiply to zero. |
| det(AB) = det(A)det(B) | Yes (square matrices) | Determinant respects multiplication. |
When Matrix Multiplication Is Commutative In Special Cases
Even though commutativity fails in general, some pairs of matrices commute. When that happens, it’s a real structural fact about the pair. Here are the main families students meet first.
Identity And Scalar Multiples Of Identity
The identity matrix I commutes with every matrix of the same size: AI=IA. Any scalar multiple cI also commutes with every matrix, because it scales every vector without changing direction.
Diagonal Matrices In The Same Basis
If A and B are diagonal (with respect to the same coordinate basis) and have the same size, then AB=BA. Multiplying diagonal matrices just multiplies matching diagonal entries, and that operation doesn’t care about order.
Powers And Polynomials Of One Matrix
A commutes with A², A³, and any polynomial in A, like (2A³ − A + I). In a wider sense, if B can be written as a polynomial in A, then AB=BA. Both sides reduce to combinations of the same powers of A.
Matrices That Share Eigenvectors
When two matrices are diagonalizable by the same change-of-basis matrix, they commute. In plain terms, they pull along the same set of eigenvector directions. That shared structure forces the actions to line up.
What Changes When One Factor Is A Number
Scalars commute with matrices. If c is a real number, then cA equals Ac, because “multiply every entry by c” doesn’t depend on side. This is one reason matrix algebra can feel familiar in early steps.
That comfort can mislead you when both factors are matrices. A number scales, while a matrix can rotate, shear, project, or mix coordinates. Scaling and rotating can commute in some setups. Two different mixes of coordinates often don’t.
A quick habit helps: when you see a scalar next to a matrix, you can slide it across. When you see two matrices next to each other, treat the order like a fixed recipe step unless you’ve proved they commute.
MIT’s linear algebra notes state the noncommutative rule plainly and also mention standard exceptions like the identity case. You can see that in MIT OpenCourseWare’s “Matrices 1: Matrix Algebra” notes.
Table Of Common Commuting Situations
| Situation | What You Can Conclude | Quick Check |
|---|---|---|
| B = cI | AB = BA | B has zeros off-diagonal, equal diagonal entries. |
| A and B diagonal (same size) | AB = BA | All off-diagonal entries are zero. |
| B is a polynomial in A | AB = BA | Try to express B using I, A, A², … |
| A and B simultaneously diagonalizable | AB = BA | They share a full eigenvector basis. |
| A and B are both diagonal in one basis | AB = BA | Find P with P⁻¹AP and P⁻¹BP diagonal. |
| A and B are rotations in the same plane | AB = BA | Both are 2D rotation matrices about the origin. |
| Commutator AB−BA equals zero | AB = BA | Compute AB−BA and see if all entries are zero. |
How To Tell If Two Matrices Commute
There’s a direct test: compute AB and BA and compare. That’s fine for small matrices and quick homework checks. For bigger systems, you’ll want smarter shortcuts.
Use The Commutator
The commutator of A and B is [A,B] = AB − BA. The matrices commute exactly when the commutator is the zero matrix. This turns “compare two products” into “check one difference.” It’s the same arithmetic work, yet it becomes a useful symbol in proofs and programming.
Look For A Shared Diagonal Form
If you can diagonalize both matrices using the same change-of-basis matrix P, then they commute. In class problems, this often shows up when A and B represent compatible measurements in the same coordinate system.
Spot A Function Relationship
If you can write B using A, like B = A² + 2I, they commute. In applied work, this pops up when B is built from A using a fixed model recipe.
Common Missteps Students Make
Swapping The Order Inside A Product
Seeing AB and rewriting it as BA is the big one. Train yourself to treat the order as fixed, like a sentence. Flip the words and the meaning changes.
Assuming Cancellation Works Like Numbers
If AB=AC, you can multiply on the left by A⁻¹ if A is invertible, giving B=C. If A is not invertible, that move is not allowed. Even with an inverse, you must multiply on the correct side. Left-multiplying and right-multiplying are different operations.
Forgetting That Vectors Are Matrices Too
A column vector is an n×1 matrix. A row vector is a 1×n matrix. Multiplying a row by a column gives a 1×1 matrix (a scalar). Swapping the order gives an n×n matrix (an outer product). Different objects, different meaning.
Why This Matters In Practice
If you’re doing graphics, robotics, data science, or any kind of linear model, matrix multiplication order is part of the pipeline. Two lines of code that look similar can produce different geometry, different coordinate frames, or different fitted coefficients.
Coordinate Changes And Units
A common pattern is P⁻¹AP, which changes the basis of a linear map A. If you shuffle those factors, you no longer represent the same map in a new coordinate system. You represent a different map.
Systems And Repeated Steps
In Markov chains and linear recurrences, multiplying by a transition matrix applies one step of the system. Two different transition steps in a row depend on order. That changes intermediate states and can change long-run behavior.
A Mental Model That Sticks
Read AB as “B then A.” If you only remember one thing, remember that. When you see three factors, read right to left as a chain of actions. Then ask: if I swap two steps, would that change what the next step receives? If the answer is yes, the swap changes the product.
Wrap-Up
Matrix multiplication is associative and distributive, so you can regroup and expand while keeping the same order. It is not commutative in general, so you can’t swap order unless you have a proven reason.
When two matrices do commute, it points to shared structure, like a common eigenvector basis, a shared diagonal form, or a function relationship such as one matrix being a polynomial in the other. That’s not a coincidence. It’s a clue about how those linear actions fit together.
References & Sources
- Khan Academy.“Properties Of Matrix Multiplication.”Summarizes which algebra rules hold for matrices and notes that order-swapping can fail.
- MIT OpenCourseWare.“Matrices 1: Matrix Algebra.”States that AB need not equal BA and lists standard matrix algebra facts and exceptions.