Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Matrix Composition


Linear Algebra·Matrix compositionTwo matrices stacked. A applied to (B applied to v) equals the single matrix AB applied to v. That's why matrix multiplication is defined the way it is.
A(Bv)=(AB)v
order
view
AvBAvv₀BvABvv
v\u2080=(1.5, 1)start
Bv=(2, 1)after B
ABv=(0.71, 2.12)after AB
Composition I → B → ABt = 0.000phase 1 · applying B
apply Bapply A
M = B
t = 0.000

Shear, then rotate

non-commutative

First B shears horizontally, then A rotates 45°. The reverse order produces a different shape.
Learn more about non-commuting pairs · when matrices commute

Insight

Shears and rotations deform the plane in incompatible ways. AB and BA differ both in the final position of every vector and in the matrix entries.

AMatricesclick to edit

A=
B=
auto-computed
AB=
0.71-0.350.711.06

04LiveAB vs BA

matrices side by side
AB
0.71-0.350.711.06
BA
1.06-0.350.710.71
endpoint comparison
ABv(0.71, 2.12)BAv(1.24, 1.77)|ABv − BAv|0.64
A and B do NOT commute








Key Terms

Composition — applying one transformation after another. Applying BB and then AA sends v\mathbf{v} to A(Bv)A(B\mathbf{v}).

Matrix product — the single matrix ABAB with (AB)v=A(Bv)(AB)\mathbf{v} = A(B\mathbf{v}) for every v\mathbf{v}. Matrix multiplication is defined so that this works.

Order of application — in ABvAB\mathbf{v} the matrix nearest v\mathbf{v} acts first: BB, then AA. Products read right to left.

Non-commutativity — ABBAAB \neq BA in general; the two orders are different transformations with different matrices.

Commuting pair — matrices with AB=BAAB = BA, such as two rotations, two diagonal matrices, or anything paired with a multiple of the identity.

Trail — the two-segment path v0BvABv\mathbf{v}_0 \to B\mathbf{v} \to AB\mathbf{v} that a vector follows through the pipeline.

Stages — the same pipeline shown as three canvases: the input, the intermediate, and the final state.

Determinant of a product — det(AB)=detAdetB\det(AB) = \det A \cdot \det B, the same in either order even when the matrices differ.

Getting Started

The tool shows a vector v\mathbf{v} travelling through two matrices. In Trail view a single canvas draws the path v0BvABv\mathbf{v}_0 \to B\mathbf{v} \to AB\mathbf{v} in two colours, teal for the first matrix and purple for the second, with the alternative order BABA drawn dashed for comparison. In Stages view the same pipeline is laid out as three canvases with chevrons between them.

Try this sequence to build intuition:

• Start on the Shear × rotate preset and press play. In the first half of the animation the grid shears and v\mathbf{v} slides to BvB\mathbf{v}; in the second half the sheared plane rotates and v\mathbf{v} arrives at ABvAB\mathbf{v}.
• Flip the AB / BA toggle in the top bar. The same two matrices, applied in the other order, land v\mathbf{v} somewhere else, and the dashed path shows where the first order went.
• Switch to Two rotations and flip the toggle again. Now both orders land in the same place: rotations commute.
• Drag v\mathbf{v} in either view. The trail and both endpoints follow it.

The point: matrix multiplication is composition of transformations, and composition depends on order.

Trail and Stages Views

The top bar switches between two layouts of the same state.

• Trail — one canvas. The grid and unit square carry the partially applied product as the animation runs, and the vector's path is drawn as a breadcrumb trail with ghost markers at v0\mathbf{v}_0, the intermediate point, and the final point. The other order's path is drawn dashed behind it
• Stages — three canvases in a row: the input plane with v\mathbf{v}, the plane after the first matrix with its unit square tinted in that matrix's colour, and the plane after both with the final square in indigo. Chevrons between them name the matrix applied at each step

Switching views changes nothing about the matrices, the vector, the mode or the animation position. Trail is better for seeing where a vector goes; Stages is better for seeing what happens to the whole plane at each step.

The Two-Phase Animation

The animation parameter tt runs from 00 to 11 in two halves.

• For tt from 00 to 0.50.5, the first matrix is blended in from the identity: the grid morphs from square to its image under BB (in ABAB mode), and v\mathbf{v} slides in a straight line from v0\mathbf{v}_0 to BvB\mathbf{v}
• For tt from 0.50.5 to 11, the second matrix is blended in on top of the completed first: the grid morphs from BB to ABAB, and v\mathbf{v} slides from BvB\mathbf{v} to ABvAB\mathbf{v}
• The progress bar is split at the midpoint and coloured to match; the transport buttons step, scrub and reset

Because each phase blends one matrix linearly, the vector's path within a phase is a straight segment, which is why the trail is a two-segment polyline with a bend at the intermediate point. Selecting a preset or flipping the order restarts the animation from t=0t = 0 and plays it.

Preset Scenarios

The sidebar offers nine pairs in three groups.

• Commutative — two rotations, two diagonal scales, and a uniform scale with a rotation; in each case AB=BAAB = BA and the dashed path lands exactly on the solid one
• Non-commutative — shear with rotation, two perpendicular shears, projection with rotation, and reflection with rotation; the two orders diverge, sometimes drastically
• Reveals — two reflections that compose to a rotation, and a shear with its inverse that composes to the identity

The four sections that follow freeze one representative of each situation, with the numbers the tool computes for the default vector. The explanation card in the tool links back to the matching section for whichever preset is active.

A Commuting Pair: Two Rotations

On the two-rotations preset AA rotates by 60°60° and BB by 30°30°. Applying BB then AA rotates by 90°90° in total; applying AA then BB also rotates by 90°90°. The two orders agree.

The frozen picture below is the end of the ABAB run: the solid trail bends at BvB\mathbf{v} and ends at ABvAB\mathbf{v}, and the dashed BABA trail, though it bends at a different intermediate point AvA\mathbf{v}, ends at exactly the same place.
AvBAvv₀BvABvv
Two rotations, end of the AB run

The solid trail bends at Bv = (0.8, 1.62) and ends at ABv = (-1, 1.5); the dashed BA trail bends elsewhere, at Av = (-0.12, 1.8), but ends at the same point. 30° + 60° = 60° + 30°.

The intermediate points differ, BvB\mathbf{v} is v\mathbf{v} turned by 30°30° while AvA\mathbf{v} is v\mathbf{v} turned by 60°60°, but the destinations coincide because 30°+60°=60°+30°30° + 60° = 60° + 30°. Rotations of the plane form a commutative group.

Commuting is a property of the pair, not of either matrix alone. Each of these rotations fails to commute with a shear, as the non-commutative presets show.

A Non-Commuting Pair: Shear and Rotation

On the default preset BB shears horizontally by 0.50.5 and AA rotates by 45°45°. Shearing first and then rotating lands v\mathbf{v} in one place; rotating first and then shearing lands it somewhere else.

The frozen picture below is the end of the ABAB run: the solid trail goes v0BvABv\mathbf{v}_0 \to B\mathbf{v} \to AB\mathbf{v}, the dashed trail goes v0AvBAv\mathbf{v}_0 \to A\mathbf{v} \to BA\mathbf{v}, and the two endpoints are visibly apart.
AvBAvv₀BvABvv
Shear then rotate, end of the AB run

Shear first, then rotate: ABv = (0.71, 2.12). Rotate first, then shear: BAv = (1.24, 1.77). Two different destinations from the same two matrices; both products have determinant 1.

A shear stretches the plane along one direction while a rotation turns every direction, and the two deform the plane in ways that do not slide past each other. The matrices ABAB and BABA have different entries, not just different pictures.

What they share is the determinant: both are 11, since the shear and the rotation each preserve area. The unit square ends up as a parallelogram of area 11 in both orders, but a differently oriented one.

A Reveal: Two Reflections Make a Rotation

On the two-reflections preset BB reflects across the x-axis and AA reflects across y=xy = x. Neither is a rotation, but their composition is: ABAB is the rotation by 90°90°.

The frozen picture below shows v\mathbf{v} arriving at ABvAB\mathbf{v}, which is v0\mathbf{v}_0 turned a quarter turn counterclockwise, and the unit square rotated but not flipped.
AvBAvv₀BvABvv
Two reflections, end of the AB run

v0 = (1.5, 1) has arrived at ABv = (-1, 1.5), a quarter turn counterclockwise, and the unit square is rotated but not flipped: two orientation reversals cancel into a rotation by 90°.

Each reflection reverses orientation, with determinant 1-1, and two reversals cancel: det(AB)=(1)(1)=+1\det(AB) = (-1)(-1) = +1. The composition preserves lengths, angles and orientation, which is the definition of a rotation, and its angle is twice the 45°45° between the two mirrors.

The other order is the rotation by 90°-90°. So this pair does not commute either, but the two results are as closely related as non-commuting products can be: inverses of each other.

A Reveal: A Shear and Its Inverse

On the shear-and-inverse preset BB shears by 0.60.6 and AA shears by 0.6-0.6. Applying one after the other undoes the first: AB=IAB = I, and v\mathbf{v} returns to v0\mathbf{v}_0.

The frozen picture below shows the trail leaving v0\mathbf{v}_0 for BvB\mathbf{v} and coming straight back, with the final unit square sitting exactly on the original.
AvBAvv₀BvABvv
Shear and its inverse, end of the AB run

The trail leaves v0 for Bv = (2.1, 1) and comes straight back: ABv = (1.5, 1). AB = I, and the final unit square sits exactly on the original.

This is what an inverse matrix means as a transformation: the map that composes with the original to give the identity. It works in both orders here, AB=BA=IAB = BA = I, which is always true of a matrix and its inverse.

The animation makes the undoing visible. The first half shears the plane; the second half shears it back, and at t=1t = 1 the grid is square again. Nothing has been lost, because a shear has determinant 11 and is invertible. Contrast the projection presets, where the first half flattens the plane and no second matrix can ever restore it.

The Matrices Card and the Live Card

The matrices card shows AA and BB as editable 2×22 \times 2 grids, with the product for the current order computed beside them. Editing an entry clears the preset and rebuilds everything.

The live card compares the two orders directly:

• ABAB and BABA as matrices, side by side
• ABvAB\mathbf{v} and BAvBA\mathbf{v} for the current v\mathbf{v}
• A verdict, commute or do not commute, from whether the two products agree
• det(AB)\det(AB), which always equals detAdetB\det A \cdot \det B and is therefore the same for both orders

The determinant line is the reminder that some things about a product do not depend on order: area scaling and orientation are multiplicative, even though the shapes themselves differ.

Display Layer Toggles

Six chips switch the overlays on and off.

• grid — the morphing background grid
• unit sq — the unit square under the current partial product, tinted by stage
• ghosts — the markers at v0\mathbf{v}_0, the intermediate point and the endpoint, which fill in as the animation passes them
• AB path — the primary trail in the current order's colours
• BA path — the dashed alternative trail and its ghosts
• labels — the names on every marker

Turning off the grid and unit square leaves only the two trails, which is the clearest way to compare where the two orders send a single vector.

What Composition Is

If BB sends v\mathbf{v} to BvB\mathbf{v} and AA then sends that to A(Bv)A(B\mathbf{v}), the overall effect is a single linear transformation, and its matrix is the product ABAB:

A(Bv)=(AB)vfor every vA(B\mathbf{v}) = (AB)\,\mathbf{v} \quad \text{for every } \mathbf{v}


This is not a coincidence about matrices; it is the reason matrix multiplication is defined the way it is. The column jj of ABAB is AA applied to column jj of BB, which is where the row-times-column rule comes from: the entry (AB)ij=kAikBkj(AB)_{ij} = \sum_k A_{ik} B_{kj} is exactly what falls out of applying AA to the image of the jj-th basis vector under BB.

Two consequences follow immediately. Products read right to left, since the matrix nearest the vector acts first. And products need not commute, because doing two things in different orders need not give the same result: shearing a picture and then rotating it is not the same as rotating and then shearing.

For the arithmetic of the product itself, see the matrix multiplication visualizer; for transformations as matrices in general, see the matrix representation theory page.

When Matrices Commute

Most pairs of matrices do not commute, but several important families do.

• Rotations of the plane — composing rotations adds their angles, and addition is commutative: R(α)R(β)=R(α+β)=R(β)R(α)R(\alpha)R(\beta) = R(\alpha + \beta) = R(\beta)R(\alpha)
• Diagonal matrices — they scale the axes independently, so the order of two independent scalings does not matter
• Multiples of the identity — kIkI commutes with every matrix, since kIM=kM=MkIkI \cdot M = kM = M \cdot kI
• Powers of one matrix — MaM^a and MbM^b always commute
• Simultaneously diagonalizable matrices — matrices that share a full set of eigenvectors commute, and this is the general criterion

The test in the tool is direct: compute ABAB and BABA and compare. When they agree, the dashed alternative path lands on the solid one and the live card says so. Note that det(AB)=det(BA)\det(AB) = \det(BA) always, so the determinant cannot tell the two orders apart; only the matrices themselves can.

Key Properties

Composition obeys a few rules that hold regardless of order.

• Associativity: (AB)C=A(BC)(AB)C = A(BC); three transformations in sequence compose the same way however the pairs are grouped
• Identity: AI=IA=AAI = IA = A; the identity matrix is the do-nothing transformation
• Inverse: AA1=A1A=IAA^{-1} = A^{-1}A = I; a transformation followed by its undoing is the identity, in either order
• Determinant: det(AB)=detAdetB\det(AB) = \det A \cdot \det B
• Inverse of a product: (AB)1=B1A1(AB)^{-1} = B^{-1}A^{-1}; to undo BB-then-AA, undo AA first, then BB
• Transpose of a product: (AB)T=BTAT(AB)^T = B^T A^T
• Rank: rank(AB)min(rankA,rankB)\operatorname{rank}(AB) \leq \min(\operatorname{rank} A, \operatorname{rank} B); composing with a rank-11 projection can never restore a lost dimension
• Not commutative: ABBAAB \neq BA in general, and AB=BAAB = BA is a special property of the pair