Check the inner dimensions before multiplying two matrices
Decide whether AB exists by comparing the columns of A with the rows of B. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.
Two matrices multiply only when the columns of the first equal the rows of the second:
Write the sizes side by side and cancel the middle. The inner pair has to match, and the outer pair survives.
Why: every entry of is one row of dotted with one column of. A dot product pairs up two lists entry by entry, so the two lists must be the same length. A row of has entries and a column of has entries — the same, or there is nothing to pair.
That appears nowhere in the answer. It is consumed by the multiplications each entry needs.
Look at what the product does to a vector. If is and is, then eats a-vector and produces an-vector, and then eats that-vector and produces an-vector. The composition goes from entries to entries, so the combined matrix is.
The intermediate is the thing that has to match:'s output length must equal's input length, or the chaining is meaningless. That is the inner pair.
This is also why the answer keeps the outer pair: the composition starts where starts (width) and ends where ends (height).
Question. is, is, is. Which of,,, exist, and what are their sizes?
Step 1 —.: inner pair and, they match, so it exists and is.
Step 2 —.: inner pair and, exists,.
Step 3 —.: inner pair and, do not match, so does not exist.
Step 4 —. Do it in two steps. With first: is, and, exists. With first: is, and, also exists. Both routes give the same matrix, which is associativity.
Answer. is, is, does not exist, is.
- Decide whether AB exists by comparing the columns of A with the rows of B
- Predict the size of AB as the outer pair of dimensions
- Explain why the inner number disappears from the answer
- Notice that AB can exist while BA does not
is, is, is. Which of,,, exist, and what are their sizes?
Answer
- -: ✓
- -: ✓
- -: — inner pair and, does not exist ✗
- -: take first, which is, then ✓
Notice that fails while succeeds. There is no rule that says a sub-product of an existing product must itself exist — the grouping matters.