CS100: DISCRETE STRUCTURES Lecture 3 Matrices Ch 3 Pages: 246-262
Matrices 2 Introduction DEFINITION 1: A matrix is a rectangular array of numbers. A matrix with m rows and n columns is called an m x n matrix. The plural of matrix is matrices. A matrix with the same number of rows as columns is called square. Two matrices are equals if they have the same number of rows and the same number of columns and the corresponding entries in every position are equal. Example: The matrix é1 0 ë 1 1ù 2 3û is a 3 x 2 matrix.
Matrices 3 DEFINITION 2:
Example 1 4 Then A is.with a 12 =. and a 23 =, B is with b 21 =, C is., D is, and E is. ANS: Then A is 2*3 with a 12 = 3 and a 23 =2, B is 2*2 with b 21 =4, C is 1*4, D is 3*1, and E is 3*3
Exercise 5 Let 1) What size is A? 3 4 2) What is the third column of A? 3) What is the second row of A? 4) What is the element of A in the (3,2) th position? A(3,2)=1
Diagonal Matrix 6 A square matrix A = [a ij ] for which every entry off the main diagonal is zero, that is, a ij = 0 for i j, is called a diagonal matrix Example :
Identity Matrix 7 The n x n diagonal matrix all of whose diagonal elements are 1, is called the identity matrix of order n. Multiplying a matrix by an appropriately sized identity matrix does not change this matrix. In other words, when A is an m x n matrix, we have AI n = I m A = A Powers of square matrices can be defined. When A is a n n x n matrix, we have A 0 = I n, A r = AAAA A (r times)
Example of Matrix applications 8 v Matrices are used in many applications in computer science, and we shall see them in our study of relations and graphs. v At this point, we present the following simple application showing how matrices can be used to display data in a tabular form
Cont d 9 The following matrix gives the airline distance between the cities indicated
Equal Matrices 10 DEFINITION 2: Two m x n matrices A = [a ij ] and B = [b ij ] are said to be equal if a ij = b ij, 1 i m, 1 j n; that is, if corresponding elements are the same. Notice how easy it is to state the definition using generic elements a ij, b ij Two matrices are equal if : they have the same dimension or order and the corresponding elements are identical.
Cont d 11 Then A = B if and only if X=-3, y=0, and z=6
Matrices 12 Matrix Arithmetic DEFINITION 3: Let A = [a ij ] and B = [b ij ] be m x n matrices. The sum of A and B, denoted by A + B, is the m x n matrix that has a ij + b ij as its (i,j) th element. In other words, A + B = [a ij + b ij ]. v The sum of two matrices of the same size is obtained by adding elements in the corresponding positions. v Matrices of different sizes can t be added.
Example 1 = û ù ë é - - - + û ù ë é - - 2 1 1 0 3 1 1 4 3 0 4 3 3 2 2 1 0 1 Example 2 13 û ù ë é - - - 2 5 2 3 1 3 2 4 4
Zero Matrix 14 v A matrix all of whose entries are zero is called a zero matrix and is denoted by 0 v Each of the following is Zero matrix
Properties of Matrix Addition 15 v A + B = B + A v (A + B) + C = A + (B + C) v A + 0 = 0 + A = A
Matrices Production 16 DEFINITION 4: Let A be an m x k matrix and B be a k x n matrix. The product of A and B, denoted by AB, is the m x n matrix with its (i,j) th entry equal to the sum of the products of the corresponding elements from the i th row of A and the i th column of B. In other words, if AB = [c ij ], then c ij = a i1 b 1j + a i2 b 2j + + ai k b kj.
Matrices Production 17 The product of the two matrices is not defined when the number of columns in the first matrix and the number of rows in the second matrix is not the same.
18 Matrices Production
19 AB=
Matrices Production Example: Let A 4X3 = and B 3X2 = Find AB if it is defined. AB = û ù ë é 2 2 0 0 1 3 1 1 2 4 0 1 û ù ë é 0 3 1 1 4 2 20 û ù ë é 2 8 13 7 9 8 4 14
Exercise 21 Consider the matrices A=,C=,B= Find the following: 2A= 4A + B = A+0=
Matrices Production 22 DEFINITION 5: If A and B are two matrices, it is not necessarily true that AB and BA are the same. E.g. if A is 2 x 3 and B is 3 x 4, then AB is defined and is 2 x 4, but BA is not defined. Even when A and B are both n x n matrices, AB and BA are not necessarily equal. Example: é1 1ù Let A 2x2 = and B 2x2 = ë2 1û Does AB = BA? Solution: é3 2ù AB = and BA = ë5 3û é4 ë3 3ù 2 û é2 ë1 1ù 1 û
Properties of Multiplication 23 If A = m x p matrix, and B is a p x n matrix, then AB can be computed and is an m x n matrix. As for BA, we have four different possibilities: 1. BA may not be defined; we may have n m For Example : A=4x5, B=5x6 2. BA may be defined if n = m, and then BA is p x p, while AB is m x m and p m. Thus AB and BA are not equal For Example : A=4x5, B=5x4 3. AB and BA may both the same size, but not equal as matrices AB BA 4. AB = BA For Example : A=4x4, B=4x4
Basic Properties of Multiplication 24 The basic properties of matrix multiplication are given by the following theorem: a. A(BC) = (AB)C b. A(B + C)= AB + AC c. (A + B)C = AC + BC
Transpose Matrices 25 DEFINITION 6: Let A = [a ij ] be an m x n matrix. The transpose of A, denoted by A t, is the n x m matrix obtained by interchanging the rows and columns of A. In other words, if At = [b ij ], then b ij = a ji, for i = 1,2,,n and j = 1,2,,m. Example: The transpose of the matrix é1 ë4 2 5 3ù 6 û is the matrix é1 2 ë 3 4ù 5 6û
Properties for Transpose 26 If A and B are matrices, then 1. A % % = A 2. (A + B) % = A % + B % 3. (AB) % = B % A %
Exercises = = = 27 Consider the matrices : A=,B=,C= Find the following: C % (A + B) % 1 2 5 3 4 2 1 1 4 0 3 2 2 2 3 + 6 4 3 8 2 1 5 7 2 = 5 5 7 8 1 3 7 5 5
Symmetric Matrices 28 DEFINITION 7: A square matrix A is called symmetric if A = A t. Thus A = [a ij ] is symmetric if a ij = a ji for all i and j with 1 i n and 1 j n. Example: The matrix é1 1 ë 0 1 0 1 0ù 1 0û is symmetric. Example
29 The Transpose of a Symmetric Matrix
Boolean Matrix Operation 30 A Boolean matrix is an m x n matrix whose entries are either zero or one. Example: 1 0 1 0 0 1 1 1 0
Boolean Matrix Operations (join) 31 v Let A = [a ij ] and B = [b ij ] be m x n Boolean matrices. v We define A v B = C = [ C ij ], the join of A and B, by 1 if a ij =1 or b ij = 1 C ij = 0 if a ij and b ij are both 0
Example 32 Find the join of A and B: 1 0 1 A = 0 1 0 B = 0 1 0 1 1 0 A v B = 1v0 0v1 1v0 0v1 1v1 0v0 = 1 1 1 1 1 0
Boolean Matrix Operations (Meet) 33 v We define A ^ B = C = [ C ij ], the meet of A and B, by 1 if a ij and b ij are both 1 C ij = 0 if a ij = 0 or b ij = 0 v Meet & Join are the same as the addition procedure each element with the corresponding element in the other matrix Matrices have the same size
Example 34 Find the meet of A and B: A = 1 0 1 B = 0 1 0 0 1 0 1 1 0 A ^ B = 1^0 0^1 1^0 0^1 1^1 0^0 = 0 0 0 0 1 0
Boolean PRODUCT 35 The Boolean product of A and B, denoted, A B is the m x n Boolean matrix defined by Procedure: C ij = < 1, if a ik = 1 and bkj = 1 for some k,1 k p 0, Otherwise 1. Select row i of A and column j of B, and arrange them side by side. 2. Compare corresponding entries. If even a single pair of corresponding entries consists of two 1 s, then C ij = 1, otherwise C ij = 0
Example 36 Find the Boolean product of A and B: A B 3x3 = = 1 0 0 1 1 0 A 3x2 = B 2x3 = 1 1 0 0 1 1 (1 ^ 1) v (0 ^ 0) (1 ^ 1) v (0 ^ 1) (1 ^ 0) v (0 ^ 1) (0 ^ 1) v (1 ^ 0) (0 ^ 1) v (1 ^ 1) (0 ^ 0) v (1 ^ 1) (1 ^ 1) v (0 ^ 0) (1 ^ 1) v (0 ^ 1) (1 ^ 0) v (0 ^ 1) 1 1 0 0 1 1 1 1 0
Boolean Operations Properties 37 If A, B, and C are Boolean Matrices with the same sizes, then 1. A v B = B v A 2. A ^ B = B ^ A 3. (A v B) v C = A v (B v C) 4. (A ^ B) ^ C = A ^ (B ^ C)
= Exercises = 38 Find meet and join for A and B: Solution : Meet of A and B = join of A and B =
Find = Exercises = 39 Find A B Solution: A B =
Any Question 40 Refer to chapter 3 of the book for further reading