In the last article the price table was multiplied by the purchase column, and out came the bill of each supplier. Now there are two tables, and one is multiplied by the other. This article explains how that works and why the rule is exactly “row times column”.
Imagine a bakery that bakes cakes and rolls. It does not bake them straight from raw materials: first it mixes dough, shortcrust and yeast dough, and only then makes the goods from the dough. So it has two tables, and the third, the one it needs most, is missing:
Table
Who knows it
What it holds
first
the technologist
how much flour and butter goes into each dough
second
the baker
how much dough goes into a cake and into a roll
third
nobody
how much flour and butter goes straight into one item
And it is the third one the bakery needs: every morning it has to order flour and butter for the day's plan. You can build the third table by hand by going through every path like “flour → dough → cake”. With three raw materials, three doughs and five items that is forty-five products.
Matrix multiplication does this assembly in one step. The rule “row times column” is not a convention there, it is exactly this walk through the paths. All three exam tasks worked through further down rest on the same rule as well.
Let us work it through for a smaller bakery, with two raw materials and two doughs.
How much flour goes into one cake?
Neither of the two tables holds this number. It comes from both: a cake takes 2 units of shortcrust at 3 ME of flour each and 1 unit of yeast dough at 4 ME, so 3⋅2+4⋅1=10 ME of flour.
What helps here. The rule from the last article: a row of the table is multiplied by the column, so the numbers are multiplied in pairs and added: (2386)(3010)=(140150). Here the same rule repeats for every item. It is explained in detail in the article “Matrix and vector: working out the cost of a purchase from several suppliers”.
Check yourself. An exam-level task: for A=132201 and B=(4215), find the element of the product A⋅B in row 3 and column 2.
The product of two matrices: where row times column comes from
In A the columns are shortcrust and yeast dough: one unit of shortcrust takes 3 ME (quantity units, German Mengeneinheiten) of flour and 2 ME of butter, one unit of yeast dough 4 ME of flour and 1 ME of butter.
In B the columns are cake and bun: a cake takes 2 units of shortcrust and 1 unit of yeast dough, a bun 3 units of yeast dough.
The flour per cake can be worked out from the recipes. The cake takes 2 units of shortcrust with 3 ME of flour each, and 1 unit of yeast dough with 4 ME of flour:
3⋅⋅2++4⋅⋅1==6++4==10 ME of flour per cake
The first factors, 3 and 4, stand in the row 'flour' of A, the second ones, 2 and 1, in the column 'cake' of B. The column 'cake' acts as a purchase vector (how much of which dough), the row 'flour' as a price list (how much flour in each dough). Butter per cake, and flour and butter per bun, come out the same way. The table of these four numbers is called the matrix product (German: Matrixprodukt) A⋅B. Step by step, one element per step:
3 · 2 + 4 · 1 = 10
Step 1 of 4Flour per cake: row 1 times column 1
3⋅2+4⋅1=10. The element in row 1 and column 1 of the product.
3⋅0+4⋅3=12. A bun takes no shortcrust, so the first term is 0.
2⋅2+1⋅1=5.
2⋅0+1⋅3=3. Result: A⋅B=(105123), rows raw materials, columns products.
The element of the product C=A⋅B in row i and column j is written cij. It is row i of A times column j of B:
cij==ai1⋅⋅b1j++ai2⋅⋅b2j++⋯++ain⋅⋅bnj
The sum runs over all n intermediate products, here the two kinds of dough. The number of the dough is the second index on a, because in A the dough labels the columns, and the first on b, because in B it labels the rows. For example c21=5: row 'butter' times column 'cake', butter per cake.
Why multiply tables? The raw material for an order of 10 cakes and 20 buns, p=(1020), is worked out in two ways:
in two steps: first the dough, B⋅p=(2⋅10+0⋅201⋅10+3⋅20)=(2070), then the raw material for that dough, A⋅(2070)=(3⋅20+4⋅702⋅20+1⋅70)=(340110);
in one step with the table A⋅B: (10⋅10+12⋅205⋅10+3⋅20)=(340110), the same.
The rule “row times column” is chosen exactly so that multiplying by A⋅B means multiplying first by B, then by A.
When the product exists and what size it has
In c11 the row 'flour' and the column 'cake' are multiplied number by number, one number per dough. So A must have as many columns as B has rows. In the result the dough is gone: the rows of the product come from A (raw materials), the columns from B (products).
(m×n)⋅(n×k)=m×k
Write the sizes side by side, and the inner numbers become neighbours. For A of size 2×3 and B of size 3×4: (2×3)⋅(3×4), inside 3 and 3, the product exists, size 2×4. In reverse order the inner numbers are 4 and 2, and B⋅A does not exist. Matrix times vector follows the same rule: (2×3)⋅(3×1)=2×1.
Trap: comparing the wrong numbers. Rushing, people compare the first or the outer numbers, 2 and 4, and answer “not defined” although the product exists. Compare only the two numbers in the middle of (2×3)⋅(3×4).
Your turn1 of 4
A has size 3×2, B size 2×4. Which statement is true?
The order matters: AB and BA are different
Why is 2⋅3=3⋅2 for numbers, while AB and BA differ for matrices? For the dough, work out the product in reverse order:
The matrices are different. Worse, B⋅A means nothing: a row of B runs over the products, a column of A over the raw materials, and the sum 2⋅3+0⋅2=6 counts nothing. It could be multiplied at all only because there are two products and two raw materials. In A⋅B the dough stands in the middle, shared by both tables.
What follows from this for the exam:
In general A⋅B=B⋅A, and one of the two products may not even exist.
(A+B)2=A2+AB+BA+B2, and AB+BA may not be merged into 2AB. Here AB+BA=(16142010), but 2AB=(2010246).
For particular matrices AB=BA does happen, for instance with the identity matrix below. A statement “for the given matrices” is checked by calculating, and one counterexample refutes a statement “for all matrices”.
Trap: working out BA instead of AB. For square matrices both products exist, and the wrong one gives a plausible number: at place (2,1), AB has 5 and BA has 9. Check: the row always comes from the left factor.
The transposed product: the order of the factors reverses
The order of the factors also changes when a product is transposed, only here it is not a mistake but a rule. Let us transpose A⋅B. The rows of (AB)T are now the products and the columns the raw materials, so the flour per cake sits in the row 'cake' and the column 'flour':
(AB)T==(101253)
To get this number as row times column, the row has to run over the dough for the cake and the column over the flour in each dough. Such rows belong to BT, such columns to AT. The factors change places, and the dough is in the middle again. Both transposed matrices beside the originals:
A==(3241),AT==(3421);B==(2103),BT==(2013)
In the figure BT is multiplied by AT; the row 'cake' and the column 'flour' are highlighted, and their product 2⋅3+1⋅4=10 gives the flour per cake again:
2 · 3 + 1 · 4 = 10
BTAT==(101253)==(AB)T,(A⋅B)T=BT⋅AT
ATBT also exists here, but it equals (6897)=(BA)T. With non-square matrices the sizes give the mistake away. For A of size 2×3 and B of size 3×4, BTAT is (4×3)⋅(3×2)=4×2, like (AB)T, while ATBT, (3×2)⋅(4×3), does not exist.
Trap: transposing each factor without reversing the order. It is tempting to write (AB)T=ATBT, the way brackets are expanded. Check: the sizes of non-square matrices.
The identity matrix, the power A², and the product of two vectors
Order matters almost always, but there is one matrix for which it does not: it changes nothing, like 1 when multiplying numbers. The identity matrix. A square matrix with ones on the main diagonal and zeros elsewhere is called the identity matrix (German: Einheitsmatrix) and written I:
I==(1001),A⋅⋅I==I⋅⋅A==A
Why: column j of I has a single one, in place j, and a row of A times this column picks out exactly element j: (34) times (10) gives 3=a11. This is one of the cases where AI=IA.
Letter: German tasks often write it E; in the next article E will stand for the end products (Endprodukte), so here it is I.
Number minus matrix: a number is subtracted from a matrix only through I. A−2I=(124−1) lowers only the diagonal by 2, while A−2 is not defined.
The power of a matrix.A2 means A⋅A, row of A times column of A:
Squaring the elements would give 9 instead of 17. A2 exists only for a square matrix, otherwise the inner sizes do not match.
The product of two vectors. A column vector of length n has size n×1, and the size rule decides what comes out. For a=(12) and b=(34):
aTb is (1×2)⋅(2×1)=1×1, one number: 1⋅3+2⋅4=11, the scalar product. aTb=bTa.
abT is (2×1)⋅(1×2)=2×2, a matrix: abT=(1⋅32⋅31⋅42⋅4)=(3648).
xTAx is (1×n)⋅(n×n)⋅(n×1)=1×1, a number too. For A=(1324) and x=(12) first Ax=(511), then xT(Ax)=1⋅5+2⋅11=27.
Trap: mixing up number and matrix.aTb and abT differ only in where the T sits. Check by sizes: the T on the left gives a number, on the right an n×n matrix.
Row times column: one element of the product
In the exam you hardly ever compute the whole product. The first task asks for one entry of it, and that needs exactly one row and one column:
Exam-style task
Gegeben sind
A==(641501),B==21−2−132−246645
und das Produkt Z=AB. Welchen Wert hat z22?
a)nicht definiert
b)13
c)23
d)18
e)−4
The task gives itself away with the words “the product” and “What is” with a single element z22 of the product Z=AB: one number is asked for, not the whole matrix.
One element depends only on one row of the left matrix and one column of the right one, just as flour per cake depended only on the row 'flour' and the column 'cake'. The whole Z here is 2×4, eight sums, and one is needed.
inner sizes match: Z is 2 × 4z22: row 2 of A, column 2 of B13: option (b)
Step 1 of 4Check the sizes
A has size 2×3, B size 3×4. Inside 3 and 3, the product exists, Z is 2×4, and the place z22 exists in it. Option (a) is out.
The first index 2 is the row: row 2 of A, (451). The second index 2 is the column: column 2 of B from top to bottom, −132.
z22=4⋅(−1)+5⋅3+1⋅2=−4+15+2=13. Three terms, matching the inner size.
The row is from the left matrix A, the column from the right one B, as in Z=AB. Answer 13, option (b).
Sometimes the question asks for the sum of the elements on the main diagonal of the product (the trace, German: Spur). Given are A=132201 and B=(421501), Z=A⋅B.
(3×2)⋅(2×3): inside 2 and 2, Z is 3×3, with three elements on the diagonal.
z11=1⋅4+2⋅2=8, z22=3⋅1+0⋅5=3, z33=2⋅0+1⋅1=1.
8+3+1=12. The six elements off the diagonal are not needed.
Other forms of the same question
Each comes down to sums “row times column”:
an element of A2: row of A times column of A, not the square of an element;
an element of (A+B)2: first A+B element by element, then a row of the sum times its column;
three factors A⋅B⋅D: the required row of A⋅B, then that row times the required column of D.
Your turn2 of 4
Given A=(201431) and B=132205. Which element stands in the product C=A⋅B at place c21?
Traps. Each wrong option of the task at the start of the section repeats a real mistake:
Row times row, option (c), 23: a row of B was taken, 4⋅1+5⋅3+1⋅4=23, and the fourth number got lost. Check: the second factor is read top to bottom.
Neighbouring element, option (d), 18: column 3 was taken, 4⋅(−2)+5⋅4+1⋅6=18=z23. Check: write down both indices before calculating.
Only one term, option (e), −4: stopped at 4⋅(−1). Check: there are as many terms as the inner size says, here 3.
Wrong sizes, option (a): the outer numbers 2 and 4 were compared instead of the inner 3 and 3.
Row times column backwards: the element is known, find x
It also works the other way round: the element of the product is given, and one of the matrices contains an unknown x. An example: A=(2153), B=(14x2), the element of A⋅B in row 1 and column 2 is 4. Row (25) times column (x2) gives 2x+10. Set it equal to 4 and find x.
Checking statements (“Aussagen”) about products
The one-entry task tested whether you can work out row times column. The next exam task tests not the arithmetic but the rules from the first half of the article:
Exam-style task
Ausgangspunkt: A==(10−11−43),B==3−624−83
Aussagen:
AB ist die Einheitsmatrix I2.
Der Eintrag von BA in Zeile 2, Spalte 1 ist −6.
Die Determinante von BA ist 0.
Geben Sie an, welche der Aussagen (1), (2), (3) zutreffen.
a)nur (1) und (3)
b)keine
c)alle
d)nur (2) und (3)
e)nur (3)
The task gives itself away with the words “State which of statements” and “are correct” and a numbered list of statements about matrix products.
Statements about the given matrices are checked by calculating, statements about a general rule with the rules from the sections above. To refute a general rule, one counterexample is enough, often with the very matrices of the task. The questions almost always sit where the rules for matrices part from the rules for numbers: the order of the factors, the transposed product, A2, (A+B)2, number or matrix.
A has size 2×3, B size 3×2. AB: (2×3)⋅(3×2)=2×2. BA: (3×2)⋅(2×3)=3×3. Both products exist, but they are not even the same size.
Row 1 of A times column 1 of B: 1⋅3+(−1)(−6)+(−4)⋅2=3+6−8=1; times column 2: 1⋅4+(−1)(−8)+(−4)⋅3=4+8−12=0. Row 2: 0⋅3+1⋅(−6)+3⋅2=0 and 0⋅4+1⋅(−8)+3⋅3=1.
AB=(1001)=I2. True.
A single element does not need the whole product: row 2 of B times column 1 of A, (−6)⋅1+(−8)⋅0=−6. True.
BA=3−621−21001: row 2 is (−2) times row 1, and a 3×3 matrix with two proportional rows has determinant 0 (what the determinant and invertibility are, and that with determinant 0 there is no inverse, is explained in “The inverse matrix and the Leontief model”). True.
This is the rule the task is about: for matrices of different sizes, AB=I does not give BA=I. BA is not even invertible.
All three are true: option (c).
A second example of this kind is already above, in the section 'The order matters: AB and BA are different': on the dough matrices the statements AB=BA and (A+B)2=A2+2AB+B2 are refuted by calculating, one counterexample each.
Another task: check statement (c).a=120, b=214. Statements: (a) aTb=4; (b) abT is a number; (c) aTb=bTa. (a): 1⋅2+2⋅1+0⋅4=4, true. (b): (3×1)⋅(1×3)=3×3, a matrix, false. Check (c).
Your turn3 of 4
Given A=(1011) and B=(1101). Which statement is true?
Traps. The wrong options in tasks of this kind are most often these:
Choosing the false ones instead of the true ones, option (b) “none”: Check: write “true” or “false” at each number before choosing.
Swapped indices, option (a): for (2), row 1, column 2 computed, 3⋅(−1)+4⋅1=1 instead of −6. Check: row first, then column, both numbers written down before calculating.
One statement misjudged, options (d) and (e): (1), or (1) and (2), taken as false. Check: write every row-times-column sum with all its terms and their signs.
Transposing without reversing:(AB)T=BTAT, not ATBT.
A number instead of a matrix:abT is an n×n matrix, aTb a number.
Writing down the matrix of a quadratic form
In the statements the product was given and checked. In the last task it is the other way round: a function is given, and you write it as a product xTAx by finding the matrix:
Exam-style task
Die Kosten (in GE) eines Betriebs für die Mengen x1 und x2 zweier Produkte sind C(x1,x2)=−4x12+3x22+8x1x2. Mit welcher symmetrischen Matrix A lässt sich C(x1,x2) als xTAx mit x = (x1x2) schreiben?
a)(388−4)
b)(308−4)
c)(344−4)
d)(−4883)
e)(−4443)
The task gives itself away with the words “symmetric matrix” and the notation xTAx next to a function containing only squares of the variables and their products in pairs. Such a function is called a quadratic form.
Call the vector v and its numbers x and y; in the exam task above they were x1 and x2. Work out vTAv for v=(xy) and a symmetric A=(abbd): first Av, whose rows give a⋅x+b⋅y and b⋅x+d⋅y, then the row (xy) times that column:
The squares come only from cells (1,1) and (2,2): their coefficients go onto the diagonal unchanged. The mixed term xy comes twice, from the cell top right and bottom left, so each gets half of its coefficient.
x₁²: −4, x₂²: 3, x₁x₂: 8squares on the diagonalmixed ones split evenly: 4 into each cellcheck with ones: the sum of the cells matches the function value at the point (1, 1)
Step 1 of 4Read off the coefficients
x12 has −4, x22 has 3, x1x2 has 8. The order of the variables is set by x: row and column 1 belong to x1, 2 to x2. In the picture the cells still hold their names: aij in row i and column j.
a11=−4, a22=3. Options (a), (b) and (c) put them the other way round and are out.
a12=a21=8/2=4:
A==(−4443)
Written out: xTAx=a11x12+a12x1x2+a21x2x1+a22x22. With x1=x2=1 each term of xTAx equals its element, and xTAx is the sum of all elements: −4+4+4+3=7. The value of the function C(x1,x2)=−4x12+3x22+8x1x2 at the point (1,1): −4+3+8=7. It matches, option (e).
There are three variables. Which symmetric matrix A gives f(x,y,z)=2x2−y2+5z2+6xy−4xz+yz=vTAv for v=(x,y,z)T?
Squares: x2: 2, y2: −1, z2: 5. Mixed: xy: 6, xz: −4, yz: 1 (the term yz with no number).
a11=2, a22=−1, a33=5.
a12=a21=3, a13=a31=−2 (the sign stays), a23=a32=0.5:
A==23−23−10.5−20.55
Sum of the elements: 2+3−2+3−1+0.5−2+0.5+5=9. The function: f(1,1,1)=2−1+5+6−4+1=9. It matches.
Cells off the diagonal.f(x,y)=5x2−2y2−6xy. Diagonal: a11=5, a22=−2. Fill them in and check with ones.
Your turn4 of 4
Which symmetric matrix A gives q(x1,x2)=−2x12+7x22+6x1x2=xTAx with x=(x1,x2)T?
Traps. This is where the wrong options of the quadratic-form task come from:
The whole mixed coefficient in both cells, option (d). It is counted twice, and the check with ones gives 15 instead of 7.
The whole coefficient in one cell, 0 in the other, option (b), with the diagonal swapped as well. The check with ones lets it through, but the matrix is not symmetric.
Diagonal swapped, option (c): the coefficient of x22 stands where x12 belongs. Check: row 1 belongs to the first variable in x.
Losing the sign when halving: half of −4 is −2, not 2.
At a glance: rules, three methods and the formula sheet
The topic in a minute
Product:cij = row i of A times column j of B; (m×n)⋅(n×k)=m×k. Trap: comparing the outer sizes instead of the inner ones.
Order: in general AB=BA, and (A+B)2=A2+2AB+B2. Trap: working out BA instead of AB.
Transposing and powers:(AB)T=BTAT; AI=IA=A; A2=A⋅A; aTb is a number, abT a matrix. Trap: (AB)T=ATBT or squaring the elements.
One element of a product is asked for, the trace, the sum of a row, or an unknown from a given element. The element cij is built from row i of the left matrix and column j of the right one.
cij==ai1b1j++ai2b2j++⋯++ainbnj
Trap:taking a row of the right matrix or the neighbouring column; the row comes from the left matrix.
“Welche der folgenden Aussagen sind richtig?” (which of the following statements are true?) about matrices and vectors. Statements about the given matrices are settled by calculating, general rules by the rules; one counterexample refutes a false general rule.
(A⋅⋅B)T==BTAT
Trap:choosing the option with the numbers of the false statements, or carrying over the number rule AB=BA.
A function of squares and products of the variables in pairs, a symmetric A with f=xTAx is asked for. Squares on the diagonal, the mixed coefficient halved into both cells.
aij==aji==21⋅⋅coefficient of xixj
Trap:putting the whole mixed coefficient into both cells; the check with ones catches it.
The exam's formula sheet has no rules of matrix multiplication: of the matrix formulas it prints only the determinant and the inverse of a 2×2 matrix and the Leontief model. Everything in this article has to be known by heart.
When A has as many columns as B has rows: (m×n)⋅(n×k)=m×k.
Formula
(A⋅B)T=?
(A⋅B)T=?
BTAT: transposing reverses the order.
Formula
Two production stages with requirements matrices A (raw materials × intermediate products) and B (intermediate products × final products): total requirements and raw material needs for the plan p?
Two production stages with requirements matrices A (raw materials × intermediate products) and B (intermediate products × final products): total requirements and raw material needs for the plan p?
G=A⋅B with the intermediate stage on the inside, then r=G⋅p.