On this page
Matrix multiplication usually depends on order: AB and BA generally differ, and the Wikipedia article on commuting matrices gives a 2×2 pair where they differ. A question asking for all B with AB = BA wants the special matrices that do commute. The method: put in unknowns, multiply, compare entries, solve.
How do you set up AB = BA with unknown entries?
Take the matrix you are given and a general matrix with four unknowns:
A = [1 2; 3 4] (rows separated by a semicolon)
B = [a b; c d]
Multiply both ways (row of the first times column of the second):
AB = [a + 2c, b + 2d; 3a + 4c, 3b + 4d]
BA = [a + 3b, 2a + 4b; c + 3d, 2c + 4d]
Matching entries gives four equations:
Top left: a + 2c = a + 3b, so 2c = 3b.
Top right: b + 2d = 2a + 4b, so 2d = 2a + 3b.
Bottom left: 3a + 4c = c + 3d, so d = a + c.
Bottom right: 3b + 4d = 2c + 4d, so 3b = 2c.
Why do four equations give infinitely many answers?
Equations 1 and 4 say the same thing. And if 2c = 3b, then equation 2 gives d = a + 3b/2 = a + c, which is equation 3. So only two of the four equations are independent, and two of the four unknowns stay free.
To avoid fractions, let b = 2t. Then c = 3t and d = a + 3t, with a and t any real numbers:
B = [a, 2t; 3t, a + 3t]
That is the complete answer. Split it:
B = (a − t)I + tA
Check: tA = [t, 2t; 3t, 4t], and adding (a − t) on the diagonal gives [a, 2t; 3t, a + 3t]. So the commuting matrices are exactly the combinations xI + yA.
How do you check the answer by multiplication?
Take a = 0 and t = 1, so B = [0 2; 3 3].
AB = [1·0 + 2·3, 1·2 + 2·3; 3·0 + 4·3, 3·2 + 4·3] = [6 8; 12 18]
BA = [0·1 + 2·3, 0·2 + 2·4; 3·1 + 3·3, 3·2 + 3·4] = [6 8; 12 18]
They match. Now try a matrix outside the family, B = [1 0; 0 0]: AB = [1 0; 3 0] but BA = [1 2; 0 0], so they do not commute, as predicted.
Is there a shortcut for any 2×2 matrix?
Run the same steps for A = [p q; r s]. The four equations shrink to three:
qc = rb
q(d − a) = b(s − p)
r(d − a) = c(s − p)
These are the components of a zero cross product: (b, c, d − a) × (q, r, s − p) = 0. A zero cross product means the two vectors are parallel, so (b, c, d − a) = t(q, r, s − p). Written as a matrix, that says B = aI + t(A − pI), which is again a combination of I and A.
For our A, (q, r, s − p) = (2, 3, 3), and the solutions above are (b, c, d − a) = (2t, 3t, 3t). The hero diagram shows this: the solutions lie on one line through the origin. Our walkthrough on expanding a cross product without sign errors covers the determinant steps.
The shortcut fails only when q = r = 0 and p = s, that is, when A is a scalar matrix kI. Then every 2×2 matrix commutes with A, as the commuting matrices article states: a matrix commutes with every matrix of its size if and only if it is scalar. More generally, it notes that when the minimal polynomial of A equals its characteristic polynomial, any matrix that commutes with A is a polynomial in A.
What mistakes cost marks here?
Missing that two equations repeat, then expecting a unique solution.
Multiplying BA in the wrong order. BA's first row comes from B's first row.
Stopping before the split when the question asks you to show B = xI + yA.
The identity (A + B)² = A² + 2AB + B² holds only when AB = BA, which our post on why (A + B)² fails for matrices works through. And because I and A always commute, the Cayley-Hamilton method for A⁻¹ and A⁵⁰ can treat A like an ordinary variable.
To practise, try A = [2 1; 0 3] and predict the family before you multiply: (b, c, d − a) should be a multiple of (1, 0, 1). If you get stuck partway, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer, so you can see which equation went wrong.



