Exercise 2: A Rectangular Matrix Times a Column Vector — Possible Solution ==================================================================== GIVEN ------------------------------ J = [[1, 0, 2], [3, 1, 1]] (a 2x3 matrix) K = [[2], [1], [4]] (a 3x1 matrix - a column vector) STEP 1: CHECKING THE DIMENSION RULE FOR J x K ------------------------------ J is 2x3 (2 rows, 3 columns). K is 3x1 (3 rows, 1 column). J's number of columns (3) matches K's number of rows (3), so J x K is defined, and per this chapter's own dimension rule the result will be a 2x1 matrix (J's row count x K's column count). STEP 2: COMPUTING J x K ------------------------------ Row 0: (1)(2) + (0)(1) + (2)(4) = 2 + 0 + 8 = 10 Row 1: (3)(2) + (1)(1) + (1)(4) = 6 + 1 + 4 = 11 J x K = [[10], [11]] — a 2x1 matrix, as predicted. STEP 3: WHY K x J IS NOT DEFINED ------------------------------ For K x J, K's number of columns must match J's number of rows. K is 3x1, so its number of columns is 1. J is 2x3, so its number of rows is 2. Since 1 does not equal 2, this chapter's own dimension rule is violated - there's no way to take a "row of K, column of J" dot product, because K's rows only have 1 entry each while J's columns have 2 entries each; the dot product itself would be undefined term by term. K x J is simply not a valid operation for these two shapes. WHY THIS WORKS AS AN ANSWER ------------------------------ It checks the dimension rule explicitly before computing anything, carries out J x K entry by entry to confirm the predicted 2x1 shape, and explains K x J's invalidity by pointing to the specific mismatched numbers (K's 1 column vs. J's 2 rows) rather than simply asserting that the order "doesn't work."