14.3 KB · commit a9602da
Matrices are used throughout discrete mathematics to express relationships between elements in sets. In subsequent chapters we will use matrices in a wide variety of models. For instance, matrices will be used in models of communications networks and transportation systems. Many algorithms will be developed that use these matrix models. This section reviews matrix arithmetic that will be used in these algorithms.
The matrix 101123 is a 3×2 matrix. ◀
We now introduce some terminology about matrices. Boldface uppercase letters will be used to represent matrices.
The basic operations of matrix arithmetic will now be discussed, beginning with a definition of matrix addition.
The sum of two matrices of the same size is obtained by adding elements in the corresponding positions. Matrices of different sizes cannot be added, because the sum of two matrices is defined only when both matrices have the same number of rows and the same number of columns.
We have 123024−1−30+31−14−31−102=4324−15−2−32. ◀
We now discuss matrix products. A product of two matrices is defined only when the number of columns in the first matrix equals the number of rows of the second matrix.
In Figure 1 the colored row of A and the colored column of B are used to compute the element cij of AB. The product of two matrices is not defined when the number of columns in the first matrix and the number of rows in the second matrix are not the same.
![]() |
|---|
| FIGURE 1 — The Product of A=[aij] and B=[bij] (Source: Page 179) |
We now give some examples of matrix products.
Let A=123001124102andB=213410. Find AB if it is defined.
Solution: Because A is a 4×3 matrix and B is a 3×2 matrix, the product AB is defined and is a 4×2 matrix. To find the elements of AB, the corresponding elements of the rows of A and the columns of B are first multiplied and then these products are added. For instance, the element in the (3,1)th position of AB is the sum of the products of the corresponding elements of the third row of A and the first column of B; namely, 3⋅2+1⋅1+0⋅3=7. When all the elements of AB are computed, we see that AB=1487849132. ◀
Matrix multiplication is not commutative. That is, if A and B are two matrices, it is not necessarily true that AB and BA are the same. In fact, it may be that only one of these two products is defined. For instance, if A is 2×3 and B is 3×4, then AB is defined and is 2×4; however, BA is not defined, because it is impossible to multiply a 3×4 matrix and a 2×3 matrix.
In general, suppose that A is an m×n matrix and B is an r×s matrix. Then AB is defined only when n=r and BA is defined only when s=m. Moreover, even when AB and BA are
both defined, they will not be the same size unless m=n=r=s. Hence, if both AB and BA are defined and are the same size, then both A and B must be square and of the same size. Furthermore, even with A and B both n×n matrices, AB and BA are not necessarily equal, as Example 4 demonstrates.
Let A=[1211]andB=[2111]. Does AB=BA?
Solution: We find that AB=[3523]andBA=[4332]. Hence, AB=BA. ◀
We now introduce an important matrix with entries that are zeros and ones.
Multiplying a matrix by an appropriately sized identity matrix does not change this matrix. In other words, when A is an m×n matrix, we have AIn=ImA=A.
Powers of square matrices can be defined. When A is an n×n matrix, we have A0=In, Ar=r timesAAA⋯A.
The operation of interchanging the rows and columns of a square matrix arises in many contexts.
The transpose of the matrix [142536] is the matrix 123456. ◀
Matrices that do not change when their rows and columns are interchanged are often important.
Note that a matrix is symmetric if and only if it is square and it is symmetric with respect to its main diagonal (which consists of entries that are in the ith row and ith column for some i). This symmetry is displayed in Figure 2.
The matrix 110101010 is symmetric. ◀
![]() |
|---|
| FIGURE 2 — A Symmetric Matrix (Source: Page 181) |
A matrix all of whose entries are either 0 or 1 is called a zero–one matrix. Zero–one matrices are often used to represent discrete structures, as we will see in Chapters 9 and 10. Algorithms using these structures are based on Boolean arithmetic with zero–one matrices. This arithmetic is based on the Boolean operations ∧ and ∨, which operate on pairs of bits, defined by b1∧b2={10if b1=b2=1otherwise, b1∨b2={10if b1=1 or b2=1otherwise.
Find the join and meet of the zero–one matrices A=[100110],B=[011100].
Solution: We find that the join of A and B is A∨B=[1∨00∨10∨11∨11∨00∨0]=[111110]. The meet of A and B is A∧B=[1∧00∧10∧11∧11∧00∧0]=[000100]. ◀
We now define the Boolean product of two matrices.
Note that the Boolean product of A and B is obtained in an analogous way to the ordinary product of these matrices, but with addition replaced with the operation ∨ and with multiplication replaced with the operation ∧. We give an example of the Boolean products of matrices.
Find the Boolean product of A and B, where A=101010,B=[101101].
Solution: The Boolean product A⊙B is given by A⊙B=(1∧1)∨(0∧0)(0∧1)∨(1∧0)(1∧1)∨(0∧0)(1∧1)∨(0∧1)(0∧1)∨(1∧1)(1∧1)∨(0∧1)(1∧0)∨(0∧1)(0∧0)∨(1∧1)(1∧0)∨(0∧1)=1∨00∨01∨01∨00∨11∨00∨00∨10∨0=101111010. ◀
We can also define the Boolean powers of a square zero–one matrix. These powers will be used in our subsequent studies of paths in graphs, which are used to model such things as communications paths in computer networks.
Let A=011001100. Find A[n] for all positive integers n.
Solution: We find that A[2]=A⊙A=101100011. We also find that A[3]=A[2]⊙A=111011101, A[4]=A[3]⊙A=111101111. Additional computation shows that A[5]=111111111. The reader can now see that A[n]=A[5] for all positive integers n with n≥5. ◀