Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
CS100: DISCRETE STRUCTURES
Lecture 3 – MatricesCh 3 – Pages: 246-262
Matrices
Introduction
¨ Example: The matrix is a 3 x 2 matrix.
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.
úúú
û
ù
êêê
ë
é
312011
2
MatricesDEFINITION 2:3
Then A is ….with a12 = …. and a23 = …, B is …with b21 = …, C is …., D is ……, and E is …….
Example 14
ANS:Then A is 2*3 with a12 = 3 and a23 =2 , B is 2*2 with b21 =4, C is 1*4, D is 3*1, and E is 3*3
Exercise
Let
1) What size is A ?
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 ?
5
3×4
A(3,2)=1
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 :
Diagonal Matrix6
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)
7
Example of Matrix applications
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
8
Cont’d
¨ The following matrix gives the airline distance between the cities indicated
9
Equal Matrices
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.
10
Cont’d
Then A = B
if and only if X=-3, y=0, and z=6
11
Matrices
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.
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].
Matrix Arithmetic12
Example 1
=úúú
û
ù
êêê
ë
é
--
-+úúú
û
ù
êêê
ë
é--
211031143
043322101
Example 2
13
úúú
û
ù
êêê
ë
é---
252313244
Zero Matrix
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
14
Properties of Matrix Addition
v A + B = B + A
v (A + B) + C = A + (B + C)
v A + 0 = 0 + A = A
15
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 i th row of A and the i th column
of B. In other words, if AB = [cij], then
cij = ai1b1j + ai2b2j + … + aikbkj.
16
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.
17
Matrices Production18
AB=19
Matrices Production
¨ Example:
Let A 4X3= and B3X2 =
Find AB if it is defined.
AB =
úúúú
û
ù
êêêê
ë
é
220013112401
úúú
û
ù
êêê
ë
é
031142
20
úúúú
û
ù
êêêê
ë
é
2813798414
Exercise
Consider the matrices A= ,B=,C=
Find the following:2A= 4A + B = A+0=
21
Matrices Production
¨ Example: Let A 2x2 = and B 2x2=
Does AB = BA?Solution:
AB = and BA =
úû
ùêë
é1211
úû
ùêë
é1112
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.
22
úû
ùêë
é3523
úû
ùêë
é2334
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:1. BA may not be defined; we may have n ≠ m
For Example : A=4x5 , B=5x62. 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 equalFor Example : A=4x5 , B=5x4
3. AB and BA may both the same size, but not equal as matrices AB ≠ BA
For Example : A=4x4 , B=4x44. AB = BA
23
Basic Properties of Multiplication
¨ 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
24
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.
úû
ùêë
é654321
úúú
û
ù
êêê
ë
é
635241
25
Properties for Transpose
If A and B are matrices, then1. 𝐴% % = 𝐴2. (𝐴 + 𝐵)%= 𝐴% +𝐵%
3. (𝐴𝐵)%= 𝐵%𝐴%
26
Exercises
Consider the matrices : A=
,B= ,C=
Find the following:𝐶% (𝐴 + 𝐵)%
= =
=
27
1 2 53 −4 −2 −1 1 4
0 3 22 −2 3
+6 4 38 −2 15 7 2
=5 5 78 1 37 5 5
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.
úúú
û
ù
êêê
ë
é
010101011
28
The Transpose of a Symmetric Matrix29
Boolean Matrix Operation
A Boolean matrix is an m x n matrix whose entries are either zero or one.
1 0 10 0 11 1 0
Example:
30
Boolean Matrix Operations (join)
v Let A = [aij] and B = [bij] be m x n Boolean matrices.
v We define A v B = C = [ Cij], the join of A and B, by
1 if aij =1 or bij = 1
Cij = 0 if aij and bij are both 0
31
Example
¨ Find the join of A and B:
A = B =
A v B =
1 0 10 1 0
0 1 01 1 0
1v0 0v1 1v00v1 1v1 0v0 = 1 1 1
1 1 0
32
Boolean Matrix Operations (Meet)
v We define A ^ B = C = [ Cij], the meet of A and B, by1 if aij and bij are both 1
Cij = 0 if aij = 0 or bij = 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
33
Example
¨ Find the meet of A and B:A = B =
A ^ B =
1 0 10 1 0
0 1 01 1 0
1^0 0^1 1^00^1 1^1 0^0
= 0 0 00 1 0
34
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:
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 Cij = 1, otherwise Cij = 0
35
Example
¨ Find the Boolean product of A and B:A 3x2= B 2x3 =
𝑨 ⊙ 𝑩3x3=
1 00 11 0
1 1 00 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 00 1 11 1 0
36
Boolean Operations Properties
¨ 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)
37
Exercises
¨ Find meet and join for A and B:
Solution :
Meet of A and B =
join of A and B =
=
=
38
Exercises
¨ Find 𝑨 ⊙𝑩
Solution:
𝑨 ⊙𝑩 =
=
=
•Find
39
Any Question
¨ Refer to chapter 3 of the book for further reading
40