Matrix Multiplication

Matrix multiplication combines each row of the first matrix with each column of the second. The entry in row i, column j of AB is the sum of the products of row i of A with column j of B. You can multiply an m \times n matrix by an n \times p matrix, and the product is m \times p. Order matters: usually AB \ne BA.

Before this lesson: You should know Matrix Operations, Multiplying and Dividing Integers and Order of Operations.

How Row-Times-Column Works

To find one entry of the product, pick a row from the first matrix and a column from the second. Multiply their first numbers, their second numbers, and so on, then add the products. That sum is one entry.

For this to work, the row and the column must have the same length. So the number of columns in the first matrix must equal the number of rows in the second. Those are the “inside” dimensions, and the “outside” dimensions give the size of the answer.

The product of the matrices with rows 2, 1 and 3, 4 and with rows 5, −1 and 0, 2 equals the matrix with rows 10, 0 and 15, 5. Row 2 of the first matrix is outlined in solid blue, column 1 of the second is outlined in dashed orange, and the entry 15 in row 2, column 1 of the answer is boxed in green, since 3 · 5 + 4 · 0 = 15.
Row 2 times column 1 gives the entry in row 2, column 1 of the product: 3 · 5 + 4 · 0 = 15.

The Rule for Matrix Multiplication

(m \times \underline{n})(\underline{n} \times p) \to m \times p
\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} ae + bg & af + bh \\ ce + dg & cf + dh \end{bmatrix}
  • Inside dimensions must match; outside dimensions give the product’s size.
  • Entry (i, j) of AB = row i of A times column j of B, added up.
  • Usually AB \ne BA, so keep the order.
  • The identity matrix I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} works like 1: AI = IA = A.

Worked Examples

Example 1: Can you multiply?

A is 2 \times 3, B is 3 \times 2 and C is 2 \times 2. Which products exist, and what size are they: AB, BA, AC, CA?

  1. AB: (2 \times 3)(3 \times 2). Inside 3 and 3 match, so AB is 2 \times 2
  2. BA: (3 \times 2)(2 \times 3). Inside 2 and 2 match, so BA is 3 \times 3
  3. AC: (2 \times 3)(2 \times 2). Inside 3 and 2 don’t match, so AC is undefined
  4. CA: (2 \times 2)(2 \times 3). Inside 2 and 2 match, so CA is 2 \times 3

Answer: AB is 2 \times 2, BA is 3 \times 3, AC is undefined and CA is 2 \times 3.

Example 2: Multiply two 2 × 2 matrices

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

2(5) + 1(0) = 10 + 0 = 10

Row 1 times column 1.

2(-1) + 1(2) = -2 + 2 = 0

Row 1 times column 2.

3(5) + 4(0) = 15 + 0 = 15

Row 2 times column 1.

3(-1) + 4(2) = -3 + 8 = 5

Row 2 times column 2.

Answer: AB = \begin{bmatrix} 10 & 0 \\ 15 & 5 \end{bmatrix}, as in the picture above.

Example 3: A 2 × 3 times a 3 × 2

Find AB for A = \begin{bmatrix} 1 & 0 & 2 \\ -1 & 3 & 1 \end{bmatrix} and B = \begin{bmatrix} 3 & 1 \\ 2 & 1 \\ 1 & 0 \end{bmatrix}.

The product is (2 \times 3)(3 \times 2) \to 2 \times 2

1(3) + 0(2) + 2(1) = 3 + 0 + 2 = 5

Row 1, column 1.

1(1) + 0(1) + 2(0) = 1 + 0 + 0 = 1

Row 1, column 2.

-1(3) + 3(2) + 1(1) = -3 + 6 + 1 = 4

Row 2, column 1.

-1(1) + 3(1) + 1(0) = -1 + 3 + 0 = 2

Row 2, column 2.

Answer: AB = \begin{bmatrix} 5 & 1 \\ 4 & 2 \end{bmatrix}

Example 4: Order matters

Using A and B from Example 2, find BA and compare it with AB.

5(2) + (-1)(3) = 10 - 3 = 7

Row 1 times column 1.

5(1) + (-1)(4) = 5 - 4 = 1

Row 1 times column 2.

0(2) + 2(3) = 0 + 6 = 6

Row 2 times column 1.

0(1) + 2(4) = 0 + 8 = 8

Row 2 times column 2.

Answer: BA = \begin{bmatrix} 7 & 1 \\ 6 & 8 \end{bmatrix}, but AB = \begin{bmatrix} 10 & 0 \\ 15 & 5 \end{bmatrix}. So AB \ne BA: matrix multiplication is not commutative.

Example 5: Word problem with sales

A café sold drinks on two days. Matrix Q lists how many coffees, teas and juices it sold, with Monday in row 1 and Tuesday in row 2. Matrix P lists the prices in dollars. Find each day’s revenue.

Q = \begin{bmatrix} 20 & 15 & 10 \\ 5 & 30 & 25 \end{bmatrix}, \quad P = \begin{bmatrix} 3.50 \\ 2.75 \\ 4.00 \end{bmatrix}

The product QP is (2 \times 3)(3 \times 1) \to 2 \times 1, one revenue per day

20(3.50) + 15(2.75) + 10(4.00) = 70 + 41.25 + 40 = 151.25

Monday: multiply each amount by its price and add.

5(3.50) + 30(2.75) + 25(4.00) = 17.50 + 82.50 + 100 = 200

Tuesday: multiply each amount by its price and add.

Answer: QP = \begin{bmatrix} 151.25 \\ 200.00 \end{bmatrix}: $151.25 on Monday and $200.00 on Tuesday.

Common Mistakes

MistakeExample of the errorFix
Multiplying matching entries\begin{bmatrix} 2 & 1 \\ 3 & 4 \end{bmatrix}\begin{bmatrix} 5 & -1 \\ 0 & 2 \end{bmatrix} = \begin{bmatrix} 10 & -1 \\ 0 & 8 \end{bmatrix}Use rows times columns: the answer is \begin{bmatrix} 10 & 0 \\ 15 & 5 \end{bmatrix}.
Ignoring the dimension checkTrying to multiply (2 \times 3)(2 \times 3)The inside numbers must match; this product is undefined.
Switching the orderAssuming AB = BAKeep the order. AB and BA are usually different.
Wrong size for the answerSaying (2 \times 3)(3 \times 2) is 3 \times 3The outside numbers give the size: 2 \times 2.
Forgetting to addWriting the entry as the list 6, 4Each entry is one number: add the products, 6 + 4 = 10.

Related Methods

Powers of a matrix

A^2 means AA, which only works for square matrices. For A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}, A^2 = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix}.

Systems as matrix equations

The system 2x + y = 5, 3x + 4y = 10 can be written AX = B with A = \begin{bmatrix} 2 & 1 \\ 3 & 4 \end{bmatrix}, X = \begin{bmatrix} x \\ y \end{bmatrix} and B = \begin{bmatrix} 5 \\ 10 \end{bmatrix}. Multiplying AX gives back the left sides.

Graphing calculator

Enter the matrices in the matrix editor and type [A][B]. The calculator gives a dimension error if the inside sizes don’t match.

Practice Problems

  1. What size is the product of a 3 \times 2 matrix and a 2 \times 4 matrix?
  2. Can you multiply a 2 \times 3 matrix by another 2 \times 3 matrix? Explain.
  3. Find \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.
  4. Find \begin{bmatrix} 2 & -1 \\ 0 & 3 \end{bmatrix}\begin{bmatrix} 4 \\ 5 \end{bmatrix}.
  5. Find \begin{bmatrix} 1 & 2 & 3 \end{bmatrix}\begin{bmatrix} 4 \\ 5 \\ 6 \end{bmatrix}.
  6. Find \begin{bmatrix} 4 \\ 5 \\ 6 \end{bmatrix}\begin{bmatrix} 1 & 2 & 3 \end{bmatrix}.
  7. Find A^2 for A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}.
  8. Find IA for A = \begin{bmatrix} 7 & -2 \\ 3 & 5 \end{bmatrix}, where I is the 2 \times 2 identity matrix.
  9. Find x if \begin{bmatrix} x & 2 \\ 1 & 3 \end{bmatrix}\begin{bmatrix} 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 8 \\ 5 \end{bmatrix}.
  10. A class weights homework 20%, quizzes 30% and tests 50%. Two students’ averages are S = \begin{bmatrix} 90 & 80 & 85 \\ 70 & 95 & 88 \end{bmatrix} (homework, quizzes, tests). Use W = \begin{bmatrix} 0.2 \\ 0.3 \\ 0.5 \end{bmatrix} to find each final grade.
Show answers

1.

Inside numbers 2 and 2 match
Answer: 3 \times 4

2.

Inside numbers are 3 and 2, which don’t match
Answer: no; the product is undefined

3.

Row 1: 1(0) + 2(1) = 2 and 1(1) + 2(0) = 1
Row 2: 3(0) + 4(1) = 4 and 3(1) + 4(0) = 3
Answer: \begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix} (the columns swapped)

4.

2(4) + (-1)(5) = 8 - 5 = 3

Multiply row 1 by the column.

0(4) + 3(5) = 0 + 15 = 15

Multiply row 2 by the column.

Answer: \begin{bmatrix} 3 \\ 15 \end{bmatrix}

5.

(1 \times 3)(3 \times 1) \to 1 \times 1

Check the sizes: the inside numbers match.

1(4) + 2(5) + 3(6) = 4 + 10 + 18 = 32

Multiply matching entries and add.

Answer: \begin{bmatrix} 32 \end{bmatrix}

6.

(3 \times 1)(1 \times 3) \to 3 \times 3; each entry is one product
Row 1: 4, 8, 12; row 2: 5, 10, 15; row 3: 6, 12, 18
Answer: \begin{bmatrix} 4 & 8 & 12 \\ 5 & 10 & 15 \\ 6 & 12 & 18 \end{bmatrix}

7.

Row 1: 1(1) + 1(0) = 1 and 1(1) + 1(1) = 2
Row 2: 0(1) + 1(0) = 0 and 0(1) + 1(1) = 1
Answer: \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix}

8.

Row 1 of I picks out row 1 of A, and row 2 of I picks out row 2

1(7) + 0(3) = 7

For example, multiply row 1 by column 1.

Answer: \begin{bmatrix} 7 & -2 \\ 3 & 5 \end{bmatrix}, the same as A

9.

Row 1: 2x + 2(1) = 8, so 2x = 6 and x = 3
Check row 2: 1(2) + 3(1) = 5, which matches
Answer: x = 3

10.

90(0.2) + 80(0.3) + 85(0.5) = 18 + 24 + 42.5 = 84.5

Student 1: multiply each score by its weight and add.

70(0.2) + 95(0.3) + 88(0.5) = 14 + 28.5 + 44 = 86.5

Student 2: multiply each score by its weight and add.

Answer: SW = \begin{bmatrix} 84.5 \\ 86.5 \end{bmatrix}

FAQ

How do you multiply two matrices?

For each entry of the answer, multiply a row of the first matrix by a column of the second, number by number, and add the products. Do this for every row and column pair.

When can you multiply matrices?

When the number of columns in the first matrix equals the number of rows in the second. A 2 \times 3 matrix can multiply a 3 \times 4 matrix, but not a 2 \times 3 matrix.

Is matrix multiplication commutative?

No. In general AB \ne BA, and sometimes one of them doesn’t even exist. Always multiply in the given order.

What is the identity matrix?

It is a square matrix with 1s on the main diagonal and 0s everywhere else. Multiplying by it leaves a matrix unchanged, just like multiplying a number by 1.

Summary

  • (m \times n)(n \times p) \to m \times p: inside sizes match, outside sizes give the answer’s size.
  • Each entry is a row of the first matrix times a column of the second, added up.
  • Matrix multiplication is not commutative: AB \ne BA in general.
  • The identity matrix I leaves a matrix unchanged.
  • Matrix products can total costs, revenues and weighted scores.

Previous lesson: Matrix Operations

Next lesson: Solving Systems with Augmented Matrices

Back to the Precalculus Index