Linear Algebra · Undergraduate

Matrix Multiplication and Ax as a Combination of Columns

Quick answer

The product Ax is the linear combination of the columns of A whose coefficients are the entries of x, which is why a linear system and a matrix equation say the same thing. Multiplying two matrices applies this column by column: AB has the same columns as B, each replaced by A times it. The sizes must match, an m × n matrix times an n × p matrix giving m × p, and the product means doing B first and then A. Matrix multiplication is associative but not commutative.

What you'll learn

  • Compute Ax as a linear combination of columns
  • Multiply matrices of compatible sizes
  • Explain the product as a composition of transformations
  • Use the identity matrix and the rules that do and do not hold

A matrix times a vector

Write a matrix as a row of columns. Then AxA\mathbf{x} is defined to be the linear combination of those columns whose coefficients are the entries of x\mathbf{x}:

Ax=[a1a2⋯an][x1x2⋮xn]=x1a1+x2a2+⋯+xnanA\mathbf{x} = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \cdots & \mathbf{a}_n \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_n

For this to make sense, x\mathbf{x} must have one entry per column of AA. With

A=[120123]x=[23]A = \begin{bmatrix} 1 & 2\\ 0 & 1\\ 2 & 3 \end{bmatrix} \qquad \mathbf{x} = \begin{bmatrix} 2 \\ 3 \end{bmatrix}

the product is 2(1,0,2)+3(2,1,3)=(8,3,13)2(1, 0, 2) + 3(2, 1, 3) = (8, 3, 13). Computing entry by entry, each component is a dot product of a row of AA with x\mathbf{x}: 1(2)+2(3)=81(2) + 2(3) = 8, then 0(2)+1(3)=30(2) + 1(3) = 3, then 2(2)+3(3)=132(2) + 3(3) = 13. The two recipes always agree.

This is why the two halves of the course fit together:

Ax=b⟺x1a1+⋯+xnan=bA\mathbf{x} = \mathbf{b} \quad\Longleftrightarrow\quad x_1\mathbf{a}_1 + \cdots + x_n\mathbf{a}_n = \mathbf{b}

So Ax=bA\mathbf{x} = \mathbf{b} has a solution exactly when b\mathbf{b} lies in Span{a1,…,an}\text{Span}\{\mathbf{a}_1, \ldots, \mathbf{a}_n\}. A system of equations, a combination of columns, and a matrix equation are three ways of writing one problem.

Multiplying two matrices

Since AA acts on vectors, it acts on each column of a second matrix. That is the definition of the product:

AB=A[b1⋯bp]=[Ab1⋯Abp]AB = A\begin{bmatrix} \mathbf{b}_1 & \cdots & \mathbf{b}_p \end{bmatrix} = \begin{bmatrix} A\mathbf{b}_1 & \cdots & A\mathbf{b}_p \end{bmatrix}

The sizes have to line up: AA must have as many columns as BB has rows. An m×nm \times n matrix times an n×pn \times p matrix is m×pm \times p. Entry by entry, the number in row ii, column jj of ABAB is the dot product of row ii of AA with column jj of BB.

Why the product is a composition

Applying BB to a vector and then AA to the result is doing two transformations in a row. Because A(Bx)A(B\mathbf{x}) is a linear combination of the columns of AA with the entries of BxB\mathbf{x} as coefficients, unwinding the definitions gives A(Bx)=(AB)xA(B\mathbf{x}) = (AB)\mathbf{x} for every x\mathbf{x}. The product ABAB is the single matrix that does BB first and then AA, and the order of the letters matches the order of application, right to left.

Two rules follow. Composition of functions is associative, so (AB)C=A(BC)(AB)C = A(BC). And composition is not commutative: turning then stretching differs from stretching then turning, so AB≠BAAB \ne BA in general.

The columns of a matrix have a meaning in this language. Since ej\mathbf{e}_j picks out the jjth column, Aej=ajA\mathbf{e}_j = \mathbf{a}_j: the columns are the images of the standard basis vectors. That is enough to pin down the whole transformation.

The unit square under the matrix [[2, 1], [0, 1]] A unit square with corners (0, 0), (1, 0), (1, 1) and (0, 1), and its image, a dashed parallelogram with corners (0, 0), (2, 0), (3, 1) and (1, 1). The first column of the matrix, (2, 0), is the image of e₁, and the second column, (1, 1), is the image of e₂. unit square image 12312xy (2, 0) (1, 1)
The unit square under the matrix [[2, 1], [0, 1]]

Worked examples

Common mistakes

Practice problems

  1. Compute [1234][56]\begin{bmatrix} 1 & 2\\ 3 & 4\end{bmatrix}\begin{bmatrix} 5 \\ 6\end{bmatrix}.

    Answer

    (17,39)(17, 39)

    Full solution

    As columns: 5(1,3)+6(2,4)=(5,15)+(12,24)5(1, 3) + 6(2, 4) = (5, 15) + (12, 24).

  2. Compute [201132][123]\begin{bmatrix} 2 & 0 & 1\\ 1 & 3 & 2\end{bmatrix}\begin{bmatrix} 1 \\ 2 \\ 3\end{bmatrix}.

    Answer

    (5,13)(5, 13)

    Full solution

    Row by row: 2+0+3=52 + 0 + 3 = 5 and 1+6+6=131 + 6 + 6 = 13.

  3. What size is the product of a 4×34 \times 3 matrix and a 3×73 \times 7 matrix?

    Answer

    4×74 \times 7

    Full solution

    The inner sizes, both 33, must match and disappear; the outer sizes remain.

  4. Can a 2×32 \times 3 matrix be multiplied by a 2×32 \times 3 matrix?

    Answer

    No

    Full solution

    The first has 33 columns and the second has 22 rows, so the sizes do not line up in either order.

  5. Compute XYXY for X=[1234]X = \begin{bmatrix} 1 & 2\\ 3 & 4\end{bmatrix} and Y=[5678]Y = \begin{bmatrix} 5 & 6\\ 7 & 8\end{bmatrix}.

    Answer

    [19224350]\begin{bmatrix} 19 & 22\\ 43 & 50 \end{bmatrix}

    Full solution

    Row 11 against the columns of YY: 5+14=195 + 14 = 19 and 6+16=226 + 16 = 22. Row 22: 15+28=4315 + 28 = 43 and 18+32=5018 + 32 = 50.

  6. Compute YXYX for the same matrices, and compare.

    Answer

    [23343146]\begin{bmatrix} 23 & 34\\ 31 & 46 \end{bmatrix}, different from XYXY

    Full solution

    5+18=235 + 18 = 23, 10+24=3410 + 24 = 34, 7+24=317 + 24 = 31, 14+32=4614 + 32 = 46. Matrix multiplication does not commute.

  7. Write Ax=bA\mathbf{x} = \mathbf{b} for the system 2x1+x2=52x_1 + x_2 = 5, x1−x2=1x_1 - x_2 = 1.

    Answer

    [211−1][x1x2]=[51]\begin{bmatrix} 2 & 1\\ 1 & -1\end{bmatrix}\begin{bmatrix} x_1 \\ x_2\end{bmatrix} = \begin{bmatrix} 5 \\ 1\end{bmatrix}

    Full solution

    The coefficients form the matrix, the unknowns the vector, and the right-hand sides the target.

  8. If AA is 3×23 \times 2, what are the images Ae1A\mathbf{e}_1 and Ae2A\mathbf{e}_2?

    Answer

    The first and second columns of AA

    Full solution

    ej\mathbf{e}_j has a 11 in position jj, so the combination of columns keeps only column jj.

  9. The matrix M=[2101]M = \begin{bmatrix} 2 & 1\\ 0 & 1\end{bmatrix} acts on the unit square. Where does the corner (1,1)(1, 1) go?

    Answer

    (3,1)(3, 1)

    Full solution

    M(1,1)M(1, 1) is the sum of the two columns, (2,0)+(1,1)(2, 0) + (1, 1), which matches the parallelogram in the figure.

  10. A student computes [1234][5678]\begin{bmatrix} 1 & 2\\ 3 & 4\end{bmatrix}\begin{bmatrix} 5 & 6\\ 7 & 8\end{bmatrix} as [5122132]\begin{bmatrix} 5 & 12\\ 21 & 32\end{bmatrix}. What went wrong?

    Hint

    How many numbers go into one entry of the product?

    Answer

    The student multiplied matching entries. Each entry of the product is a dot product of a row with a column, giving [19224350]\begin{bmatrix} 19 & 22\\ 43 & 50\end{bmatrix}.

    Full solution

    Entry by entry multiplication is a different operation, and it does not match composition: the point of the row-by-column rule is that (AB)x=A(Bx)(AB)\mathbf{x} = A(B\mathbf{x}), which entrywise products fail.

Frequently asked questions

What is Ax?

The linear combination of the columns of A with the entries of x as coefficients. For a 3 × 2 matrix and x = (2, 3), it is 2 times the first column plus 3 times the second.

When can two matrices be multiplied?

When the first has as many columns as the second has rows. An m × n matrix times an n × p matrix gives an m × p matrix.

How is each entry of a product computed?

The entry in row i and column j of AB is the dot product of row i of A with column j of B.

Is matrix multiplication commutative?

No. AB and BA can have different sizes, and even when both exist they are usually different matrices.

What does the identity matrix do?

I has ones on the diagonal and zeros elsewhere, and AI = IA = A. It is the matrix of the transformation that changes nothing.

What to learn next