Skip to lesson content

Lesson 4 of 8

Matrices · Lesson 4 of 8

How Matrix Multiplication Works

“Build row-by-column products and understand why order and dimensions matter.”

Learning Objectives

• Explain matrix multiplication through weighted totals. • Decide whether a product exists and determine its order before calculating. • Calculate each product entry as a row-by-column sum. • Distinguish AB from BA, including cases with different existence or dimensions. • Use counterexamples to explain noncommutativity and zero products of nonzero matrices.

A product combines quantities with weights

Matrix multiplication answers a different question from entrywise addition. A shopping bill, for instance, multiplies each quantity by its matching price and adds the costs. This sum of products is the basic calculation behind every entry of a matrix product.

Meera needs 2 pens and 5 storybooks; Nadeem needs 8 pens and 10 storybooks. At a shop charging ₹5 per pen and ₹50 per storybook, Meera’s bill is 2×5+5×50 = ₹260. Nadeem’s bill is 8×5+10×50 = ₹540. The quantities form two rows, and the matching prices form a column.

Quantities multiplied by pricesLaTeX
Rows of the first matrix represent people, its columns represent items, and the second matrix puts one price against each item. The output has one bill per person.

A second shop charges ₹4 per pen and ₹40 per storybook. Place the two shops’ price columns next to each other: P = [5,4;50,40]. Keeping items in the row order pens, storybooks makes them align with the quantity columns. Multiplication now gives both shops’ bills in one array.

Two shops in one productLaTeX
The rows of QP are Meera and Nadeem; its columns are shops 1 and 2. For example, the top-right bill is 2×4+5×40 = ₹208.

We did not multiply entries merely because they occupied the same position in Q and P. We matched the items across one complete row of quantities and one complete column of prices. If one matrix listed pens before books and the other books before pens, the arithmetic would combine the wrong categories even if the dimensions were compatible.

Dimensions first, entries second

A row and a column can be paired only when they contain the same number of entries. This gives a quick test for whether multiplication is possible. It also predicts the shape of the answer before any arithmetic begins.

Definition
Matrix product

If A has order m × n and B has order n × p, the product AB is defined and has order m × p. Its (i,k) entry is the sum of the products of corresponding entries in row i of A and column k of B.

The row-by-column ruleLaTeX
The shared index j runs through the n matched positions. The fixed index i selects an output row and the fixed index k selects an output column.

The inner dimensions must agree: A’s column count equals B’s row count. The outer dimensions then give the product order. Thus a 2 × 3 matrix multiplied by a 3 × 4 matrix gives a 2 × 4 matrix. There are eight output entries, and each is a sum of three products. Equal total entry counts are irrelevant to this test.

One output entry uses one row and one columnA: 2 × 3B: 3 × 2AB: 2 × 21-1203427-115-413-217-13First row · first column: 1×2 + (−1)×(−1) + 2×5 = 13The shared length is 3; the output keeps 2 rows and 2 columns.
Tracing one row and one column— The shaded first row and first column make 13 in the product. Repeat the same rule at the other three output positions.
Example — All four cells of a rectangular product

Problem
Find CD for C = [1,−1,2;0,3,4] and D = [2,7;−1,1;5,−4].

  1. 1.The orders are 2 × 3 and 3 × 2. The inner dimensions agree, so CD exists and has order 2 × 2.
  2. 2.First row, first column: 1×2+(−1)×(−1)+2×5 = 2+1+10 = 13. First row, second column: 1×7+(−1)×1+2×(−4) = 7−1−8 = −2.
  3. 3.Second row, first column: 0×2+3×(−1)+4×5 = 0−3+20 = 17. Second row, second column: 0×7+3×1+4×(−4) = 0+3−16 = −13.
  4. 4.Therefore CD = [13,−2;17,−13]. Four different row-column pairings produced the four output addresses.
Example — A defined product and an undefined reverse product

Problem
Find AB for A = [6,9;2,3] and B = [2,6,0;7,9,8]. Is BA also defined?

  1. 1.A has order 2 × 2 and B has order 2 × 3. Thus AB exists and has order 2 × 3.
  2. 2.Using the first row of A, the three output entries are 6×2+9×7 = 75, 6×6+9×9 = 117, and 6×0+9×8 = 72.
  3. 3.Using the second row, they are 2×2+3×7 = 25, 2×6+3×9 = 39, and 2×0+3×8 = 24.
  4. 4.Hence AB = [75,117,72;25,39,24]. For BA, the inner dimensions would be 3 and 2, which do not agree. BA is not defined; it is not a zero matrix.
Multiplication is not entrywise

The entry (AB)ᵢⱼ is generally not aᵢⱼbᵢⱼ. A matrix product uses a whole row and a whole column. Also distinguish “undefined” from “zero”: zero is a valid matrix with a definite order, while an incompatible product has no value under this rule.

Why reversing the factors changes the problem

Switching A and B changes which rows meet which columns. The reverse product may be undefined, may have a different order, or may have the same order but different entries. These are separate reasons not to assume AB = BA.

If A has order m × n and B has order k × ℓ, AB exists exactly when n = k. The reverse product BA exists exactly when ℓ = m. Therefore both products exist exactly when both conditions hold. For two square matrices of one common order, both products always exist, but existence alone says nothing about equality.

Example — Both products exist but have different orders

Problem
Let A = [1,−2,3;−4,2,5] and B = [2,3;4,5;2,1]. Calculate AB and BA.

  1. 1.The orders 2 × 3 and 3 × 2 make AB a 2 × 2 matrix and BA a 3 × 3 matrix. They cannot be equal because equality requires the same order.
  2. 2.For AB, row 1 gives [2−8+6, 3−10+3] = [0,−4]. Row 2 gives [−8+8+10, −12+10+5] = [10,3]. Thus AB = [0,−4;10,3].
  3. 3.For BA, the first row [2,3] gives [2−12, −4+6, 6+15] = [−10,2,21]. The second row [4,5] gives [−16,2,37].
  4. 4.The third row [2,1] gives [2−4, −4+2, 6+5] = [−2,−2,11]. Hence BA = [−10,2,21;−16,2,37;−2,−2,11].
  5. 5.Reversing the factors changes both the number and the meaning of the output pairings. Even matching some entries would not remove the order difference.
Example — Noncommutativity even for square matrices

Problem
Let A = [1,0;0,−1] and B = [0,1;1,0]. Show that AB and BA differ.

  1. 1.Both matrices are 2 × 2, so both products are defined and both are 2 × 2.
  2. 2.Multiplying A by B gives AB = [0,1;−1,0]. For example, its bottom-left entry is 0×0+(−1)×1 = −1.
  3. 3.Reversing the factors gives BA = [0,−1;1,0]. Its top-right entry is 0×0+1×(−1) = −1.
  4. 4.Thus AB ≠ BA even though their orders match. A single valid counterexample is enough to show that matrix multiplication is not commutative in general.

“Not commutative in general” does not mean “never commutative”. Diagonal matrices of one common order commute: their product is diagonal, with corresponding diagonal entries multiplied. For D = [1,0;0,2] and E = [3,0;0,4], both DE and ED equal [3,0;0,8]. We must determine which situation applies to the actual factors.

A zero product does not force a zero factor

For real numbers, ab = 0 forces at least one factor to be zero. Matrix multiplication combines multiple terms into each output entry, so the same conclusion does not follow. This difference is a reason to check matrix arguments carefully rather than transfer every number rule unchanged.

Example — Nonzero factors with zero product

Problem
Calculate AB for A = [0,−1;0,2] and B = [3,5;0,0].

  1. 1.Neither factor is the zero matrix: A contains −1 and 2, while B contains 3 and 5.
  2. 2.The first row of A paired with B’s first column gives 0×3+(−1)×0 = 0. With the second column it gives 0×5+(−1)×0 = 0.
  3. 3.The second row gives 0×3+2×0 = 0 and 0×5+2×0 = 0. Therefore AB = [0,0;0,0] = O.
  4. 4.The vanishing product comes from how these rows and columns meet. It does not establish A = O or B = O. In fact, BA = [0,7;0,0], so reversing the factors does not even preserve this zero product.

Quiz

Quick check

A has order 3 × 2 and B has order 2 × 4. What is the order of AB?

Quick check

For A = [1,2;3,4] and B = [5,6;7,8], what is the top-right entry of AB?

Quick check

If AB exists, what can always be concluded about BA?

Quick check

Which statement about same-order diagonal matrices is correct?

Quick check

What does AB = O imply for arbitrary compatible matrices?

Quick check

If A is 2 × 5 and B is 5 × 2, which statement holds?

Practice Problems

Practice Problems
  1. For A = [2,4;3,2] and B = [1,3;−2,5], calculate AB and BA separately. Compare corresponding entries rather than assuming equality.
  2. Calculate (a) [a,b;−b,a][a,−b;b,a] and (b) [1;2;3][2,3,4]. State each product order before calculating.
  3. Calculate (a) [1,−2;2,3][1,2,3;2,3,1] and (b) [2,3,4;3,4,5;4,5,6][1,−3,5;0,2,4;3,0,5].
  4. Calculate (a) [2,1;3,2;−1,1][1,0,1;−1,2,1] and (b) [3,−1,3;−1,0,2][2,−3;1,0;3,1]. Check one output cell independently in each answer.
  5. Compare both multiplication orders for each pair: (a) [5,−1;6,7] and [2,1;3,4]; (b) [1,2,3;0,1,0;1,1,0] and [−1,1,0;0,−1,1;2,3,4]. Find an entry that proves the two products unequal.
  6. Let Y, W, P have orders 3 × k, n × 3, p × k. Find all restrictions on n, k, p for PY+WY to be defined. Distinguish the multiplication checks from the final addition check.
  7. For Q = [2,5;8,10] and P = [5,4;50,40], explain the meaning and units of every entry of QP. Explain why an entrywise product would not calculate shopping bills.

Key Takeaways

Key Takeaways

• AB exists when A’s column count equals B’s row count; the outer dimensions give its order. • Each output entry is one row-by-column sum of matched products. • Labels and units must align in data applications, not just numerical dimensions. • AB and BA may have different existence, different orders, or different entries. • Same-order diagonal matrices commute, but arbitrary matrices need not. • A zero matrix product can have two nonzero factors.