Matrices

19
Matrices CSLU 1100.003 Fall 2007 Cameron McInally [email protected] Fordham University

description

Matrices. CSLU 1100.003 Fall 2007 Cameron McInally [email protected] Fordham University. Matrices. Matrix In English… What is a list of items called? What is a list of lists called?. a list. a table. Matrices. Matrix In Computer Science… What is a row of elements called? - PowerPoint PPT Presentation

Transcript of Matrices

Page 1: Matrices

Matrices

CSLU 1100.003Fall 2007

Cameron [email protected]

Fordham University

Page 2: Matrices

Matrices

• Matrix– In English…

• What is a list of items called?

• What is a list of lists called?

a list.

a table.

Item 1 Item 2 Item 3 Item 4

A B C D

List 1 List 2 List 3 List 4

Item 1 Item 1 Item 1 Item 1

Item 2 Item 2 Item 2 Item 2

Item 3 Item 3 Item 3 Item 3

Page 3: Matrices

Matrices

• Matrix– In Computer Science…

• What is a row of elements called?

• What is an array of arrays called?

an array.

a matrix.

Element 0

Element1

Element 2

Element 3

A B C D

Array 0 Array 1 Array 2 Array 3

Element 0 Element 0 Element 0 Element 0

Element 1 Element 1 Element 1 Element 1

Element 2 Element 2 Element 2 Element 2

Page 4: Matrices

Matrices

• Elements of a Matrix– The items.– How do we reference a particular element in matrix M?

Array 0 Array 1 Array 2 Array 3

Element 0

Element 0

Element 0

Element 0

Element 1

Element 1

Element 1

Element 1

Element 2

Element 2

Element 2

Element 2

M =

M(x,y) = item y in array x

Page 5: Matrices

Matrices

• Elements of a MatrixArray 0 Array 1 Array 2 Array 3

A B C D

E F G H

I J K L

M =

M(1,2) =M(0,0) =M(1,0) =M(3,2) =

JABL

Page 6: Matrices

Matrices

• Examples

701

235A

131

202

551

C

10

10

16

B

1000

0100

0010

0001

D

Page 7: Matrices

Matrices

• Size of a Matrix– We describe the size of a matrix by its width and

its height. So….

size(A) = number_of_elements(A) =

701

235A

3x23*2 = 6

Page 8: Matrices

Matrices

• Adding Matrices– Rule #1: The two matrices we wish to add must be

the same size.– Rule #2: Add the corresponding elements in the

two matrices to create a new matrix.– Rule #3: Memorize these.

Page 9: Matrices

Matrices

• Adding Matrices Example

– Rule #1: Both matrices are 3x2. – Rule #2:

701

235A

111

111B

610

146

171011

121315 BA

Page 10: Matrices

Matrices

• Adding Matrices Example

– Rule #1: A is 3x2 and B is 2x3.

A and B can not be added together!!!

701

235A

10

10

16

B

Page 11: Matrices

Matrices

• Scalar Multiplication– Rule #0: A scalar is a single number.– Rule #1: Multiply each element in a matrix by a

scalar.

Page 12: Matrices

Matrices

• Scalar Multiplication Example

701

235A

1402

4610

2*72*02*1

2*22*32*5A2

Page 13: Matrices

Matrices

• Matrix Multiplication– Rule #1 : You can only multiple two matrices if the

number of columns in the first matrix is equal to the number of rows in the second matrix.

Page 14: Matrices

Matrices

• Matrix Multiplication– Rule #1 Explained:

Can we multiply A x B?Yes, we have a 2x3 matrix multiplied by a 3x2 matrix. The number of columns in the first one (3) matches the number of rows in the second one (3).

701

235A

10

10

16

B

Page 15: Matrices

Matrices

• Matrix Multiplication– Rule #1 Explained:

701

235A

Can we multiply D x A?No it is a 3x3 multiplied by a 2x3. The number of columns in the first one (3) does not match the number of rows in the second one (2). Note: We can multiply A x D.

000

111

111

D

Page 16: Matrices

Matrices

• Matrix Multiplication

What is A x B?1. First rewrite the matrices so that

the first one is on the left of the result matrix and the second one is above the result matrix.

2. Start with the first row on the left matrix and the first column on the above matrix.

3. Multiply each pair of terms from 1..n and add them together.

701

235

10

10

16

30 10

6 -6

Page 17: Matrices

Matrices

• Matrix Multiplication Example

– What is D*B?

000

111

111

10

10

16

B

000

111

111

D

10

10

16

00

16

16

Page 18: Matrices

Matrices

• Matrix Multiplication Practice

1. What is AxC?2. What is CxA?3. What is AxD?4. What is DxA?

701

235A

10

10

16

B

01

24

23

C

000

111

111

D

Page 19: Matrices

Homework(Always Due in One WeekAlways Due in One Week)

• Read Appendix B section “Matrix Operations”• Complete Section 6.1 pages 623:

1 (a – e), 2(a – d) [Hint: I is the Identity Matrix] • Why is I called the Identity Matrix?

Matrices

10

01