girgit.org

Matrices

Multiplying matrices: row into column

The big ideaTo multiply matrices, run each row of the first along each column of the second, multiplying pairs and adding: this works only when the first matrix has as many columns as the second has rows.

In simple words

You know how many of each thing two friends want to buy, and you know the price of each thing. To find what one friend pays, take her list and the price list, multiply each amount by its price, and add it all up. Do this for every friend and every shop, and put the answers in a new grid. That is all matrix multiplication is: many shopping bills at once.

Two friends, two shops

Riya wants 3 notebooks and 2 pens. Kabir wants 1 notebook and 4 pens. A notebook costs ₹40 and a pen ₹10. Riya pays 3 × 40 + 2 × 10 = ₹140; Kabir pays 1 × 40 + 4 × 10 = ₹80. In matrices:

\[ \underbrace{\begin{bmatrix} 3 & 2 \\ 1 & 4 \end{bmatrix}}_{\text{what they buy}} \underbrace{\begin{bmatrix} 40 \\ 10 \end{bmatrix}}_{\text{prices}} = \underbrace{\begin{bmatrix} 3 \times 40 + 2 \times 10 \\ 1 \times 40 + 4 \times 10 \end{bmatrix}}_{\text{bills}} = \begin{bmatrix} 140 \\ 80 \end{bmatrix} \]

A second shop charges ₹35 a notebook and ₹15 a pen. Put both price lists side by side as columns and do everything at once:

\[ \begin{bmatrix} 3 & 2 \\ 1 & 4 \end{bmatrix} \begin{bmatrix} 40 & 35 \\ 10 & 15 \end{bmatrix} = \begin{bmatrix} 140 & 135 \\ 80 & 95 \end{bmatrix} \]

Row = friend, column = shop. Riya should go to the second shop (₹135); Kabir to the first (₹80).

The row-into-column rule

Each entry of the product comes from one row of the first matrix and one column of the second. Walk along the row and down the column together, multiply the pairs, then add. The entry lands in that row and that column of the answer.

For this to work, the row and the column must be the same length. So the product AB is defined only when

\[ \text{number of columns of A} = \text{number of rows of B}. \]

If A is m × n and B is n × p, then AB is m × p. Write the orders side by side: the inside numbers must match, and the outside numbers give the size of the answer.

\[ (m \times \underline{n})\,(\underline{n} \times p) \;\to\; m \times p \]

In symbols, if \( A = [a_{ij}]_{m \times n} \) and \( B = [b_{jk}]_{n \times p} \), then \( AB = C = [c_{ik}]_{m \times p} \) with

\[ c_{ik} = a_{i1}b_{1k} + a_{i2}b_{2k} + \cdots + a_{in}b_{nk} = \sum_{j=1}^{n} a_{ij}b_{jk}. \]

The sum runs over j, the shared "inside" index: the column number in A and the row number in B.

Step by step

Worked example

\( A = \begin{bmatrix} 2 & 1 & 0 \\ -1 & 3 & 4 \end{bmatrix} \) (2 × 3) and \( B = \begin{bmatrix} 1 & 2 \\ 0 & -1 \\ 5 & 3 \end{bmatrix} \) (3 × 2). Find AB.

  1. Check: A has 3 columns, B has 3 rows. Defined. AB will be 2 × 2.
  2. Row 1 of A with column 1 of B: (2)(1) + (1)(0) + (0)(5) = 2. This is \( c_{11} \).
  3. Row 1 of A with column 2 of B: (2)(2) + (1)(−1) + (0)(3) = 3. This is \( c_{12} \).
  4. Row 2 of A with column 1 of B: (−1)(1) + (3)(0) + (4)(5) = 19. This is \( c_{21} \).
  5. Row 2 of A with column 2 of B: (−1)(2) + (3)(−1) + (4)(3) = 7. This is \( c_{22} \).

\[ AB = \begin{bmatrix} 2 & 3 \\ 19 & 7 \end{bmatrix} \]

Keep a finger on the row and another on the column. Most mistakes come from using a column of A or a row of B.

Try it: here is the same product, laid out so that each row of A meets each column of B right at the entry it makes. Tap an entry of AB, then change any number.

Guess first: a row times a column

Let \( R = \begin{bmatrix} 1 & 2 & 3 \end{bmatrix} \) and \( K = \begin{bmatrix} 4 \\ 5 \\ 6 \end{bmatrix} \). Guess: what size are RK and KR?

See what happens
RK is (1 × 3)(3 × 1) = 1 × 1: just [4 + 10 + 18] = [32]. But KR is (3 × 1)(1 × 3) = 3 × 3: \[ KR = \begin{bmatrix} 4 & 8 & 12 \\ 5 & 10 & 15 \\ 6 & 12 & 18 \end{bmatrix}. \] The same two matrices give a single number one way and nine numbers the other way. Order matters a great deal in matrix multiplication, as the next page shows.

If A is m × n and B is k × l, then AB needs n = k and BA needs l = m. Both are defined only when n = k and l = m. In particular, for two square matrices of the same order, both AB and BA are always defined.

Try it: change the four sizes and see when AB and BA exist, and how big they are.

Remember

  • AB is defined only if columns of A = rows of B.
  • (m × n)(n × p) gives m × p.
  • \( c_{ik} \) = (row i of A) times (column k of B), entry by entry, then added.

Try it. Find \( \begin{bmatrix} 1 & -2 \\ 3 & 0 \end{bmatrix} \begin{bmatrix} 2 & 1 & 4 \\ 1 & 5 & -1 \end{bmatrix} \).

Answer
(2 × 2)(2 × 3) gives 2 × 3. Row 1: 2 − 2 = 0, 1 − 10 = −9, 4 + 2 = 6. Row 2: 6 + 0 = 6, 3 + 0 = 3, 12 + 0 = 12. So the product is \( \begin{bmatrix} 0 & -9 & 6 \\ 6 & 3 & 12 \end{bmatrix} \).

Words to know

Product AB
The matrix whose (i, k)th entry is row i of A times column k of B.
Defined (product)
Possible to compute: columns of A equal rows of B.
Order of AB
Rows of A × columns of B.
\( \sum \)
"Add up all of these"; here, over the shared index j.

A is 3 × 2 and B is 2 × 4. What can you say?

  1. AB is 3 × 4; BA is not defined
  2. AB is 2 × 2
  3. AB and BA are both defined

\( \begin{bmatrix} 1 & 2 \\ 0 & 3 \end{bmatrix} \begin{bmatrix} 4 & 1 \\ 5 & 2 \end{bmatrix} \) has which (1, 2) entry?

  1. 2
  2. 5
  3. 14

X is 2 × n, W is n × 3. What is the order of XW?

  1. n × n
  2. 2 × 3
  3. 3 × 2