Matrix Commutator
Edit two real 2x2 matrices to compare AB and BA, visualize their action on one vector and distinguish a zero commutator from its always-zero trace.
By Riano · Published · Updated · Report a correction
Matrix Commutator: measuring the difference in composition order
Matrix multiplication is generally not commutative. Applying transformation B then A can yield a different result than applying A then B. The matrix commutator C = AB − BA measures this difference. If C is the zero matrix, the matrices commute. This experiment lets you compare the action of AB and BA on a vector, and observe the resulting difference vector.
Worked example: matrix units
Consider the "Matrix units" preset: A = [[0, 1], [0, 0]] and B = [[0, 0], [1, 0]]. Let us compute the commutator and apply it to the vector v = (1, 1).
- First, calculate AB: the product is [[1, 0], [0, 0]]. Applying this to v = (1, 1) yields ABv = (1, 0).
- Next, calculate BA: the product is [[0, 0], [0, 1]]. Applying this to v = (1, 1) yields BAv = (0, 1).
- Now compute the commutator C = AB − BA = [[1, 0], [0, -1]].
- The trace of C is the sum of its diagonal elements: 1 + (-1) = 0.
- Applying C to v = (1, 1) yields Cv = (1, -1). This matches the difference vector ABv − BAv = (1, 0) − (0, 1) = (1, -1).
Experimenting with the commutator
Open Matrix Commutator. You can select presets or edit individual matrix and vector entries to observe their effects.
- Select the "Diagonal and swap" preset. The commutator matrix C becomes [[0, -1], [1, 0]]. With v = (1, 1), you can see Cv = (-1, 1).
- Click "Swap A and B". Observe that the entries of C are all negated, becoming [[0, 1], [-1, 0]], and the vector Cv reverses direction.
- Change the preset to "Identity". Because the identity matrix commutes with any matrix, C becomes the zero matrix, and trace(C) is 0. Both ABv and BAv coincide on the canvas.
- Edit the vector to (0, 0). All transformation vectors collapse to the origin, regardless of whether the matrices commute.
Properties and edge cases
A key property of the matrix commutator is that its trace is always zero, regardless of the matrices A and B. This is because trace(AB) = trace(BA) for any square matrices. However, as demonstrated by the "Matrix units" example, a zero trace does not imply that the matrices commute (i.e., that C is the zero matrix). The trace is zero, but C itself is nonzero.
Other boundary cases include equal matrices (A = B), where the commutator is trivially zero. Furthermore, a zero vector (0, 0) will result in coincident output vectors even if the matrices do not commute. Therefore, visual coincidence of ABv and BAv for a single vector does not guarantee that the matrices commute; one must inspect the commutator matrix C itself.
The canvas adapts a common scale to keep all four vectors in view, preserving their relative lengths. Drag to pan and use Reset view to recenter; this does not change the matrices. Displayed matrix/vector components are rounded to two decimals, and the commute indicator uses a small floating-point tolerance. The interface handles blank, nonfinite, or out-of-range inputs with an explicit validation state, preventing mathematically undefined behaviors without coercing inputs to zero.
References
For a formal definition and properties of the matrix commutator, see the NIST Digital Library of Mathematical Functions: DLMF 1.2(vi) Matrices: Commutator.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Matrix Commutator module.
Try Matrix Commutator on Riano →