# Matrices - PowerPoint PPT Presentation

1 / 46

Matrices. Section 2.6 Monday, 2 June. Outline. Introduction Matrix Arithmetic: Sum, Product Transposes and Powers of Matrices Identity matrix, Transpose, Symmetric matrices Zero-one Matrices: Join, Meet, Boolean product. 2. Introduction.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Matrices

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## Matrices

Section 2.6

Monday, 2 June

MATRICES

### Outline

• Introduction

• Matrix Arithmetic:

• Sum, Product

• Transposes and Powers of Matrices

• Identity matrix, Transpose, Symmetric matrices

• Zero-one Matrices:

• Join, Meet, Boolean product

2

MATRICES

### Introduction

Definition: If m and n are positive integers, an m×n matrix consists of (mn) elements, arranged in m rows and n columns.

element in ith row, jth column

m rows

n columns

Also written as A=aij

When m = n, Ais called asquare matrix.

3

MATRICES

### Matrix Equality

• Definition: Let Aand B be two matrices. Then A= B if A and B have the same number of rows and the same number of columns, and every element at each position in A equals the element at corresponding position in B.

* Showing equality is not trivial if elements are real numbers subject to digital approximation.

4

MATRICES

Let A = aij, B = bij be mn matrices. Then:

A + B = aij + bij, and A–B= aij–bij

5

MATRICES

### Inventories

• Makealot, Inc. manufactures widgets, nerfs, smores, and flots.

• It supplies three different warehouses (#1,#2,#3).

Opening inventory:

Sales:

Closing inventory:

wi ne sm fl

#1

=

#2

#3

MATRICES

### MATLAB is “the matrix lab”

>> A = [ 1, -1; 3, 4; 2, 0 ]

A =

1 -1

3 4

2 0

>> B = [ 3, 4; 1, -4; 2, 3]

B =

3 4

1 -4

2 3

>> A+B

ans =

4 3

4 0

4 3

>> A-B

ans =

-2 -5

2 8

0 -3

Octave is a free version from Source Forge

MATRICES

### Matrix Multiplication

Let A be an mk matrix, and B be a kn matrix. Then their product is: AB=[cij], where

8

MATRICES

### Matrix Multiplication

Let A be an mk matrix, and B be a kn matrix. Then their product is: AB=[cij], where

9

MATRICES

### Matrix Multiplication

+

+

=

a

b

a

b

a

b

c

21

12

22

22

23

32

22

Let A be an mk matrix, and B be a kn matrix. Then their product is: AB=[cij]

10

MATRICES

### Example

>> A

A =

1 -1

3 4

2 0

>>C =

3 1 2

4 -4 3

>> A*C

ans =

-1 5 -1

25 -13 18

6 2 4

% to get ans row 2, col 3,

% dot product A row 2 by

% C col 3

>> [ 3, 4] * [2; 3]

ans =

18

>> dot ( [3,4], [2, 3])

ans =

18

Note the semicolon to produce a 2 x1 column vector or matrix

MATRICES

### Matching Dimensions

• Given an n×mmatrix A and an r×smatrix B:

• The product AB is defined only if m = r .

• When defined, AB is an n×smatrix.

23

34

24

12

MATRICES

### Nutrient counting - EXERCISE

• Construct:F: food×nutrient matrixC: day× units-consumed matrix

• Using F and C, calculate:W: day×nutrient matrix

• What do the following represent?

• W(1,1)?

• W(1,2)?

• W(2, 3)?

MATRICES

### Nutrient counting

F:

C:

W:

=

=

W(1,1): 355 Fat Cal’s on Sat; W(1,2): 220 Prot Cal’s on Sat;W(1,3): 1250 Sodium on Sat; W(2,1): 330 Fat Cal’s on Sun; etc.

MATRICES

### Nutrition in combined food units

>> Food = [25, 30, 100;

50, 10, 250;

40, 20, 150;

40, 15, 100 ]

Food =

25 30 100

50 10 250

40 20 150

40 15 100

>> Consumption = [3 0 5 2; 5, 1, 0, 4]

Consumption =

3 0 5 2

5 1 0 4

>> Consumption * Food

ans =

355 220 1250

335 220 1150

MATRICES

### Multiplicative Properties

• Prove or disprove: If A and B are matrices, and AB is defined, then BA is also defined.

• This is false. Consider, e.g,:

• Prove or disprove: If A and B are matrices and if AB and BA are both defined, then AB = BA.

• This is false. Consider, e.g.,

• Matrix multiplication is not commutative

Under what circumstances are ABand BA both defined?

16

MATRICES

### Multiplicative Properties

• Let A, B and C be matrices. Prove or disprove: If the product (AB)C is defined, then so is the product A(BC).

• This is true. To see why, assume that A is m ×n. Then, since AB is defined, there is some positive integer ksuch that B is n ×k and AB is m×k. As (AB)C is defined and AB is m×k, there is some positive integer l such that C is k ×l.These conclusions imply that BC is defined and is n ×l, which in turn implies that A(BC) is defined (and is m ×l).

MATRICES

### Multiplicative Properties

• Let A, B and C be matrices. If (AB)C defined, then (AB)C = A(BC).

• Assume A is m ×n, B is n ×k and C is k ×l. The result follows from:

ipth element of AB

qjth element of BC

ijth element of (AB)C

ijth element of A(BC)

MATRICES

### Cost of Matrix Product

23

34

a11b12+ a12b22+ a13b32= c12

It takes 3 multiplications (and 2 additions) to calculate each element.

There are 24=8 elements to calculate.

So 243 multiplications are needed.

In general to multiply an (mk) matrix and a (kn) matrix requires m·k·n multiplications.

19

MATRICES

### Best Order?

Consider the product of the following matrices. Should we do (AB)C or A(BC)?

(A B) C

20 ∙ 40 ∙10 = 8000 operations

32000

20 ∙ 30 ∙40 = 24000 operations

A (B C)

30 ∙ 40 ∙10 = 12000 operations

18000

20 ∙ 30 ∙10 = 6000 operations

So, A(BC) is bestin this case.

20

MATRICES

### Identity Matrix

The identity matrix is a square matrix with all 1’s along

the diagonal and 0’s elsewhere.

We write In to denote the n ×nidentity matrix.

Given an mn matrix A, we have A =Im A = A In

21

MATRICES

### Identity Matrix

The identity matrix is a square matrix with all 1’s along

the diagonal and 0’s elsewhere.

We write In to denote the n ×nidentity matrix.

Given an mn matrix A, we have A =Im A = A In

22

MATRICES

### Inverse Matrix

• Let A and B be nn matrices.

• If AB=BA=Inthen B is called the inverse of A, denoted B=A-1.

• Not all square matrices are invertible.

Thus:

23

MATRICES

### Application: Solving linear equalities

• Represent a system of linear equalities as a matrix equation:

• There is a unique solution if the coefficient matrix is invertible:

MATRICES

### Transpose

• Given an n ×m matrix A = (aij), the transpose of A, written At, is the m ×n matrix that has element aij in row j and column i, for 1 ≤ i ≤ m and 1 ≤ j ≤ n.

Flip across diagonal

MATRICES

### Symmetric Matrix

A square matrix A is said to be symmetric if A = At.

Non-symmetric:

Symmetric:

26

MATRICES

### Exercise

Are the following matrices symmetric?

• The 100 × 100 matrix M = [mij] satisfying mij= gcd(i,j)

• The 100 × 100 matrix S = [sij] satisfying sij= i−j

• I2000

MATRICES

### Powers of matrices

• Let A be ann ×n matrix. Thepowers of A are defined recursively:0th power of A: A0 = Inkth power of A: Ak = A∙Ak −1, for k > 0

. . .

28

MATRICES

### Powers of matrices

• Let A be ann ×n matrix. Thepowers of A are defined recursively:0th power of A: A0 = Inkth power of A: Ak = A∙Ak −1, for k > 0

k

Ak= AA ∙∙∙ A

29

MATRICES

Calculate

MATRICES

Calculate

MATRICES

### Zero-one Matrices

• All entries are 0 or 1.

• Operations are Boolean operations: Let A = [aij] and B = [bij] be m ×n zero-one matrices. Then:

• The join of A and B, written A  B, is the m ×n zero-one matrix [aijbij].

• The meet of A and B, written A ∧B, is the m ×n zero-one matrix [aij∧bij].

32

MATRICES

### Flight connections

Delta connection matrix:

Delta operates direct flights: From: To: From: To DTW JFK JFK DTW JFK MIA MIA JFK MIA LAX LAX MIA

Airtran operates direct flights: From: To: From: To: FNT DTW DTW CLE CLE TOL TOL JFK DTW JFK DTW MIA

Order the airport codes: 1:CLE, 2:DTW, 3:FNT, 4:JFK, 5:LAX, 6:MIA, 7: TOL

C D F J L M T

D =

C D F J L M T

MATRICES

### Flight connections

Delta operates direct flights: From: To: From: To DTW JFK JFK DTW JFK MIA MIA JFK MIA LAX LAX MIA

Airtran operates direct flights: From: To: From: To: FNT DTW DTW CLE CLE TOL TOL JFK DTW JFK DTW MIA

Order the airport codes: 1:CLE, 2:DTW, 3:FNT, 4:JFK, 5:LAX, 6:MIA, 7: TOL

Airtran connections:

C D F J L M T

A =

C D F J L M T

MATRICES

### Flight connections - EXERCISE

C D F J L M T

C D F J L M T

D =

A =

C D F J L M T

C D F J L M T

What operation on A and D produces the matrix showing the airports connected by a Delta flight or an Airtran flight?

What operation on A and D produces the matrix showing the airports connected by both a Delta flight and an Airtranflight? (You have a choice of airlines.)

MATRICES

### Flight connections

Airports connected by a Delta flight or an Airtran flight:

D  A =

=

MATRICES

### Flight connections

Airports connected by both a Delta flight and an Airtran flight:

D  A =

=

MATRICES

### MATLAB computations

>> or(Delta, Airtran)

ans =

0 0 0 0 0 0 1

1 0 0 1 0 1 0

0 1 0 0 0 0 0

0 1 0 0 0 1 0

0 0 0 0 0 1 0

0 0 0 1 1 0 0

0 0 0 1 0 0 0

>> and(Delta, Airtran)

ans =

0 0 0 0 0 0 0

0 0 0 1 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

>> Delta = [ 0 0 0 0 0 0 0;

0 0 0 1 0 0 0;

0 0 0 0 0 0 0;

0 1 0 0 0 1 0;

0 0 0 0 0 1 0;

0 0 0 1 1 0 0;

0 0 0 0 0 0 0 ];

>> Airtran = [ 0 0 0 0 0 0 1;

1 0 0 1 0 1 0;

0 1 0 0 0 0 0;

0 0 0 0 0 0 0;

0 0 0 0 0 0 0;

0 0 0 0 0 0 0;

0 0 0 1 0 0 0 ];

MATRICES

### Boolean Product

AB

Domination law says you

can stop when you find

a ‘1’

AB

39

MATRICES

### Boolean Product Properties

AB  BA

In general, A⊙B  B⊙A

Example:

BA

AB

40

MATRICES

### Boolean Power

• A Boolean power matrix can be defined in exactly the same way as a power matrix. For a nn square matrix A, the power matrix:

A[0] = In and

A[r] = AA[r −1] for r > 0

AA  . . .  A

41

MATRICES

### Flight connections

Airports connected via taking a Delta flight and then an Airtran flight.

DA =

=

C D F J L M T

C D F J L M T

C D F J L M T

MATRICES

### Flight connections

Airports connected via taking a Delta flight and then an Airtran flight.

DA =

=

C D F J L M T

C D F J L M T

C D F J L M T

MATRICES

### Flight connections

Airports connected via taking a Delta flight and then an Airtran flight.

DA =

=

C D F J L M T

C D F J L M T

C D F J L M T

MATRICES

### Flight connections - EXERCISE

Calculate the airports connected via taking an Airtran flight and then a Delta flight:

AD =

=

C D F J L M T

MATRICES

Flight connections

Airports connected via any number of Delta or Airtran flights (including no flights).

I (DA)  (DA)[2] (DA)[3] (DA)[4] …

From CLE: get to all but FNT. . .From FNT: get to all. . .

To JFK: from any of the airports

. . .

To FNT: only from FNT

C D F J L M T

MATRICES