You are on page 1of 24

University of Hawaii

ICS141:
Discrete Mathematics for
Computer Science I
Dept. Information & Computer Sci., University of Hawaii

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 141: Discrete Mathematics I – Fall 2011 13-1


University of Hawaii

Lecture 19
Chapter 3. The Fundamentals
3.8 Matrices

ICS 141: Discrete Mathematics I – Fall 2011 13-2


3.8 Matrices
University of Hawaii

n A matrix is a rectangular array of


objects (usually numbers). ⎡2 3⎤
⎢ 5 − 1⎥
n An m × n (“m by n”) matrix has ⎢ ⎥
exactly m horizontal rows, and n ⎢⎣7 0⎥⎦
vertical columns. A 3×2 matrix

n Plural of matrix = matrices (say MAY-trih-sees)


n An n × n matrix is called a square matrix

ICS 141: Discrete Mathematics I – Fall 2011 13-3


Applications of Matrices
University of Hawaii

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 141: Discrete Mathematics I – Fall 2011 13-4
Row and Column Order
University of Hawaii

n The rows in a matrix are usually indexed 1 to m from top


to bottom.
n The columns are usually indexed 1 to n from left to right.
n Elements are indexed by row, then by column.

⎡ a11 a12  a1n ⎤


⎢ a a  a2 n ⎥⎥
⎢ 21 22
A = [aij ] =
⎢     ⎥
⎢ ⎥
⎣am1 am 2  amn ⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-5


Matrix Equality
University of Hawaii

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.

⎡ 3 2⎤ ⎡ 3 2 0⎤
⎢− 1 6⎥ ≠ ⎢− 1 6 0⎥
⎣ ⎦ ⎣ ⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-6


Matrix Sums
University of Hawaii

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 = [aij + bij]

⎡2 6⎤ ⎡ 9 3⎤ ⎡ 11 9⎤


⎢0 − 8⎥ + ⎢− 11 3⎥ = ⎢− 11 − 5⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
ICS 141: Discrete Mathematics I – Fall 2011 13-7
Matrix Products
University of Hawaii

n For an m × k matrix A and a k × n matrix B,


the product AB is the m × n matrix:

AB = C = [cij ]
k
cij = ai1b1 j + ai 2b2 j +  + aik bkj = ∑ aibj
 =1
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!
ICS 141: Discrete Mathematics I – Fall 2011 13-8
Matrix Product Example
University of Hawaii

⎡0 − 1⎤
⎡0 1 − 1⎤ ⎢ ⎥
⎢2 0 ⎥ ⋅ ⎢2 0⎥
⎣ 3⎦
⎢⎣ 1 0⎥⎦
⎡0 ⋅ 0 + 1⋅ 2 + (−1) ⋅1 0 ⋅ (−1) + 1 ⋅ 0 + (−1) ⋅ 0⎤
= ⎢ ⎥
⎣ 2 ⋅ 0 + 0 ⋅ 2 + 3 ⋅1 2 ⋅ (−1) + 0 ⋅ 0 + 3 ⋅ 0⎦
⎡ 1 0⎤
= ⎢ ⎥
⎣3 − 2⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-9


Matrix Product Example
University of Hawaii

⎡1 0 2⎤ ⎡2 1⎤


A = ⎢ ⎥ and B = ⎢ ⎥
⎣3 1 1⎦ ⎣1 1⎦

n Because A is a 2×3 matrix and B is a 2×2


matrix, the product AB is not defined.

ICS 141: Discrete Mathematics I – Fall 2011 13-10


Matrix Multiplication: University of Hawaii

Non-Commutative
n Matrix multiplication is not commutative!
n A: m × n matrix and B: r × s matrix
n AB is defined when n = r
n BA is defined when s = m
n When both AB and BA are defined, generally they
are not the same size unless m = n = r = s
n If both AB and BA are defined and are the same size,
then A and B must be square and of the same size
n Even when A and B are both n × n matrices,
AB and BA are not necessarily equal

ICS 141: Discrete Mathematics I – Fall 2011 13-11


Matrix Product Example
University of Hawaii

⎡1 1⎤ ⎡2 1⎤


A = ⎢ ⎥ and B = ⎢ ⎥
⎣2 1⎦ ⎣1 1⎦

⎡3 2⎤ ⎡4 3⎤


AB = ⎢ ⎥ BA = ⎢ ⎥
⎣5 3⎦ ⎣3 2⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-12


Matrix Multiplication Algorithm
University of Hawaii

procedure matmul(matrices A: m × k, B: k × n)
for i := 1 to m Θ(m)·{ What’s the Θ of its
time complexity?
for j := 1 to n begin Θ(n)·(

cij := 0 Θ(1)+ Answer:


Θ(mnk)
for q := 1 to k Θ(k) ·

cij := cij + aiqbqj Θ(1))}


end {C = [cij] is the product of A and B}

ICS 141: Discrete Mathematics I – Fall 2011 13-13


Identity Matrices
University of Hawaii

n The identity matrix of order n, In, is the rank-n


square matrix with 1’s along the upper-left to
lower-right diagonal, and 0’s everywhere else.

⎡1 0  0⎤
∀1 ≤ i, j ≤ n
⎡⎧1 if i = j ⎤ 0 ⎢ ⎥
1  0⎥
I n = [δ ij ] = ⎢⎨ ⎥ = ⎢ n
⎣⎩0 if i ≠ j ⎦ ⎢     ⎥
⎢ ⎥
Kronecker Delta ⎣0 0  1⎦

ICS 141: Discrete Mathematics I – Fall 2011


n 13-14
Matrix Inverses
University of Hawaii

n For some (but not all) square matrices A, there


exists a unique multiplicative inverse A−1 of A,
a matrix such that A−1A = In.
n If the inverse exists, it is unique, and
A−1A = AA−1.
n We won’t go into the algorithms for matrix
inversion...

ICS 141: Discrete Mathematics I – Fall 2011 13-15


Powers of Matrices
University of Hawaii

If A is an n × n square matrix and p ≥ 0, then:


n Ap = AAA···A (and A0 = In)
p times
3
⎡ 2 1⎤ ⎡ 2 1⎤ ⎡ 2 1⎤ ⎡ 2 1⎤
n Example: ⎢ ⎥ = ⎢ ⎥ ⋅ ⎢ ⎥ ⋅ ⎢ ⎥
⎣ − 1 0 ⎦ ⎣ − 1 0 ⎦ ⎣ − 1 0 ⎦ ⎣ − 1 0 ⎦

⎡ 2 1⎤ ⎡ 3 2⎤
= ⎢ ⎥ ⋅ ⎢ ⎥
⎣ − 1 0 ⎦ ⎣ − 2 − 1⎦

⎡ 4 3⎤
= ⎢ ⎥
⎣ − 3 − 2 ⎦
ICS 141: Discrete Mathematics I – Fall 2011 13-16
Matrix Transposition
University of Hawaii

n If A = [aij] is an m × n matrix, the transpose of A


(often written At or AT) is the n × m matrix given by
At = B = [bij] = [aji] (1 ≤ i ≤ n,1 ≤ j ≤ m)

t ⎡2 0⎤
⎡2 1 3⎤ ⎢ ⎥
⎢0 − 1 − 2⎥ = ⎢ 1 − 1⎥
⎣ ⎦ ⎢⎣ 3 − 2⎥⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-17


Symmetric Matrices
University of Hawaii

n A square matrix A is symmetric iff A = At.


I.e., ∀i, j ≤ n: aij = aji .

n Which of the below matrices is symmetric?

⎡1 1⎤ ⎡− 2 1 3⎤ ⎡ 3 0 1⎤


⎢1 1⎥ ⎢ 1 0 − 1⎥ ⎢0 2 − 1⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢⎣1 1⎥⎦ ⎢⎣ 3 − 1 2⎥⎦ ⎢⎣ 1 1 − 2⎥⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-18


Zero-One Matrices
University of Hawaii

n Useful for representing other structures.


n E.g., relations, directed graphs (later on)

n All elements of a zero-one matrix are either 0 or 1.


n E.g., representing False & True respectively.

n The join of A, B (both m × n zero-one matrices):


n A ∨ B = [aij ∨ bij]

n The meet of A, B:
n A ∧ B = [aij ∧ bij] = [aij bij]

ICS 141: Discrete Mathematics I – Fall 2011 13-19


Join and Meet Example
University of Hawaii

⎡1 0 1⎤ ⎡0 1 0⎤


A = ⎢ ⎥ and B = ⎢ ⎥
⎣0 1 0⎦ ⎣1 1 0⎦

⎡1 ∨ 0 0 ∨1 1 ∨ 0 ⎤ ⎡1 1 1⎤


A ∨ B = ⎢ ⎥ = ⎢
⎣0 ∨ 1 1∨ 1 0 ∨ 0⎦ ⎣1 1 0⎥⎦

⎡1 ∧ 0 0 ∧1 1 ∧ 0 ⎤ ⎡0 0 0⎤


A ∧ B = ⎢ ⎥ = ⎢ ⎥
⎣0 ∧ 1 1∧1 0 ∧ 0⎦ ⎣0 1 0⎦
ICS 141: Discrete Mathematics I – Fall 2011 13-20
Boolean Products
University of Hawaii

n Let A = [aij] be an m × k zero-one matrix and


B = [bij] 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”:

⎡ k ⎤

A⊙B = C = [cij ] = ⎢ ai ∧ bj ⎥
⎣  =1 ⎦

ICS 141: Discrete Mathematics I – Fall 2011 13-21


Boolean Products Example
University of Hawaii

n Find the Boolean product of A and B, where


⎡ 1 0⎤
⎢ ⎥ ⎡1 1 0⎤
A = ⎢0 1⎥ B = ⎢ ⎥
⎣ 0 1 1 ⎦
⎢⎣ 1 0⎥⎦
⎡(1 ∧ 1) ∨ (0 ∧ 0) (1 ∧ 1) ∨ (0 ∧ 1) (1 ∧ 0) ∨ (0 ∧ 1)⎤
A⊙B = ⎢⎢(0 ∧ 1) ∨ (1 ∧ 0) (0 ∧ 1) ∨ (1 ∧ 1) (0 ∧ 0) ∨ (1 ∧ 1)⎥⎥
⎢⎣(1 ∧ 1) ∨ (0 ∧ 0) (1 ∧ 1) ∨ (0 ∧ 1) (1 ∧ 0) ∨ (0 ∧ 1)⎥⎦

⎡1 ∨ 0 1 ∨ 0 0 ∨ 0⎤ ⎡1 1 0⎤


= ⎢⎢0 ∨ 0 0 ∨ 1 0 ∨ 1⎥⎥ = ⎢⎢0 1 1⎥⎥
⎢⎣1 ∨ 0 1 ∨ 0 0 ∨ 0⎥⎦ ⎢⎣1 1 0⎥⎦
ICS 141: Discrete Mathematics I – Fall 2011 13-22
Boolean Powers
University of Hawaii

n For a square zero-one matrix A, and any k ≥ 0,


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[0] = In

ICS 141: Discrete Mathematics I – Fall 2011 13-23


Matrices as Functions
University of Hawaii

n An m × n matrix A = [aij] of members of a set S


can be encoded as a partial function
fA: N×N → S,
such that for i < m, j < n, fA(i, j) = aij.

n By extending the domain over which fA is


defined, various types of infinite and/or
multidimensional matrices can be obtained.

ICS 141: Discrete Mathematics I – Fall 2011 13-24

You might also like