Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS100: Discrete structures

Similar presentations


Presentation on theme: "CS100: Discrete structures"— Presentation transcript:

1 CS100: Discrete structures
Computer Science Department Lecture 5 - Matrices

2 Matrices 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 is a 3 x 2 matrix. 18-Jan-19 Computer Science Department

3 Matrices DEFINITION 2: 18-Jan-19 Computer Science Department

4 Example 1 Then A is 2 x 3 with a12 = 3 and a23 = 2, B is 2 x 2 with b21 = 4, C is 1 x 4, D is 3 x 1, and E is 3 x 3 ? ? ? ? ? ? ? ? 18-Jan-19 Computer Science Department

5 Exercise 3×4 Let What size is A ? What is the third column of A ?
What is the second row of A ? What is the element of A in the (3,2)th position ? 3×4 A(3,2)=1 18-Jan-19 Computer Science Department

6 Diagonal Matrix Example :
A square matrix A = [aij ] for which every entry off the main diagonal is zero, that is, aij = 0 for i ≠ j, is called a diagonal matrix Example : 18-Jan-19 Computer Science Department

7 Identity Matrix 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 AIn= ImA = A Powers of square matrices can be defined. When A is an n x n matrix, we have A0 = In , Ar = AAAA…A (r times) 18-Jan-19 Computer Science Department

8 Example of Matrix applications
Matrices are used in many applications in computer science, and we shall see them in our study of relations and graphs. At this point, we present the following simple application showing how matrices can be used to display data in a tabular form 18-Jan-19 Computer Science Department

9 Cont’d The following matrix gives the airline distance between the cities indicated 18-Jan-19 Computer Science Department

10 Equal Matrices if aij = bij , DEFINITION 2:
Two m x n matrices A = [aij ] and B = [bij] are said to be equal if aij = bij , 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 aij , bij Two matrices are equal if they have the same dimension or order and the corresponding elements are identical. 18-Jan-19 Computer Science Department

11 Then A = B if and only if X=-3, y=0, and z=6
Cont’d Then A = B if and only if X=-3, y=0, and z=6 18-Jan-19 Computer Science Department

12 Matrices Matrix Arithmetic
DEFINITION 3: Let A = [aij] and B = [bij] be m x n matrices. The sum of A and B, denoted by A + B, is the m x n matrix that has aij + bij as its (i,j)th element. In other words, A + B = [aij + bij]. The sum of two matrices of the same size is obtained by adding elements in the corresponding positions. Matrices of different sizes can’t be added. 18-Jan-19 Computer Science Department

13 Example 1 Example 2 18-Jan-19 Computer Science Department

14 Zero Matrix A matrix all of whose entries are zero is called a zero matrix and is denoted by 0 Each of the following is Zero matrix 18-Jan-19 Computer Science Department

15 Properties of Matrix Addition
A + B = B + A (A + B) + C = A + (B + C) A + 0 = 0 + A = A 18-Jan-19 Computer Science Department

16 Matrices Production 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 ith row of A and the ith column of B. In other words, if AB = [cij], then cij = ai1b1j + ai2b2j + … + aikbkj. 18-Jan-19 Computer Science Department

17 Matrices Production 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-Jan-19 Computer Science Department

18 Matrices Production 18-Jan-19 Computer Science Department

19 AB= 18-Jan-19 Computer Science Department

20 Matrices Production Example: Find AB if it is defined.
Let A 4X3= and B3X2 = Find AB if it is defined. AB4X2 = 18-Jan-19 Computer Science Department

21 Exercise Consider the matrices A= ,B= ,C= Find the following: 2A= 4A + B = A+0= 18-Jan-19 Computer Science Department

22 Matrices Production No Solution: Example: Let A 2x2 = and B 2x2=
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: Let A 2x2 = and B 2x2= Does AB = BA? Solution: AB = and BA = No 18-Jan-19 Computer Science Department

23 Properties of Multiplication
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: BA may not be defined; we may have n ≠ m For Example : A=4x5 , B=5x6 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 AB and BA may both the same size, but not equal as matrices AB ≠ BA For Example : A=4x4 , B=4x4 AB = BA 18-Jan-19 Computer Science Department

24 Basic Properties of Multiplication
The basic properties of matrix multiplication are given by the following theorem: A(BC) = (AB)C A(B + C)= AB + AC (A + B)C = AC + BC 18-Jan-19 Computer Science Department

25 Transpose Matrices Example: The transpose of the matrix is the matrix
DEFINITION 6: Let A = [aij] be an m x n matrix. The transpose of A, denoted by At, is the n x m matrix obtained by interchanging the rows and columns of A. In other words, if At = [bij], then bij = aji, for i = 1,2,…,n and j = 1,2,…,m. Example: The transpose of the matrix is the matrix 18-Jan-19 Computer Science Department

26 Properties for Transpose
If A and B are matrices, then 𝐴 𝑇 𝑇 =𝐴 (𝐴+𝐵) 𝑇 = 𝐴 𝑇 + 𝐵 𝑇 (𝐴𝐵) 𝑇 = 𝐵 𝑇 𝐴 𝑇 18-Jan-19 Computer Science Department

27 Exercises Consider the matrices : A= ,B= ,C= Find the following:
𝐶 𝑇 (𝐴+𝐵) 𝑇 =𝐴 𝑇 + 𝐵 𝑇 −4 −2 − − − = 18-Jan-19 Computer Science Department

28 Symmetric Matrices Example: The matrix is symmetric. Example
DEFINITION 7: A square matrix A is called symmetric if A = At. Thus A = [aij] is symmetric if aij = aji for all i and j with 1 ≤ i ≤ n and 1 ≤ j ≤ n. Example: The matrix is symmetric. Example 18-Jan-19 Computer Science Department

29 The Transpose of a Symmetric Matrix
18-Jan-19 Computer Science Department

30 Boolean Matrix Operation
A Boolean matrix is an m x n matrix whose entries are either zero or one. Example: 18-Jan-19 Computer Science Department

31 Boolean Matrix Operations (join)
Let A = [aij] and B = [bij] be m x n Boolean matrices. We define A v B = C = [ Cij], the join of A and B, by 1 if aij =1 or bij = 1 Cij = if aij and bij are both 0 18-Jan-19 Computer Science Department

32 Example Find the join of A and B: A = B = A v B = 1 0 1 0 1 0
1v0 0v1 1v0 0v1 1v1 0v0 = 18-Jan-19 Computer Science Department

33 Boolean Matrix Operations (Meet)
We define A ^ B = C = [ Cij], the meet of A and B, by if aij and bij are both 1 Cij = if aij = 0 or bij = 0 Meet & Join are the same as the addition procedure each element with the corresponding element in the other matrix Matrices have the same size 18-Jan-19 Computer Science Department

34 Example Find the meet of A and B: A = B = A ^ B = 1 0 1 0 1 0
1^0 0^1 1^0 0^1 1^1 0^0 = 18-Jan-19 Computer Science Department

35 Boolean PRODUCT The Boolean product of A and B, denoted , 𝑨 ⊙𝑩 is the m x n Boolean matrix defined by C𝑖𝑗= 1 , if aik = 1 and bkj = 1 for some k,1 ≤ k ≤ p 0,𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Procedure: Select row i of A and column j of B, and arrange them side by side. Compare corresponding entries. If even a single pair of corresponding entries consists of two 1’s, then Cij = 1, otherwise Cij = 0 18-Jan-19 Computer Science Department

36 Example Find the Boolean product of A and B: A 3x2= B 2x3 = 𝑨 ⊙𝑩3x3=
(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) = 18-Jan-19 Computer Science Department

37 Boolean Operations Properties
If A, B, and C are Boolean Matrices with the same sizes, then A v B = B v A A ^ B = B ^ A (A v B) v C = A v (B v C) (A ^ B) ^ C = A ^ (B ^ C) 18-Jan-19 Computer Science Department

38 Exercises Find meet and join for A and B: Solution : Meet of A and B =
join of A and B = 18-Jan-19 Computer Science Department

39 Exercises Find 𝑨 ⊙𝑩 Solution: 𝑨 ⊙𝑩 = 18-Jan-19
Computer Science Department

40 Any Question Refer to chapter 3 of the book for further reading
18-Jan-19 Computer Science Department


Download ppt "CS100: Discrete structures"

Similar presentations


Ads by Google