Composition of Linear Transformations
The composition of linear transformations S ∘ T applies T first and then S, so (S ∘ T)(x) = S(T(x)). If T has standard matrix A and S has standard matrix B, then S ∘ T is also linear and its standard matrix is the product BA. The matrix of the transformation applied first goes on the right.
Before this lesson: Standard Matrix of a Linear Transformation and Matrix Multiplication
What composing two transformations means
Let T: ℝⁿ → ℝᵐ and S: ℝᵐ → ℝᵖ be linear. The composition S ∘ T: ℝⁿ → ℝᵖ sends x to S(T(x)): first T moves x into ℝᵐ, then S moves T(x) into ℝᵖ. It only makes sense when the outputs of T are valid inputs for S, so the middle space ℝᵐ must match.
You saw the same idea with functions in composition of functions and with rigid motions in compositions of transformations. Here the maps are matrices, so the composition is a matrix too.
Composition of linear transformations formula
Write T(x) = Ax with A of size m × n, and S(y) = By with B of size p × m. Then S(T(x)) = B(Ax) = (BA)x, because matrix multiplication is associative.
(S \circ T)(\mathbf{x}) = S(T(\mathbf{x})) = B(A\mathbf{x}) = (BA)\mathbf{x}So the standard matrix of S ∘ T is BA, a p × m matrix times an m × n matrix, which gives a p × n matrix. Read the product right to left: A acts first, then B.
- The order matters. T ∘ S (S first, then T) has matrix AB, and AB is usually not equal to BA.
- T ∘ S is defined only when the outputs of S fit the inputs of T. If the sizes do not match, that composition does not exist.
- A composition of linear transformations is always linear, so it always has a standard matrix.
How to find the matrix of a composition
- Write the standard matrix of each transformation: A for T and B for S.
- Check the sizes: the number of columns of B must equal the number of rows of A.
- Multiply in the order “last applied on the left”: the matrix of S ∘ T is BA.
- Check with one vector: compute S(T(x)) in two steps and compare it with (BA)x.
Composition of linear transformations examples
Example 1: A shear followed by a scaling
T(x₁, x₂) = (x₁ + 2x₂, x₂) is a horizontal shear, and S(y₁, y₂) = (2y₁, 3y₂) stretches by 2 horizontally and 3 vertically. Find the standard matrix of S ∘ T and check it with x = (1, 1).
A = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix},\; B = \begin{bmatrix} 2 & 0 \\ 0 & 3 \end{bmatrix}Write the matrix of T and the matrix of S.
BA = \begin{bmatrix} 2(1) + 0(0) & 2(2) + 0(1) \\ 0(1) + 3(0) & 0(2) + 3(1) \end{bmatrix}S ∘ T has matrix BA. Multiply each row of B by each column of A.
= \begin{bmatrix} 2 & 4 \\ 0 & 3 \end{bmatrix}Multiply and add in each entry.
T(1, 1) = (1 + 2(1),\; 1) = (3, 1)
Check: apply T first.
S(3, 1) = (2(3),\; 3(1)) = (6, 3)
Then apply S.
\begin{bmatrix} 2 & 4 \\ 0 & 3 \end{bmatrix}\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 + 4 \\ 0 + 3 \end{bmatrix} = \begin{bmatrix} 6 \\ 3 \end{bmatrix}BA gives the same output in one step.
Answer: the standard matrix of S ∘ T is [2 4; 0 3] (rows separated by a semicolon).
Example 2: The other order
With the same T and S as Example 1, find the standard matrix of T ∘ S (scale first, then shear). Is it the same as the matrix of S ∘ T?
AB = \begin{bmatrix} 1(2) + 2(0) & 1(0) + 2(3) \\ 0(2) + 1(0) & 0(0) + 1(3) \end{bmatrix}T ∘ S applies S first, so its matrix is AB.
= \begin{bmatrix} 2 & 6 \\ 0 & 3 \end{bmatrix}Multiply and add in each entry.
\begin{bmatrix} 2 & 6 \\ 0 & 3 \end{bmatrix} \ne \begin{bmatrix} 2 & 4 \\ 0 & 3 \end{bmatrix}Compare with BA from Example 1: the top-right entries differ.
Answer: T ∘ S has matrix [2 6; 0 3], so T ∘ S ≠ S ∘ T. For example, (T ∘ S)(1, 1) = (8, 3), but (S ∘ T)(1, 1) = (6, 3).
Example 3: A rotation followed by a reflection
R rotates the plane 90° counterclockwise, and F reflects across the x-axis. Find the standard matrix of F ∘ R and describe it as a single transformation.
R = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}R(e₁) = (0, 1) and R(e₂) = (−1, 0) are its columns.
F = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}F(e₁) = (1, 0) and F(e₂) = (0, −1) are its columns.
FR = \begin{bmatrix} 1(0) + 0(1) & 1(-1) + 0(0) \\ 0(0) + (-1)(1) & 0(-1) + (-1)(0) \end{bmatrix}F ∘ R applies R first, so its matrix is FR.
= \begin{bmatrix} 0 & -1 \\ -1 & 0 \end{bmatrix}Multiply and add in each entry.
(x_1, x_2) \mapsto (-x_2, -x_1)
Read the formula from the rows of FR.
Answer: F ∘ R has matrix [0 −1; −1 0]. It sends (x₁, x₂) to (−x₂, −x₁), which is the reflection across the line y = −x.
Example 4: Transformations between different spaces
T: ℝ³ → ℝ² has matrix A = [1 0 2; −1 3 1], and S: ℝ² → ℝ³ has matrix B = [1 1; 2 0; 0 −1]. Find the standard matrices of S ∘ T and T ∘ S, and give the domain and codomain of each.
BA = \begin{bmatrix} 1(1) + 1(-1) & 1(0) + 1(3) & 1(2) + 1(1) \\ 2(1) + 0(-1) & 2(0) + 0(3) & 2(2) + 0(1) \\ 0(1) + (-1)(-1) & 0(0) + (-1)(3) & 0(2) + (-1)(1) \end{bmatrix}S ∘ T: B is 3 × 2 and A is 2 × 3, so BA is 3 × 3.
= \begin{bmatrix} 0 & 3 & 3 \\ 2 & 0 & 4 \\ 1 & -3 & -1 \end{bmatrix}Multiply and add in each entry.
AB = \begin{bmatrix} 1(1) + 0(2) + 2(0) & 1(1) + 0(0) + 2(-1) \\ -1(1) + 3(2) + 1(0) & -1(1) + 3(0) + 1(-1) \end{bmatrix}T ∘ S: A is 2 × 3 and B is 3 × 2, so AB is 2 × 2.
= \begin{bmatrix} 1 & -1 \\ 5 & -2 \end{bmatrix}Multiply and add in each entry.
Answer: S ∘ T: ℝ³ → ℝ³ has the 3 × 3 matrix BA = [0 3 3; 2 0 4; 1 −3 −1]. T ∘ S: ℝ² → ℝ² has the 2 × 2 matrix AB = [1 −1; 5 −2]. The two compositions do not even have the same size.
Example 5: Cost and weight of a bakery order
A bakery makes bread and cakes. A loaf of bread uses 500 g of flour, 20 g of sugar and no eggs. A cake uses 300 g of flour, 250 g of sugar and 4 eggs. Flour costs $0.002 per gram, sugar $0.003 per gram and eggs $0.25 each; an egg weighs 50 g. T sends an order (loaves, cakes) to the ingredients (flour, sugar, eggs), and S sends ingredients to (cost in dollars, weight in grams). Find the matrix of S ∘ T and use it for an order of 10 loaves and 4 cakes.
A = \begin{bmatrix} 500 & 300 \\ 20 & 250 \\ 0 & 4 \end{bmatrix}T: one column per product, one row per ingredient.
B = \begin{bmatrix} 0.002 & 0.003 & 0.25 \\ 1 & 1 & 50 \end{bmatrix}S: row 1 is cost per unit, row 2 is grams per unit.
BA = \begin{bmatrix} 0.002(500) + 0.003(20) + 0.25(0) & 0.002(300) + 0.003(250) + 0.25(4) \\ 1(500) + 1(20) + 50(0) & 1(300) + 1(250) + 50(4) \end{bmatrix}S ∘ T has matrix BA (2 × 3 times 3 × 2).
= \begin{bmatrix} 1 + 0.06 + 0 & 0.6 + 0.75 + 1 \\ 500 + 20 + 0 & 300 + 250 + 200 \end{bmatrix}Multiply each pair.
= \begin{bmatrix} 1.06 & 2.35 \\ 520 & 750 \end{bmatrix}Add. Column 1: one loaf costs $1.06 and weighs 520 g; column 2: one cake costs $2.35 and weighs 750 g.
\begin{bmatrix} 1.06 & 2.35 \\ 520 & 750 \end{bmatrix}\begin{bmatrix} 10 \\ 4 \end{bmatrix} = \begin{bmatrix} 10.6 + 9.4 \\ 5200 + 3000 \end{bmatrix}Apply BA to the order (10, 4).
= \begin{bmatrix} 20 \\ 8200 \end{bmatrix}Add.
Answer: the matrix of S ∘ T is [1.06 2.35; 520 750]. The order of 10 loaves and 4 cakes uses $20.00 of ingredients that weigh 8,200 g (8.2 kg).
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Multiplying in the order the maps are applied | Using AB for S ∘ T in Example 1 and getting [2 6; 0 3] | The map applied first goes on the right: S ∘ T has matrix BA. |
| Assuming S ∘ T = T ∘ S | Using the same matrix for “shear then scale” and “scale then shear” | Compute both products; they are usually different. |
| Ignoring the sizes | Trying to form T ∘ S when S: ℝ² → ℝ³ and T: ℝ⁴ → ℝ² | The outputs of the first map must be inputs of the second: columns of the left matrix = rows of the right matrix. |
| Adding the matrices | Writing A + B for “do T, then do S” | Composition is a product, not a sum. A + B is the matrix of x ↦ T(x) + S(x). |
| Getting a domain or codomain wrong | Calling S ∘ T in Example 4 a map from ℝ² to ℝ² | S ∘ T starts where T starts (ℝ³) and ends where S ends (ℝ³). |
Related ideas
Undoing a transformation. If S ∘ T is the identity map, its matrix BA is the identity matrix I, so S undoes T and B = A⁻¹ (see inverse matrices). This happens exactly when T is one-to-one and onto, as in one-to-one and onto transformations.
Repeating a transformation. Applying T twice is T ∘ T, with matrix A². Rotating twice by 90° gives a 180° rotation, so the rotation matrix squared is −I. Powers of a matrix return in Diagonalization (coming soon).
Practice problems
- T has matrix A = [2 1; 0 1] and S has matrix B = [1 0; 1 1]. Find the standard matrix of S ∘ T.
- With the same A and B, find the standard matrix of T ∘ S.
- T(x₁, x₂) = (x₁ + x₂, x₂) and S(y₁, y₂) = (2y₁, y₁ − y₂). Find the matrix of S ∘ T and check it at x = (3, −1).
- R rotates the plane 90° counterclockwise. Find the standard matrix of R ∘ R and describe it.
- T: ℝ⁴ → ℝ² and S: ℝ² → ℝ³. Which of S ∘ T and T ∘ S is defined? What size is its standard matrix?
- T has matrix A = [1 2 0; 0 1 −1] and S has matrix B = [1 −1; 2 0]. Find the standard matrix of S ∘ T.
- R rotates 90° counterclockwise and P projects onto the x-axis, with matrix [1 0; 0 0]. Find the matrix of P ∘ R and (P ∘ R)(2, 5).
- A = [1 1; 0 1] and B = [1 0; 1 1]. Show that the matrices of S ∘ T and T ∘ S are different.
- T has matrix A = [2 1; 1 1] and S has matrix B = [1 −1; −1 2]. Find the matrix of S ∘ T. What does S do to T?
- A workshop makes chairs and tables. A chair uses 4 boards and 20 screws; a table uses 6 boards and 40 screws. A board costs $5 and weighs 3 kg; a screw costs $0.10 and weighs 0.01 kg. Find the matrix that sends (chairs, tables) to (cost, weight), then the cost and weight of the materials for 5 chairs and 2 tables.
Show answers
1.
BA = \begin{bmatrix} 1(2) + 0(0) & 1(1) + 0(1) \\ 1(2) + 1(0) & 1(1) + 1(1) \end{bmatrix}S ∘ T has matrix BA.
= \begin{bmatrix} 2 & 1 \\ 2 & 2 \end{bmatrix}Multiply and add.
Answer: [2 1; 2 2].
2.
AB = \begin{bmatrix} 2(1) + 1(1) & 2(0) + 1(1) \\ 0(1) + 1(1) & 0(0) + 1(1) \end{bmatrix}T ∘ S has matrix AB.
= \begin{bmatrix} 3 & 1 \\ 1 & 1 \end{bmatrix}Multiply and add.
Answer: [3 1; 1 1], which is different from the answer to Problem 1.
3.
A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix},\; B = \begin{bmatrix} 2 & 0 \\ 1 & -1 \end{bmatrix}Matrices of T and S.
BA = \begin{bmatrix} 2(1) + 0(0) & 2(1) + 0(1) \\ 1(1) + (-1)(0) & 1(1) + (-1)(1) \end{bmatrix}S ∘ T has matrix BA.
= \begin{bmatrix} 2 & 2 \\ 1 & 0 \end{bmatrix}Multiply and add.
T(3, -1) = (3 - 1,\; -1) = (2, -1)
Check: apply T.
S(2, -1) = (2(2),\; 2 - (-1)) = (4, 3)
Then apply S.
\begin{bmatrix} 2 & 2 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 3 \\ -1 \end{bmatrix} = \begin{bmatrix} 6 - 2 \\ 3 + 0 \end{bmatrix} = \begin{bmatrix} 4 \\ 3 \end{bmatrix}BA gives the same output.
Answer: [2 2; 1 0].
4.
R^2 = \begin{bmatrix} 0(0) + (-1)(1) & 0(-1) + (-1)(0) \\ 1(0) + 0(1) & 1(-1) + 0(0) \end{bmatrix}R ∘ R has matrix R·R, with R = [0 −1; 1 0].
= \begin{bmatrix} -1 & 0 \\ 0 & -1 \end{bmatrix}Multiply and add.
Answer: R ∘ R has matrix −I and sends (x₁, x₂) to (−x₁, −x₂): a 180° rotation.
5.
Answer: S ∘ T is defined, because T’s outputs are in ℝ², which is S’s domain. Its matrix is 3 × 4 (a 3 × 2 matrix times a 2 × 4 matrix). T ∘ S is not defined: S’s outputs are in ℝ³, but T needs inputs in ℝ⁴.
6.
BA = \begin{bmatrix} 1(1) + (-1)(0) & 1(2) + (-1)(1) & 1(0) + (-1)(-1) \\ 2(1) + 0(0) & 2(2) + 0(1) & 2(0) + 0(-1) \end{bmatrix}S ∘ T has matrix BA (2 × 2 times 2 × 3).
= \begin{bmatrix} 1 & 1 & 1 \\ 2 & 4 & 0 \end{bmatrix}Multiply and add.
Answer: [1 1 1; 2 4 0], a 2 × 3 matrix.
7.
PR = \begin{bmatrix} 1(0) + 0(1) & 1(-1) + 0(0) \\ 0(0) + 0(1) & 0(-1) + 0(0) \end{bmatrix}P ∘ R applies R first, so its matrix is PR.
= \begin{bmatrix} 0 & -1 \\ 0 & 0 \end{bmatrix}Multiply and add.
\begin{bmatrix} 0 & -1 \\ 0 & 0 \end{bmatrix}\begin{bmatrix} 2 \\ 5 \end{bmatrix} = \begin{bmatrix} 0 - 5 \\ 0 + 0 \end{bmatrix} = \begin{bmatrix} -5 \\ 0 \end{bmatrix}Apply PR to (2, 5).
Answer: PR = [0 −1; 0 0] and (P ∘ R)(2, 5) = (−5, 0). Check: R(2, 5) = (−5, 2), and projecting gives (−5, 0).
8.
BA = \begin{bmatrix} 1(1) + 0(0) & 1(1) + 0(1) \\ 1(1) + 1(0) & 1(1) + 1(1) \end{bmatrix} = \begin{bmatrix} 1 & 1 \\ 1 & 2 \end{bmatrix}Matrix of S ∘ T.
AB = \begin{bmatrix} 1(1) + 1(1) & 1(0) + 1(1) \\ 0(1) + 1(1) & 0(0) + 1(1) \end{bmatrix} = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}Matrix of T ∘ S.
Answer: BA = [1 1; 1 2] and AB = [2 1; 1 1] differ in the top-left and bottom-right entries, so S ∘ T ≠ T ∘ S.
9.
BA = \begin{bmatrix} 1(2) + (-1)(1) & 1(1) + (-1)(1) \\ -1(2) + 2(1) & -1(1) + 2(1) \end{bmatrix}S ∘ T has matrix BA.
= \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}Multiply and add.
Answer: BA = I, so S(T(x)) = x for every x. S undoes T, and B is the inverse of A.
10.
A = \begin{bmatrix} 4 & 6 \\ 20 & 40 \end{bmatrix},\; B = \begin{bmatrix} 5 & 0.1 \\ 3 & 0.01 \end{bmatrix}T: (chairs, tables) → (boards, screws); S: (boards, screws) → (cost, weight).
BA = \begin{bmatrix} 5(4) + 0.1(20) & 5(6) + 0.1(40) \\ 3(4) + 0.01(20) & 3(6) + 0.01(40) \end{bmatrix}S ∘ T has matrix BA.
= \begin{bmatrix} 22 & 34 \\ 12.2 & 18.4 \end{bmatrix}Multiply and add: 20 + 2, 30 + 4, 12 + 0.2 and 18 + 0.4.
\begin{bmatrix} 22 & 34 \\ 12.2 & 18.4 \end{bmatrix}\begin{bmatrix} 5 \\ 2 \end{bmatrix} = \begin{bmatrix} 110 + 68 \\ 61 + 36.8 \end{bmatrix} = \begin{bmatrix} 178 \\ 97.8 \end{bmatrix}Apply BA to the order (5, 2).
Answer: the matrix is [22 34; 12.2 18.4]; the materials cost $178 and weigh 97.8 kg.
Composition of linear transformations FAQ
What is the matrix of a composition of linear transformations?
If T has matrix A and S has matrix B, then S ∘ T has matrix BA. The matrix of the map applied first is on the right.
Is the composition of linear transformations linear?
Yes. S(T(cx + dy)) = S(cT(x) + dT(y)) = cS(T(x)) + dS(T(y)), so S ∘ T keeps linear combinations.
Does the order of composition matter?
Usually, yes. S ∘ T has matrix BA and T ∘ S has matrix AB, and matrix multiplication is not commutative, so the two maps are usually different.
Why is the matrix BA and not AB?
Because S(T(x)) = B(Ax). A must act on x first, so it sits next to x, and B is applied to the result.
Summary
- (S ∘ T)(x) = S(T(x)): apply T first, then S.
- If T(x) = Ax and S(y) = By, then S ∘ T has standard matrix BA.
- S ∘ T needs the outputs of T to be inputs of S; BA is p × n when B is p × m and A is m × n.
- S ∘ T and T ∘ S are usually different, because AB ≠ BA in general.
- Check the matrix by computing S(T(x)) for one vector in two steps.
Previous lesson: One-to-One and Onto Transformations
Next lesson: Transpose of a Matrix
Back to the Linear Algebra Index