The product AB is the map you get by applying B first and then A: (AB)x=A(Bx). Entry (i,j) of the product is row i of A dotted with column j of B, so the shapes must fit: an m×n matrix times an n×p matrix gives an m×p matrix. The product is associative, (AB)C=A(BC), and it distributes over sums, but in general it is not commutative: AB=BA because the order of two actions matters.
(AB)ij=k=1∑nAikBkj,(AB)T=BTAT(1)
Computing AB for an m×n and an n×p matrix takes mnp multiply-adds (about 2mnp floating-point operations). For two n×n matrices that is n3, so doubling n makes the work eight times larger. A matrix times a vector costs only n2. Because the product is associative, the order of the brackets does not change the answer but can change the cost enormously.
Order matters, twiceWith A=(1021) and B=(0110): AB=(2110) but BA=(0112), so the order changes the answer. Brackets change the cost: for n×n matrices A,B and a vector v, (AB)v costs n3+n2 multiply-adds while A(Bv) costs 2n2. For n=1000 that is a thousand million against two million.
Shape rule: (m×n)(n×p)=(m×p); the inner sizes must match.
Not commutative: AB=BA in general, so never swap factors.
Cost: mnp multiply-adds; matrix times vector is n2, matrix times matrix is n3.
Bracket your products from the vector side
When a chain of matrices ends in a vector, multiply from the vector side: A(B(Cv)) uses only matrix-vector products. Portfolio risk wTΣw is computed as w⋅(Σw), never by first forming a matrix from w.
Lab · what's graded
6 tasks · 100 pts
The product AB20 pts
The product BA15 pts
The shape of a product10 pts
Counting multiply-adds15 pts
Two ways to bracket20 pts
Why the bracketing matters20 pts
0/ 6 answered
1Matrix · vector20 ptsNot answered
Let A=(1021) and B=(0110). Fill in AB.
AB=
2Matrix · vector15 ptsNot answered
Let A=(1021) and B=(0110). Fill in BA and notice that it differs from AB.
BA=
3Choice10 ptsNot answered
P is 3×4 and Q is 4×2. What is the shape of PQ?
4Numeric answer15 ptsNot answered
How many multiply-adds does it take to multiply a 200×300 matrix by a 300×100 matrix?
[objectObject]=accepted: ± 0.1%
5Numeric answer20 ptsNot answered
A and B are 1000×1000 and v has 1000 entries. How many times more multiply-adds does (AB)v need than A(Bv)? Use n3+n2 against 2n2.
[objectObject]=accepted: ± 1
6Explain in words20 ptsNot answered
In two sentences, say why you should compute A(Bv) rather than (AB)v, and whether the answers differ.
Math modeKeyboard or LaTeX inputTask 1 of 6 · Ctrl ⏎ to check