4) Matrices Multiplication
Two matrices (A
) can be multiplied if they are compatible, meaning that the first (left) matrix has as many columns as the second (right) matrix has rows. If matrices A
meet this condition, you can multiply them. The result of such a multiplication will be matrix C
, which has as many rows as matrix A
and as many columns as matrix B
Amxn ∙Bnxp = Cmxp
The rules for matrices multiplication are not as trivial as for scalar matrix multiplication. To calculate the ij-element of the product matrix, you need to multiply the ith row vector of the first matrix by the jth column vector of the second matrix. The multiplication of a row vector by a column vector goes as follows:
1. Multiply the first elements of the row and column vectors to get product 1.
2. Multiply the second elements of the row and column vectors to get product 2.
. . . . . . . . . . . . .
N. Multiply the Ns elements of the row and column vectors to get product N.
Lastly, sum up all the products.
The result of such a calculation will be a scalar.
Figure 2 shows the algorithm in math notation for Amxn ∙Bnxp = Cmxp (where i = 1, 2, . . m, and j =1, 2, . . p.).
|Figure 2. Calculating ij-element of Product Matrix C:|
Here is the algorithm in math notation for Amxn ∙Bnxp = Cmxp.
To find product C = A ∙ B, where:
You would use this solution:
Matrices multiplication is not commutative (i.e., A∙B ≠ B∙A). Indeed, in Example 4, the multiplication A3x2 ∙ B2x4 is allowed, because matrices A3x2 and B2x4 are compatible. However, the multiplication B2x4 ∙ A3x2 would be illegal, because the number of columns in the left matrix is not equal to the number of rows in the right matrix. But even if both A∙B and B∙A are compatible, that doesn’t guarantee the same result.
Consider two square matrices:
However, matrices multiplication is associative and distributive:
- associative - A∙(B∙C) = (A∙B)∙C
- distributive - A∙(B + C) = A∙B + A∙C
- distributive - (A + B)C = A∙C + B∙C
5) Matrix Transpose
The transposing of a matrix simply means an exchange between the rows and the columns. Suppose you have an m x n matrix, Amxn. If you transpose that matrix, you will get an n x m matrix, Bnxm, with the following correspondence between the elements of A and B:
aixj = bjxi, for all i and j.
The most common notation for the transposing of matrix A is AT.
Find the transpose of a matrix A as follows: