Curso de Álgebra Lineal: Fundamentos y Aplicaciones

How Matrix Multiplication Chains Transformations

Curso de Álgebra Lineal: Fundamentos y Aplicaciones

Contenido del curso

Sistemas de Ecuaciones Lineales

How Matrix Multiplication Chains Transformations

Resumen

Matrix multiplication is the operation that lets you apply two or more linear transformations in sequence, like rotating a space first and then scaling it. It matters for anyone studying linear algebra, computer graphics, or machine learning, because it's the math behind composing transformations on vectors.

What does it mean to multiply two matrices?

Think of a matrix as instructions for where the basis vectors i hat and j hat land after a transformation. When you multiply matrix A by matrix B, you're not doing element by element math. You're stacking transformations: B acts on the space first, then A acts on the result.

That order is the part most people miss at first. You read the composition from right to left. If you write A·B, B happens first and A happens second. The columns of B tell you where i hat and j hat go, and then A transforms those new vectors again.

What does composing transformations mean? It means applying one matrix B to the space, and then applying another matrix A on top of the already transformed space. The product A·B captures both steps in a single matrix.

When is matrix multiplication possible?

Before you multiply, check the dimensions. The number of columns of the first matrix must equal the number of rows of the second matrix. If those inner dimensions don't match, the operation is impossible.

The resulting matrix takes the outer dimensions. So if A is M by K and B is K by N, then A·B is M by N. This is the first check you should always run.

How do I know if I can multiply A by B? Count the columns of A and the rows of B. If they're equal, you can multiply. The result will have the rows of A and the columns of B.

How do you calculate A times B step by step?

Let's work through a concrete example. Take A as a shear matrix with columns (1, 0) and (1, 1), and B as a rotation matrix with columns (0, 1) and (-1, 0) that rotates the space 90 degrees to the left. You want to find C = A·B, which means rotating first and shearing second.

The trick is to treat B as two column vectors and apply the matrix vector product you already know, one column at a time.

  • First column: A times B's i hat, which is (0, 1). Using linear combinations: 0·(1, 0) + 1·(1, 1) = (1, 1).
  • Second column: A times B's j hat, which is (-1, 0). That gives -1·(1, 0) + 0·(1, 1) = (-1, 0).
  • Final result: C has columns (1, 1) and (-1, 0).

That matrix C is the single transformation equivalent to rotating and then shearing. If you animate it, you'll see i hat and j hat first rotate, then stretch to the right, and land exactly on the columns of C.

Why is matrix multiplication not commutative?

Here's where intuition saves you. A·B is not the same as B·A. If B is a rotation and A is a scaling, doing rotation first and scaling second produces a different final space than scaling first and rotating second. The order of the transformations changes the outcome.

This is why you always read compositions from right to left, and why you should never assume you can swap the order of two matrices.

What other properties should you remember?

Beyond non commutativity, two more rules make your life easier when chaining operations.

  • It is associative: (A·B)·C is the same as A·(B·C). You can group the multiplications however helps you compute.
  • It is distributive over addition and subtraction: A·(B ± C) equals A·B ± A·C.

These properties let you simplify long chains of transformations without changing the result, as long as you keep the left to right order intact.

Practice exercise to lock in the concept

Try this on your own. Take A = shear matrix with columns (1, 0) and (1, 1), and B = scaling matrix with columns (2, 0) and (0, 2).

  • Calculate C = A·B.
  • Calculate D = B·A.
  • Compare both results and confirm with your own eyes that A·B ≠ B·A.

If you want to go further, graph the transformations and see how i hat and j hat end up in different places depending on the order. Share your results in the comments and tell me which order surprised you the most.