RobotGuide
Math foundations/Matrix Multiplication: Chaining Transformations, Not a Table Operation

Foundations T8 / 27 · Linear Algebra and Geometry

Matrix Multiplication: Chaining Transformations, Not a Table Operation

The j-th column of AB = A applied to b_j — matrix multiplication is the pipeline «first B, then A». The order is a physical fact: rotate-then-stretch ≠ stretch-then-rotate.

About 40 min3 theorems9 proof steps4 self-test questions

One-line takeaway

The only meaning of (AB)x = A(Bx): first hand x to B, then hand the result to A. So AB ≠ BA is not a matter of arithmetic convention but the difference between «dress first, then pack the suitcase» and «pack the suitcase first, then dress». A robot multiplies a matrix every time it passes a coordinate frame — kinematic chains and error propagation both keep their books by this law.

Animated · the same input arrow, AB and BA land at different endpoints — drag the slider to change the input direction; it holds everywhere

In T1 you learned how a single matrix acts on a vector. But a robot's tip pose = base × shoulder × elbow × wrist, four transformations stacked — and the law of stacking is matrix multiplication. If multiplication were just «tables multiplied entrywise», multi-stage transformations in this world would make no sense.

Why this tool exists

You can handle a single matrix — what about a chain? Linear algebra's answer to this intuitive question is beautifully cold: the matrices of a chain multiply. That is the whole thing.

This page also gives you the minimal physical counterexample for «why AB ≠ BA». Whoever sees non-commutative matrix multiplication for the first time in a textbook assumes it is a weird rule mathematicians invented; this page proves it is a fact about the world.

Definitions

Definition 2.1 Matrix multiplication (the only reasonable definition)

(AB)x is defined as «first compute Bx, then apply A». The equivalent table form: (AB)ij = row i of A dotted with column j of B. Both forms give the same number, but to understand a robot's multi-stage transformations you are only allowed the first — it is a verb (one action followed by another), not a noun (a table operation).

Definition 2.2 Linear transformations

A transformation T is linear when T(x + y) = T(x) + T(y) and T(cx) = cT(x). Rotation, scaling, projection, shear — all of them. A matrix is the «bookkeeping form» of a linear transformation: given a basis, each linear transformation corresponds to exactly one matrix.

Theorems and proofs

Theorem 2.1 Associativity (AB)C = A(BC)

For a chain of three transformations, it does not matter which two you combine first.

Proof

For any vector x: ((AB)C)x = (AB)(Cx) = A(B(Cx)); likewise (A(BC))x = A((BC)x) = A(B(Cx)).

The two transformations act identically on every x, so they are the same transformation, corresponding to the same matrix.∎

NoteThis is why a robot's kinematic chain can be multiplied from the tip backward or from the base backward with the same result — where you put the parentheses inside a chain is free, but the order of multiplication (who acts first, who acts second) is not.

Theorem 2.2 The product of rotation matrices is a rotation matrix

R(α)R(β) = R(α+β), and the product is still orthogonal (length-preserving, angle-preserving).

Proof

For the unit vector x = (cos θ, sin θ): R(α)x = (cos(θ+α), sin(θ+α)) (proved in T1 — a rotation matrix adds the angle α to the polar angle).

So R(β)x first turns θ into θ+β, and left-multiplying by R(α) turns it into θ+β+α — exactly what R(α+β) does to x.

The two matrices agree on every vector, so R(α)R(β) = R(α+β). Rotation preserves length (‖R(α+β)x‖ = ‖x‖), and every invertible length-preserving matrix is orthogonal.∎

NoteClosure = do it once, then do it again, and you are still rotating. This is what lets «orientation» be accumulated without the bookkeeping running away. The exponential notation R(α)^k = R(kα) follows immediately, and in this page's real run the drift of composing 100 small steps was only 10-15.

Theorem 2.3 AB ≠ BA (a minimal physical counterexample)

A = a 90° rotation, B = a stretch by factor 2 along the x-axis. Then AB and BA are not merely unequal — the shapes of their effects differ.

Proof

A = [[0,−1],[1,0]], B = [[2,0],[0,1]]
AB = [[0,−1],[2,0]], BA = [[0,−2],[1,0]]

Watch them act on the basis vector e_1 = (1,0): AB e_1 = (0, 2) — the stretch first turns e_1 into (2,0), then the 90° rotation gives (0,2). BA e_1 = (0, 1) — the rotation first turns e_1 into (0,1), and the stretch acts only on the x direction, so it leaves it alone.

Same starting point, different endpoints (0,2) vs (0,1). One counterexample kills the identity AB = BA.∎

NoteReplace «stretch» with any non-isotropic operation (anything that neither translates nor rotates) and the conclusion stands. So in robot calibration, «install the offset first, then compensate» and «compensate first, then install the offset» are two different engineering schemes, not a mere preference about parameter order.

Work it by hand

A robot wrist first rotates 90° about the base, then stretches by factor 2 along its own x direction (say, a telescoping rod). Is the total transformation AB or BA? And what does each do to e_1?

  1. «First B, then A» corresponds to the matrix AB (the position convention before Theorem 2.1: the rightmost acts first). Stretch-then-rotate = B on the right, A on the left, total transformation AB.
  2. AB e_1: e_1 is first stretched by B into (2,0), then rotated by A into (0,2). The elongation factor survives.
  3. BA e_1: e_1 is first rotated by A into (0,1), and B stretches only the x direction, so (0,1) is untouched. The elongation is entirely lost.
  4. Conclusion: whether the telescoping rod sits «before» or «after» the rotation changes its behavior completely. This is not a mis-tuned parameter — it is a structural ordering error.
Answer

Total transformation AB (the stretch matrix B sits on the right and acts first). AB e_1 = (0,2), BA e_1 = (0,1). Order is structure; error propagation and kinematic chaining are both governed by it.

Run the numbers

Where the numbers come from

Actually run at generation time:

  • The largest discrepancy between AB and BA over 500 random vectors was 2.79e+0 (about 4.5 units — not rounding error, a structural difference)
  • 100 compositions of the 3.6° rotation matrix deviate from the identity by at most 5.69e-16 (machine precision — closure verified empirically)
  • Contrast: if every composition «resets to the standard rotation and adds the angle», the drift is 0 — the bookkeeping scheme affects numerical lifespan

Where this shows up

The object hereThe counterpart in RLUsed in
Serial kinematicsTip pose = the product of the transformation matrices of every stageused in →
Error propagationCalibration errors propagate along the matrix chain; the order cannot be swappedused in →
Homogeneous coordinatesTranslation is not a linear transformation — how do you stuff it into a matrix? T12used in →

Boundaries: where this article stops

Where this page stops: compositions of 3-D rotations (Euler-angle ambiguity, gimbal lock) do not appear in 2×2 — they go to /k/ and to the quaternion page; matrix exponentials and Lie groups are also skipped. This page's boundary is 2×2 — but every conclusion holds verbatim in any dimension.

Self-test: 4 questions

All hand-computation and «find the flaw in this proof» questions — nothing to memorize. Stuck? Go back to the section.

01Does matrix multiplication commute? When does it?

Not in general (Theorem 2.3's counterexample). It does when: both are diagonal, or they are polynomial functions of one another (e.g. R(α)R(β)=R(β)R(α)=R(α+β) — rotations about the same axis always commute).

02What real-world fact does (AB)C = A(BC) correspond to in robotics?

Multi-stage coordinate-transform chains may be parenthesized freely: accumulate from tip to base or the reverse, and the result agrees. That is associativity, not a numerical coincidence.

03Why do «stretch then rotate» and «rotate then stretch» differ?

Stretching depends on direction (anisotropy); rotation changes direction. A stretch matrix is defined in one coordinate frame and acts only in that frame — get the order wrong and you apply it in the wrong frame.

04Why does composing a rotation matrix 100 times in small steps drift only 10-15?

Rotation matrices form a closed group: the product is still a rotation matrix, and orthogonality keeps each multiplication from amplifying numerical error. By contrast, composing Euler-angle triples amplifies error near singular configurations.

Up next

The full series · 27 articles

T1The Matrix Is a Ledger for Rotation≈ 25 minT2From Slope to Gradient: The First Line of Every Robot Learning Algorithm≈ 25 minT3Vectors and forces: the physical reading of the dot productAbout 20 minT4Two Rulers and a Better Rulerabout 25 minT5The Ledger of One Motor Revolution: Radians, Speed, and Powerabout 20 minT6Complex multiplication is rotation: the one-dimensional version of quaternionsAbout 20 minT7Bases and coordinates: why robots put everything in matrices45 minT8Matrix Multiplication: Chaining Transformations, Not a Table OperationAbout 40 minT9The Jacobian: Rotate a Joint One Degree — How Far Does the End Effector Move?About 45 minT10Eigenvectors: The Directions a Matrix Dare Not Touchabout 45 minT11SVD and the Pseudoinverse: When There Is No Exact Solution, Find the Nearest Oneabout 50 minT12Taylor expansion: putting a straight line to work in place of a curveAbout 40 minT13Probability spaces: why «random» needs axioms50 minT14Expectation: A Rigorous Construction of «Average»About 55 minT15Conditional Expectation: What the Vertical Bar Really Means≈ 60 minT16Four inequalities: the quantitative answer to «how many samples are enough»45 minT17Norms and fixed points: where «it always converges» comes from55 minT18Markov Chains: When the Time Average Equals the Ensemble Averageabout 55 minT19The Mathematical Construction of the MDP: What One Axiom Is Worthabout 50 minT20Dynamic Programming: The Accounting for Two Iterations≈ 50 minT21Optimization: why constraints cannot rely on penalties aloneAbout 55 minT22Stochastic Approximation: Every Term in the Learning-Rate Formulaabout 55 minT23The Mathematics of Contact: Hertz Theoryabout 45 minT24Friction and the Friction Cone: The Geometry of Constraintsabout 40 minT25Force Closure and Grasp Metrics: ε Is a Linear ProgramAbout 50 minT26Contact Kinematics: Why Rolling Is Not «Sliding Along»≈ 45 minT27Slip detection: from «I felt it» to «I computed it»About 50 min