Multiplying Two Matrices, Row by Column
Adding two matrices is simple: you add the entries that sit in the same place. Multiplying two matrices works differently. Each ROW of the first matrix is combined with each COLUMN of the second matrix. You multiply the matching entries in pairs, first with first and second with second, and then add the products. That single number becomes one entry of the answer.
Take the matrices \( A = \begin{bmatrix} 3 & 4 \\ 5 & 6 \end{bmatrix} \) and \( B = \begin{bmatrix} 1 & -3 \\ -2 & -5 \end{bmatrix} \). Each has 2 rows and 2 columns, so each is of order \( 2 \times 2 \). The product of A and B is written AB, with the two matrices placed side by side:
\[ AB = \begin{bmatrix} 3 & 4 \\ 5 & 6 \end{bmatrix} \begin{bmatrix} 1 & -3 \\ -2 & -5 \end{bmatrix} \]
The answer will also be a \( 2 \times 2 \) matrix, so there are four entries to find. Each entry comes from one row of A and one column of B.
Step 1: First row of A times first column of B. The first row of A is 3, 4 and the first column of B is 1, \( -2 \). Multiplying first with first and second with second, then adding:
\[ 3 \times 1 + 4 \times (-2) = 3 - 8 = -5 \]
Step 2: First row of A times second column of B, which is \( -3 \), \( -5 \). This entry goes in row 1, column 2:
\[ 3 \times (-3) + 4 \times (-5) = -9 - 20 = -29 \]
Step 3: Second row of A, which is 5, 6, times first column of B. This entry goes in row 2, column 1:
\[ 5 \times 1 + 6 \times (-2) = 5 - 12 = -7 \]
Step 4: Second row of A times second column of B. This entry goes in row 2, column 2:
\[ 5 \times (-3) + 6 \times (-5) = -15 - 30 = -45 \]
Step 5: Placing the four entries in their positions:
\[ AB = \begin{bmatrix} -5 & -29 \\ -7 & -45 \end{bmatrix}_{2 \times 2} \]
Product of two matrices: In the product AB, the entry in row i and column j is found by multiplying the entries of row i of A by the matching entries of column j of B and adding the results. This is called row by column multiplication.
The position of an entry tells you where it comes from. Row 2, column 1 of AB always comes from row 2 of the first matrix and column 1 of the second matrix.
Is BA the Same as AB?
Now reverse the order and find BA. This time the rows of B are combined with the columns of A.
Step 1: Row 1 of B is 1, \( -3 \). Multiplying it by the first column of A, which is 3, 5:
\[ 1 \times 3 + (-3) \times 5 = 3 - 15 = -12 \]
Step 2: Row 1 of B times the second column of A, which is 4, 6:
\[ 1 \times 4 + (-3) \times 6 = 4 - 18 = -14 \]
Step 3: Row 2 of B is \( -2 \), \( -5 \). Multiplying it by the first column of A:
\[ (-2) \times 3 + (-5) \times 5 = -6 - 25 = -31 \]
Step 4: Row 2 of B times the second column of A:
\[ (-2) \times 4 + (-5) \times 6 = -8 - 30 = -38 \]
Step 5: Collecting the four entries:
\[ BA = \begin{bmatrix} -12 & -14 \\ -31 & -38 \end{bmatrix} \]
Compare this with \( AB = \begin{bmatrix} -5 & -29 \\ -7 & -45 \end{bmatrix} \). The two products are different. With ordinary numbers, \( 3 \times 4 \) and \( 4 \times 3 \) are always equal, but with matrices the order of multiplication can change the answer completely. So whenever you multiply matrices, keep careful track of which matrix comes first.
When Can Two Matrices Be Multiplied?
In AB, every row of A must be paired, entry by entry, with a column of B. A row of A has as many entries as A has columns. A column of B has as many entries as B has rows. If these two numbers are not the same, some entries are left without a partner and the product cannot be made.
Condition for multiplication: Two matrices A and B can be multiplied to give AB only when the number of columns of the first matrix A is equal to the number of rows of the second matrix B. Otherwise the multiplication is not possible.
When the condition holds, the order of the product is easy to predict. If A is of order \( m \times n \) and B is of order \( n \times p \), then AB is of order \( m \times p \). In symbols:
\[ A_{m \times n} \times B_{n \times p} = (AB)_{m \times p} \]
A quick way to use this rule: write the two orders side by side. The two numbers in the middle must be equal, and the two numbers on the outside give the order of the answer.
| First matrix | Second matrix | Middle numbers | Product |
| \( 2 \times 3 \) | \( 3 \times 2 \) | 3 and 3, equal | Possible, order \( 2 \times 2 \) |
| \( 3 \times 2 \) | \( 2 \times 3 \) | 2 and 2, equal | Possible, order \( 3 \times 3 \) |
| \( 1 \times 2 \) | \( 2 \times 1 \) | 2 and 2, equal | Possible, order \( 1 \times 1 \) |
| \( 3 \times 1 \) | \( 1 \times 3 \) | 1 and 1, equal | Possible, order \( 3 \times 3 \) |
| \( 2 \times 2 \) | \( 3 \times 2 \) | 2 and 3, not equal | Not possible |
Suppose A is \( m \times n \) and B is \( n \times p \), so AB can be found. Can BA be found as well? In BA the matrix B comes first. B has p columns and A has m rows, so BA exists only when \( p = m \). Even then, BA has order \( n \times n \), which may be different from the order \( m \times m \) of AB. So knowing that AB exists tells you nothing certain about BA.
Do not compare the rows of one matrix with the rows of the other. The check is always the columns of the FIRST matrix against the rows of the SECOND. Two matrices of order \( 2 \times 3 \) cannot be multiplied, even though they have exactly the same order.
Properties Related to Matrix Multiplication
Ordinary numbers obey several laws of multiplication. Three of these laws carry over to matrices, and one of them does not. Each law below is checked on actual matrices, so you can see it working instead of taking it on trust.
Commutative Property
Commutative property: For numbers, \( ab = ba \). For matrices this is NOT true in general. If A and B are two matrices, then usually \( AB \neq BA \).
You have already seen this happen. With \( A = \begin{bmatrix} 3 & 4 \\ 5 & 6 \end{bmatrix} \) and \( B = \begin{bmatrix} 1 & -3 \\ -2 & -5 \end{bmatrix} \), AB came out as \( \begin{bmatrix} -5 & -29 \\ -7 & -45 \end{bmatrix} \) while BA came out as \( \begin{bmatrix} -12 & -14 \\ -31 & -38 \end{bmatrix} \). A few special pairs, such as a square matrix and the identity matrix, do give AB equal to BA, but you can never assume it.
Associative Property
Associative property: If A, B and C are three matrices and the products (AB)C and A(BC) can be found, then \( (AB)C = A(BC) \). When three matrices are multiplied in a fixed order, it does not matter which pair is multiplied first.
Check it with \( A = \begin{bmatrix} 2 & 0 \\ 3 & 1 \end{bmatrix} \), \( B = \begin{bmatrix} 4 & -1 \\ -2 & 5 \end{bmatrix} \) and \( C = \begin{bmatrix} 1 & 3 \\ 6 & 0 \end{bmatrix} \). Each matrix below shows the products already worked out and waiting to be added. For example, the top left entry of AB is \( 2 \times 4 + 0 \times (-2) = 8 + 0 \).
Step 1: Multiplying A by B, row by column:
\[ \begin{aligned} AB &= \begin{bmatrix} 8 + 0 & -2 + 0 \\ 12 - 2 & -3 + 5 \end{bmatrix} \\ &= \begin{bmatrix} 8 & -2 \\ 10 & 2 \end{bmatrix} \end{aligned} \]
Step 2: Multiplying the result AB by C:
\[ \begin{aligned} (AB)C &= \begin{bmatrix} 8 - 12 & 24 + 0 \\ 10 + 12 & 30 + 0 \end{bmatrix} \\ &= \begin{bmatrix} -4 & 24 \\ 22 & 30 \end{bmatrix} \end{aligned} \]
Step 3: Now the other grouping. Multiplying B by C first:
\[ \begin{aligned} BC &= \begin{bmatrix} 4 - 6 & 12 - 0 \\ -2 + 30 & -6 + 0 \end{bmatrix} \\ &= \begin{bmatrix} -2 & 12 \\ 28 & -6 \end{bmatrix} \end{aligned} \]
Step 4: Multiplying A by the result BC:
\[ \begin{aligned} A(BC) &= \begin{bmatrix} -4 + 0 & 24 + 0 \\ -6 + 28 & 36 - 6 \end{bmatrix} \\ &= \begin{bmatrix} -4 & 24 \\ 22 & 30 \end{bmatrix} \end{aligned} \]
Steps 2 and 4 give the same matrix, so \( (AB)C = A(BC) \).
Distributive Property
Distributive property: If A, B and C are three matrices and A(B + C) and AB + AC can be found, then \( A(B + C) = AB + AC \). Multiplying a sum gives the same result as multiplying each part separately and then adding.
Check it with \( A = \begin{bmatrix} 1 & 2 \\ 0 & 3 \end{bmatrix} \), \( B = \begin{bmatrix} 1 & 4 \\ 2 & 5 \end{bmatrix} \) and \( C = \begin{bmatrix} -1 & -3 \\ 6 & 0 \end{bmatrix} \).
Step 1: Adding B and C, entry by entry:
\[ \begin{aligned} B + C &= \begin{bmatrix} 1 - 1 & 4 - 3 \\ 2 + 6 & 5 + 0 \end{bmatrix} \\ &= \begin{bmatrix} 0 & 1 \\ 8 & 5 \end{bmatrix} \end{aligned} \]
Step 2: Multiplying A by (B + C). The top left entry, for example, is \( 1 \times 0 + 2 \times 8 = 0 + 16 \):
\[ \begin{aligned} A(B + C) &= \begin{bmatrix} 0 + 16 & 1 + 10 \\ 0 + 24 & 0 + 15 \end{bmatrix} \\ &= \begin{bmatrix} 16 & 11 \\ 24 & 15 \end{bmatrix} \end{aligned} \]
Step 3: Multiplying A by B:
\[ \begin{aligned} AB &= \begin{bmatrix} 1 + 4 & 4 + 10 \\ 0 + 6 & 0 + 15 \end{bmatrix} \\ &= \begin{bmatrix} 5 & 14 \\ 6 & 15 \end{bmatrix} \end{aligned} \]
Step 4: Multiplying A by C:
\[ \begin{aligned} AC &= \begin{bmatrix} -1 + 12 & -3 + 0 \\ 0 + 18 & 0 + 0 \end{bmatrix} \\ &= \begin{bmatrix} 11 & -3 \\ 18 & 0 \end{bmatrix} \end{aligned} \]
Step 5: Adding AB and AC:
\[ \begin{aligned} AB + AC &= \begin{bmatrix} 5 + 11 & 14 - 3 \\ 6 + 18 & 15 + 0 \end{bmatrix} \\ &= \begin{bmatrix} 16 & 11 \\ 24 & 15 \end{bmatrix} \end{aligned} \]
Steps 2 and 5 give the same matrix, so \( A(B + C) = AB + AC \).
Identity Property
Identity property of matrix multiplication: If A is a square matrix and I is the identity matrix of the same order, then \( AI = IA = A \). Multiplying by I leaves a matrix unchanged, just as multiplying a number by 1 leaves the number unchanged.
The \( 2 \times 2 \) identity matrix is \( I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \), with 1 on the leading diagonal and 0 everywhere else. Take \( A = \begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix} \).
Step 1: Multiplying A by I. The top left entry is \( 2 \times 1 + 3 \times 0 = 2 + 0 \):
\[ \begin{aligned} AI &= \begin{bmatrix} 2 + 0 & 0 + 3 \\ 1 + 0 & 0 + 4 \end{bmatrix} \\ &= \begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix} = A \end{aligned} \]
Step 2: Multiplying I by A. The top left entry is \( 1 \times 2 + 0 \times 1 = 2 + 0 \):
\[ \begin{aligned} IA &= \begin{bmatrix} 2 + 0 & 3 + 0 \\ 0 + 1 & 0 + 4 \end{bmatrix} \\ &= \begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix} = A \end{aligned} \]
Both products give back A, so \( AI = IA = A \). This is one of the special cases in which changing the order does not change the answer. Here are the four properties side by side:
| Property | Statement | True for matrices? |
| Commutative | \( AB = BA \) | No, not in general |
| Associative | \( (AB)C = A(BC) \) | Yes, when the products exist |
| Distributive | \( A(B + C) = AB + AC \) | Yes, when the sum and products exist |
| Identity | \( AI = IA = A \) | Yes, for a square matrix A |
Example 1: Checking Whether AB and BA Are Defined
Let \( A = \begin{bmatrix} 2 & 4 & 0 \\ 3 & 5 & 1 \end{bmatrix} \) and \( B = \begin{bmatrix} -1 & 4 \\ 8 & 2 \\ 3 & 7 \end{bmatrix} \). Decide whether AB and BA are defined, giving a reason, and find each one that is.
A has 2 rows and 3 columns, so its order is \( 2 \times 3 \). B has 3 rows and 2 columns, so its order is \( 3 \times 2 \).
For AB: the number of columns of A is 3 and the number of rows of B is 3. They are equal, so AB is defined, and its order will be \( 2 \times 2 \).
\[ AB = \begin{bmatrix} 2 & 4 & 0 \\ 3 & 5 & 1 \end{bmatrix} \begin{bmatrix} -1 & 4 \\ 8 & 2 \\ 3 & 7 \end{bmatrix} \]
Step 1: Row 1 of A times column 1 of B. There are now three pairs to multiply before adding:
\[ \begin{aligned} & 2 \times (-1) + 4 \times 8 + 0 \times 3 \\ &= -2 + 32 + 0 = 30 \end{aligned} \]
Step 2: Row 1 of A times column 2 of B:
\[ \begin{aligned} & 2 \times 4 + 4 \times 2 + 0 \times 7 \\ &= 8 + 8 + 0 = 16 \end{aligned} \]
Step 3: Row 2 of A times column 1 of B:
\[ \begin{aligned} & 3 \times (-1) + 5 \times 8 + 1 \times 3 \\ &= -3 + 40 + 3 = 40 \end{aligned} \]
Step 4: Row 2 of A times column 2 of B:
\[ \begin{aligned} & 3 \times 4 + 5 \times 2 + 1 \times 7 \\ &= 12 + 10 + 7 = 29 \end{aligned} \]
Step 5: Placing the entries:
\[ AB = \begin{bmatrix} 30 & 16 \\ 40 & 29 \end{bmatrix} \]
For BA: the number of columns of B is 2 and the number of rows of A is 2. They are equal, so BA is also defined. Its order will be \( 3 \times 3 \), so there are nine entries to find.
\[ BA = \begin{bmatrix} -1 & 4 \\ 8 & 2 \\ 3 & 7 \end{bmatrix} \begin{bmatrix} 2 & 4 & 0 \\ 3 & 5 & 1 \end{bmatrix} \]
Step 1: Row 1 of B is \( -1 \), 4. Multiplying it by each of the three columns of A gives the first row of BA:
\[ \begin{aligned} (-1) \times 2 + 4 \times 3 &= 10 \\ (-1) \times 4 + 4 \times 5 &= 16 \\ (-1) \times 0 + 4 \times 1 &= 4 \end{aligned} \]
Step 2: Row 2 of B is 8, 2. Multiplying it by the three columns of A gives the second row:
\[ \begin{aligned} 8 \times 2 + 2 \times 3 &= 22 \\ 8 \times 4 + 2 \times 5 &= 42 \\ 8 \times 0 + 2 \times 1 &= 2 \end{aligned} \]
Step 3: Row 3 of B is 3, 7. Multiplying it by the three columns of A gives the third row:
\[ \begin{aligned} 3 \times 2 + 7 \times 3 &= 27 \\ 3 \times 4 + 7 \times 5 &= 47 \\ 3 \times 0 + 7 \times 1 &= 7 \end{aligned} \]
Step 4: Writing the three rows together:
\[ BA = \begin{bmatrix} 10 & 16 & 4 \\ 22 & 42 & 2 \\ 27 & 47 & 7 \end{bmatrix} \]
AB is a \( 2 \times 2 \) matrix while BA is a \( 3 \times 3 \) matrix. Both products exist, yet they are not even the same size, which is the clearest possible sign that AB and BA are different.
Example 2: Squaring a Matrix
If \( A = \begin{bmatrix} 4 & 1 \\ -1 & 2 \end{bmatrix} \), prove that \( A^2 - 6A + 9I = O \), where I and O are the identity matrix and the zero matrix of order \( 2 \times 2 \).
Square of a matrix: For a square matrix A, \( A^2 \) means \( A \times A \), the matrix A multiplied by itself, row by column. Only a square matrix can be squared, because an \( m \times n \) matrix can be multiplied by itself only when \( m = n \).
\( A^2 \) is not found by squaring each entry of A. Squaring the entries of this A would give \( \begin{bmatrix} 16 & 1 \\ 1 & 4 \end{bmatrix} \), which is wrong. Multiply A by A, row by column.
Here \( I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \) and \( O = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix} \).
Step 1: Finding \( A^2 \) by multiplying A by A. The top left entry is \( 4 \times 4 + 1 \times (-1) = 16 - 1 \), and the others are found the same way:
\[ \begin{aligned} A^2 &= \begin{bmatrix} 16 - 1 & 4 + 2 \\ -4 - 2 & -1 + 4 \end{bmatrix} \\ &= \begin{bmatrix} 15 & 6 \\ -6 & 3 \end{bmatrix} \end{aligned} \]
Step 2: Multiplying A by the number 6, which multiplies every entry by 6:
\[ 6A = \begin{bmatrix} 24 & 6 \\ -6 & 12 \end{bmatrix} \]
Step 3: Multiplying I by the number 9:
\[ 9I = \begin{bmatrix} 9 & 0 \\ 0 & 9 \end{bmatrix} \]
Step 4: Putting these into the left hand side and combining the entries in each position:
\[ \begin{aligned} & A^2 - 6A + 9I \\ &= \begin{bmatrix} 15 - 24 + 9 & 6 - 6 + 0 \\ -6 + 6 + 0 & 3 - 12 + 9 \end{bmatrix} \\ &= \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix} = O \end{aligned} \]
The left hand side equals O, which is the right hand side. Hence \( A^2 - 6A + 9I = O \) is proved.
Example 3: Finding Unknown Entries
If \( A = \begin{bmatrix} 4 & 0 \\ 0 & 5 \end{bmatrix} \), \( B = \begin{bmatrix} p & q \\ 0 & r \end{bmatrix} \) and \( AB = A + B \), find the values of p, q and r.
The plan is to work out each side as a single matrix. Two equal matrices have equal entries in the same positions, so matching entries give simple equations.
Step 1: Finding AB, row by column. The top left entry is \( 4 \times p + 0 \times 0 = 4p + 0 \):
\[ \begin{aligned} AB &= \begin{bmatrix} 4p + 0 & 4q + 0 \\ 0 + 0 & 0 + 5r \end{bmatrix} \\ &= \begin{bmatrix} 4p & 4q \\ 0 & 5r \end{bmatrix} \end{aligned} \]
Step 2: Finding A + B by adding the entries in the same positions:
\[ A + B = \begin{bmatrix} 4 + p & q \\ 0 & 5 + r \end{bmatrix} \]
Step 3: Since AB = A + B, the two matrices are equal:
\[ \begin{bmatrix} 4p & 4q \\ 0 & 5r \end{bmatrix} = \begin{bmatrix} 4 + p & q \\ 0 & 5 + r \end{bmatrix} \]
Step 4: Equating the entries in row 1, column 1 and solving for p:
\[ \begin{aligned} 4p &= 4 + p \\ 3p &= 4 \\ p &= \frac{4}{3} \end{aligned} \]
Step 5: Equating the entries in row 1, column 2 and solving for q:
\[ \begin{aligned} 4q &= q \\ 3q &= 0 \\ q &= 0 \end{aligned} \]
Step 6: Equating the entries in row 2, column 2 and solving for r:
\[ \begin{aligned} 5r &= 5 + r \\ 4r &= 5 \\ r &= \frac{5}{4} \end{aligned} \]
Hence \( p = \frac{4}{3} \), \( q = 0 \) and \( r = \frac{5}{4} \).
Example 4: Transpose of a Product
If \( A = \begin{bmatrix} 1 & 2 \\ 0 & 9 \end{bmatrix} \) and \( B = \begin{bmatrix} 3 & 4 \\ 2 & 1 \end{bmatrix} \), prove that \( (AB)^T = B^T.A^T \).
Transpose of a product: For two matrices A and B whose product AB exists, \( (AB)^T = B^T.A^T \). The transpose of a product is the product of the transposes taken in the REVERSE order.
Step 1: Finding AB. The top left entry is \( 1 \times 3 + 2 \times 2 = 3 + 4 \):
\[ \begin{aligned} AB &= \begin{bmatrix} 3 + 4 & 4 + 2 \\ 0 + 18 & 0 + 9 \end{bmatrix} \\ &= \begin{bmatrix} 7 & 6 \\ 18 & 9 \end{bmatrix} \end{aligned} \]
Step 2: Taking the transpose of AB, which turns its rows into columns. Call this result (i):
\[ (AB)^T = \begin{bmatrix} 7 & 18 \\ 6 & 9 \end{bmatrix} \]
Step 3: Finding the transpose of A:
\[ A^T = \begin{bmatrix} 1 & 0 \\ 2 & 9 \end{bmatrix} \]
Step 4: Finding the transpose of B:
\[ B^T = \begin{bmatrix} 3 & 2 \\ 4 & 1 \end{bmatrix} \]
Step 5: Multiplying \( B^T \) by \( A^T \), in that order. The top left entry is \( 3 \times 1 + 2 \times 2 = 3 + 4 \). Call this result (ii):
\[ \begin{aligned} B^T.A^T &= \begin{bmatrix} 3 + 4 & 0 + 18 \\ 4 + 2 & 0 + 9 \end{bmatrix} \\ &= \begin{bmatrix} 7 & 18 \\ 6 & 9 \end{bmatrix} \end{aligned} \]
Results (i) and (ii) are the same matrix. Hence \( (AB)^T = B^T.A^T \) is proved.
\( (AB)^T \) is not \( A^T.B^T \) in general. With the matrices above, \( A^T.B^T = \begin{bmatrix} 3 & 2 \\ 42 & 13 \end{bmatrix} \), which is not equal to \( (AB)^T \). The order of the two transposes must be reversed.
The full lesson is waiting for you
The notes are free to read in full. A free account opens the rest of the practice, and tracks your progress and confidence score for every subject. Presentations and videos need approval from Learn Yeti.