Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of...

11
Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science

Transcript of Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of...

Page 1: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 1Kemal Akkaya

DISCRETE MATHEMATICSLecture 16

Dr. Kemal Akkaya

Department of Computer Science

Page 2: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 2Kemal Akkaya

§3.8 Matrices

A matrix is a rectangular array of objects (usually numbers).

An mn (“m by n”) matrix has exactly m horizontal rows, and n vertical columns.

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

An nn matrix is called a square matrix,whose order or rank is n.

07

15

32a 32 matrix

Page 3: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 3Kemal Akkaya

Applications of Matrices

Tons of applications, including:Solving systems of linear equationsComputer Graphics, Image ProcessingModels within many areas of

Computational Science & EngineeringQuantum Mechanics, Quantum

ComputingMany, many more…

Page 4: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 4Kemal Akkaya

Matrix Equality

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.

061

023

61

23

Page 5: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 5Kemal Akkaya

Row and Column Order

The rows in a matrix are usually indexed 1 to m from top to bottom. The columns are usually indexed 1 to n from left to right. Elements are indexed by row, then column.

nmmm

n

n

ji

aaa

aaa

aaa

a

,2,1,

,22,21,2

,12,11,1

, ][

A

Page 6: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 6Kemal Akkaya

Matrix Sums

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 = [ai,j+bi,j]

511

911

311

39

80

62

Page 7: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 7Kemal Akkaya

Matrix Products

For an mk matrix A and a kn matrix B, the product AB is the mn matrix:

i.e., the element of AB indexed (i,j) is given by the vector dot product of the ith row of A and the jth column of B (considered as vectors).

Note: Matrix multiplication is not commutative!

k

jiji bac1

,,, ][

CAB

Page 8: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 8Kemal Akkaya

Matrix Product Example

An example of matrix multiplication:

31123

1501

1301

0202

0110

302

110

k

jiji bac1

,,, ][

Page 9: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 9Kemal Akkaya

n

n

Identity Matrices

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.

100

010

001

if 0

if 1][

ji

jiijn I

Kronecker Delta

1≤i,j≤n

Page 10: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 10Kemal Akkaya

Matrix Inverses

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.

If the inverse exists, it is unique, and A−1A = AA−1.

We won’t go into the algorithms for matrix inversion...

Page 11: Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.

Discrete Mathematics 11Kemal Akkaya

Matrix Multiplication Algorithm

procedure matmul(matrices A: mk, B: kn)

for i := 1 to m

for j := 1 to n begin

cij := 0

for q := 1 to k

cij := cij + aiqbqj

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

What’s the of itstime complexity?

(m)

(n)

(1)

(k)

(1)

Answer:(mnk)