ICS4: Discrete Mathematics for Computer Science I Dept. Information & Computer Sci., Jan Stelovsky based on slides by Dr. Baek and Dr. Still Originals by Dr. M. P. Frank and Dr. J.L. Gross Provided by McGraw-Hill ICS 4: Discrete Mathematics I Fall -
Lecture 9 Chapter. The Fundamentals.8 Matrices ICS 4: Discrete Mathematics I Fall -
.8 Matrices n A matrix is a rectangular array of objects (usually numbers). n An m n ( m by n ) matrix has exactly m horizontal rows, and n vertical columns. 5 7 A matrix n Plural of matrix matrices (say MAY-trih-sees) n An n n matrix is called a square matrix ICS 4: Discrete Mathematics I Fall -
Applications of Matrices n Tons of applications, including: n Solving systems of linear equations n Computer Graphics, Image Processing n Games n Models within many areas of Computational Science & Engineering n Quantum Mechanics, Quantum Computing n Many, many more ICS 4: Discrete Mathematics I Fall -4
Row and Column Order n n n The rows in a matrix are usually indexed to m from top to bottom. The columns are usually indexed to n from left to right. Elements are indexed by row, then by column. A [ a ij ] a a a m a a a m a a a n n mn ICS 4: Discrete Mathematics I Fall -5
Matrix Equality n Two matrices A and B are considered equal iff they have the same number of rows, the same number of columns, and all their corresponding elements are equal. 6 6 ICS 4: Discrete Mathematics I Fall -6
Matrix Sums n The sum A + B of two matrices A, B (which must have the same number of rows, and the same number of columns) is the matrix (also with the same shape) given by adding corresponding elements of A and B. A + B [a ij + b ij ] 6 + 9 9 8 5 ICS 4: Discrete Mathematics I Fall -7
Matrix Products n For an m k matrix A and a k n matrix B, the product AB is the m n matrix: AB c ij C a i b [ c j ij + ] a i b j + + a n I.e., the element of AB indexed (i, j) is given by the vector dot product of the i-th row of A and the j-th column of B (considered as vectors). n Note: Matrix multiplication is not commutative! ik b kj k a i b j ICS 4: Discrete Mathematics I Fall -8
-9 ICS 4: Discrete Mathematics I Fall Matrix Product Example + + + + + + + + ) ( ) ( ) ( ) (
Matrix Product Example A and B n Because A is a matrix and B is a matrix, the product AB is not defined. ICS 4: Discrete Mathematics I Fall -
Matrix Multiplication: Non-Commutative n Matrix multiplication is not commutative! n A: m n matrix and B: r s matrix n n n n n AB is defined when n r BA is defined when s m When both AB and BA are defined, generally they are not the same size unless m n r s If both AB and BA are defined and are the same size, then A and B must be square and of the same size Even when A and B are both n n matrices, AB and BA are not necessarily equal ICS 4: Discrete Mathematics I Fall -
- ICS 4: Discrete Mathematics I Fall Matrix Product Example 5 AB 4 BA B A and
Matrix Multiplication Algorithm procedure matmul(matrices A: m k, B: k n) for i : to m Θ(m) { for j : to n begin c ij : for q : to k Θ(n) ( Θ()+ Θ(k) What s the Θ of its time complexity? Answer: Θ(mnk) c ij : c ij + a iq b qj Θ())} end {C [c ij ] is the product of A and B} ICS 4: Discrete Mathematics I Fall -
Identity Matrices n The identity matrix of order n, I n, is the rank-n square matrix with s along the upper-left to lower-right diagonal, and s everywhere else. i, j n I [ δ ] n ij Kronecker Delta if if i i j j n ICS 4: Discrete Mathematics I Fall n -4
Matrix Inverses n For some (but not all) square matrices A, there exists a unique multiplicative inverse A of A, a matrix such that A A I n. n If the inverse exists, it is unique, and A A AA. n We won t go into the algorithms for matrix inversion... ICS 4: Discrete Mathematics I Fall -5
-6 ICS 4: Discrete Mathematics I Fall Powers of Matrices If A is an n n square matrix and p, then: n A p AAA A (and A I n ) n Example: p times 4
-7 ICS 4: Discrete Mathematics I Fall Matrix Transposition n If A [a ij ] is an m n matrix, the transpose of A (often written A t or A T ) is the n m matrix given by A t B [b ij ] [a ji ] ( i n, j m) t
-8 ICS 4: Discrete Mathematics I Fall Symmetric Matrices n A square matrix A is symmetric iff A A t. I.e., i, j n: a ij a ji. n Which of the below matrices is symmetric?
Zero-One Matrices n Useful for representing other structures. n E.g., relations, directed graphs (later on) n All elements of a zero-one matrix are either or. n E.g., representing False & True respectively. n The join of A, B (both m n zero-one matrices): n A B [a ij b ij ] n The meet of A, B: n A B [a ij b ij ] [a ij b ij ] ICS 4: Discrete Mathematics I Fall -9
- ICS 4: Discrete Mathematics I Fall Join and Meet Example B A B A and B A
Boolean Products n Let A [a ij ] be an m k zero-one matrix and B [b ij ] be a k n zero-one matrix, n The boolean product of A and B is like normal matrix multiplication, but using instead of +, and instead of in the row-column vector dot product : A B k C [ cij] a i b j ICS 4: Discrete Mathematics I Fall -
Boolean Products Example n Find the Boolean product of A and B, where A B ( ) ( ) ( ) ( ) ( ) ( ) A B ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ICS 4: Discrete Mathematics I Fall -
Boolean Powers n For a square zero-one matrix A, and any k, the k-th Boolean power of A is simply the Boolean product of k copies of A. A [k] A A A k times A [] I n ICS 4: Discrete Mathematics I Fall -
Matrices as Functions n An m n matrix A [a ij ] of members of a set S can be encoded as a partial function f A : N N S, such that for i < m, j < n, f A (i, j) a ij. n By extending the domain over which f A is defined, various types of infinite and/or multidimensional matrices can be obtained. ICS 4: Discrete Mathematics I Fall -4