Welcome back! 1 Today Matrices: why and what? Matrix operations - - PowerPoint PPT Presentation

welcome back
SMART_READER_LITE
LIVE PREVIEW

Welcome back! 1 Today Matrices: why and what? Matrix operations - - PowerPoint PPT Presentation

Graphics (INFOGR), 2018-19, Block IV, lecture 8 Deb Panja Today: Matrices and introduction to transformations Welcome back! 1 Today Matrices: why and what? Matrix operations Determinants Adjoint/adjugate and inverse of matrices


slide-1
SLIDE 1

Graphics (INFOGR), 2018-19, Block IV, lecture 8 Deb Panja

Today: Matrices and introduction to transformations

Welcome back!

1

slide-2
SLIDE 2

Today

  • Matrices: why and what?
  • Matrix operations
  • Determinants
  • Adjoint/adjugate and inverse of matrices
  • Geometric interpretation of determinants
  • Introduction to transformations

2

slide-3
SLIDE 3

Spatial transformations − part II of the course

3

slide-4
SLIDE 4

Spatial transformations − part II of the course

  • Why matrices?

− you need to execute such spatial transformations (a lot!) − matrices are the vehicles you need for these tasks

4

slide-5
SLIDE 5

Spatial transformations − part II of the course

  • Why matrices?

− you need to execute such spatial transformations (a lot!) − matrices are the vehicles you need for these tasks

  • That means: it’s nearly impossible to dissociate matrices from

transformations they achieve

5

slide-6
SLIDE 6

Bigger scheme of things: three upcoming maths lectures

6

slide-7
SLIDE 7

Bigger scheme of things: three upcoming maths lectures

7

slide-8
SLIDE 8

Bigger scheme of things: three upcoming maths lectures

  • It’s been a choice to make a clean separation this way!

8

slide-9
SLIDE 9

What is a matrix?

9

slide-10
SLIDE 10

What is a matrix?

10

slide-11
SLIDE 11

What is a matrix?

  • You’ll store it on a computer as a two-dimensional array: arr[3][3]

11

slide-12
SLIDE 12

Why matrices?

  • Example:

(more about that in the next lecture)

12

slide-13
SLIDE 13

Matrices

13

slide-14
SLIDE 14

Matrices

  • Dimension of the above matrix: m × n

− when m = n, the matrix is called a square matrix − aij (i ∈ [1, m], j ∈ [1, n]) are the matrix elements/coefficients − shorthand notation A = {aij}

14

slide-15
SLIDE 15

Matrices

  • Dimension of the above matrix: m × n

− when m = n, the matrix is called a square matrix − aij (i ∈ [1, m], j ∈ [1, n]) are the matrix elements/coefficients − shorthand notation A = {aij}

  • A d-dimensional vector is a d × 1 matrix

− an m×n matrix: n vertical concatenation of m-dimensional vectors

15

slide-16
SLIDE 16

Matrices

  • Dimension of the above matrix: m × n

− when m = n, the matrix is called a square matrix − aij (i ∈ [1, m], j ∈ [1, n]) are the matrix elements/coefficients − shorthand notation A = {aij}

  • A d-dimensional vector is a d × 1 matrix

− an m×n matrix: n vertical concatenation of m-dimensional vectors

  • A scalar is a 1 × 1 matrix

16

slide-17
SLIDE 17

Special matrices

  • Diagonal matrix: square matrix with aij = 0

for i = j; e.g., (a diagonal matrix is by definition a square matrix)

17

slide-18
SLIDE 18

Special matrices

  • Diagonal matrix: square matrix with aij = 0

for i = j; e.g., (a diagonal matrix is by definition a square matrix)

  • Identity matrix: diagonal matrix with aii = 1, e.g.,

(denoted by I, an identity matrix is also by definition a square matrix)

18

slide-19
SLIDE 19

Special matrices

  • Diagonal matrix: square matrix with aij = 0

for i = j; e.g., (a diagonal matrix is by definition a square matrix)

  • Identity matrix: diagonal matrix with aii = 1, e.g.,

(denoted by I, an identity matrix is also by definition a square matrix)

  • Null matrix (denoted by Ø or O): aij = 0, e.g.,

19

slide-20
SLIDE 20

Matrix operations

20

slide-21
SLIDE 21

Addition of matrices

21

slide-22
SLIDE 22

Addition of matrices

  • Can only add matrices of same dimensions!

22

slide-23
SLIDE 23

Scalar multiplication of matrices

23

slide-24
SLIDE 24

Addition and scalar multiplication of matrices

24

slide-25
SLIDE 25

Subtraction of matrices

  • A and B are matrices of the same dimensions; then A−B = A+(−1)B;

− e.g., (can only subtract matrices of same dimensions!)

25

slide-26
SLIDE 26

Matrix multiplication

  • A and B are m × n and n × p dimensional matrices respectively

then C = AB is an m × p-dimensional matrix

26

slide-27
SLIDE 27

Matrix multiplication

  • A and B are m × n and n × p dimensional matrices respectively

then C = AB is an m × p-dimensional matrix

  • matrix elements cij =

n

  • k=1

aikbkj

  • n a computer: cij = 0; for (k = 1; k <= n; k++) cij += aikbkj

e.g.,

27

slide-28
SLIDE 28

Vector dot product as a matrix multiplication

  • Vectors

u =       u1 u2 . . ud       and v =       v1 v2 . . vd      

  • u ·

v = [u1 u2 . . . ud]       v1 v2 . . vd       = v · u = u1v1 + u2v2 + . . . + udvd

28

slide-29
SLIDE 29

Matrix multiplication properties

  • In general, AB = BA! (i.e., they do not commute)

however, AB = BA if both A and B are diagonal in particular, IA = AI = A and AØ = ØA = Ø

  • A(B + C) = AB + AC, (A + B)C = AC + BC: distributive
  • (AB)C = A(BC): associative

29

slide-30
SLIDE 30

Transpose of a matrix

30

slide-31
SLIDE 31

Transpose of a matrix

  • AT = transpose(A); (AT)T = A

31

slide-32
SLIDE 32

Determinants and cofactors (only for square matrices!)

32

slide-33
SLIDE 33

Determinants

  • Determinant of matrix A ≡ det(A), or |A|; a scalar quantity
  • Also as
  • Determinants and cofactors are inextricably linked

33

slide-34
SLIDE 34

Determinant (1 × 1 matrices)

  • Determinant of a 1 × 1 matrix is the value of its element

e.g., A = [−5], det(A) = −5

34

slide-35
SLIDE 35

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12)

35

slide-36
SLIDE 36

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12) = a21 cof(a21) + a22 cof(a22)

36

slide-37
SLIDE 37

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12) = a21 cof(a21) + a22 cof(a22)

= a11 cof(a11) + a21 cof(a21)

37

slide-38
SLIDE 38

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12) = a21 cof(a21) + a22 cof(a22)

= a11 cof(a11) + a21 cof(a21) = a12 cof(a12) + a22 cof(a22)

38

slide-39
SLIDE 39

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12)

cof(aij) = (−1)i+j det(minor(aij)) minor(aij) is the matrix without the i-th row and j-th column of A

  • Q. What is the determinant of the above matrix A?

39

slide-40
SLIDE 40

Determinant (2 × 2 matrices)

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • det(A) = a11 cof(a11) + a12 cof(a12)

cof(aij) = (−1)i+j det(minor(aij)) minor(aij) is the matrix without the i-th row and j-th column of A

  • Q. What is the determinant of of the above matrix A?
  • A. cof(a11) = det(a22) = a22; cof(a12) = − det(a12) = −a21

det(A) = a11a22 − a12a21; note also that det(A) = det(AT)

  • Example:

40

slide-41
SLIDE 41

Determinant (3 × 3 matrices)

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33   det(A) = a11 cof(a11) + a12 cof(a12) + a13 cof(a13)

41

slide-42
SLIDE 42

Determinant (3 × 3 matrices)

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33   det(A) = a11 cof(a11) + a12 cof(a12) + a13 cof(a13) = a21 cof(a21) + a22 cof(a22) + a23 cof(a23)

42

slide-43
SLIDE 43

Determinant (3 × 3 matrices)

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33   det(A) = a11 cof(a11) + a12 cof(a12) + a13 cof(a13) = a11

  • a22

a23 a32 a33

  • − a12
  • a21

a23 a31 a33

  • + a13
  • a21

a22 a31 a32

  • = a11a22a33 − a11a23a32 + a12a23a31 − a12a21a33

+ a13a21a32 − a13a22a31 = det(AT)

  • Example:

43

slide-44
SLIDE 44

Determinant (3 × 3 matrices), Sarrus’ rule

44

slide-45
SLIDE 45

Determinant (3 × 3 matrices), Sarrus’ rule

  • Does not work for 2 × 2, 4 × 4, ... matrices

45

slide-46
SLIDE 46

Adjoint/adjugate and inverse (only for square matrices!)

46

slide-47
SLIDE 47

Cofactor matrix and adjoint/adjugate

  • Cofactor matrix C = {cij} of matrix A = {aij}

i.e., cij = cof(aij) example:

  • Adjoint/adjugate(A) ≡ adj(A) = transpose(cof(A))

47

slide-48
SLIDE 48

Inverse of a matrix

  • Inverse of A ≡ A−1 = adj(A)

|A|

  • Has the property AA−1 = A−1A = I (identity matrix)
  • Inverse does not exist if |A| = 0; then A is a singular matrix

48

slide-49
SLIDE 49

Geometric interpretation of determinants

49

slide-50
SLIDE 50

Determinants of 2 × 2 matrices

  • Consider the 2 × 2 matrix A =
  • a11

a12 a21 a22

  • ,

and the two vectors u =

  • a11

a21

  • and

v =

  • a12

a22

  • then det(A) is the oriented area of the parallelogram formed by (

u, v) Oriented area is positive if u to v requires a counterclockwise rotation. Otherwise oriented area is negative.

50

slide-51
SLIDE 51

Determinants of 3 × 3 matrices

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33  , and the three vectors u =   a11 a21 a31  , v =   a12 a22 a23   and w =   a13 a23 a33   then det(A) is the oriented volume of the parallelepiped formed by ( u, v, w) Oriented volume is positive if ( u, v, w) forms a right-handed co-ordinate system. Otherwise

  • riented volume is negative.

51

slide-52
SLIDE 52

Determinants of 3 × 3 matrices

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33  , and the three vectors u =   a11 a21 a31  , v =   a12 a22 a23   and w =   a13 a23 a33   then det(A) is the oriented volume of the parallelepiped formed by ( u, v, w) Oriented volume is positive if ( u, v, w) forms a right-handed co-ordinate system. Otherwise

  • riented volume is negative.
  • Q. How to determine (

u, v, w)’s handedness?

52

slide-53
SLIDE 53

Cross product and handedness of a co-ordinate system

  • Right-handed co-ordinate system: ˆ

x × ˆ y = ˆ z, ˆ y × ˆ z = ˆ x, ˆ z × ˆ x = ˆ y i.e., (ˆ x × ˆ y) · ˆ z > 0 etc. (this is what we will use)

  • Left-handed co-ordinate system: ˆ

x × ˆ y = −ˆ z, ˆ y × ˆ z = −ˆ x, ˆ z × ˆ x = −ˆ y i.e., (ˆ x × ˆ y) · ˆ z < 0 etc.

53

slide-54
SLIDE 54

Determinants of 3 × 3 matrices

  • Consider the 3 × 3 matrix A =

  a11 a12 a13 a21 a22 a23 a31 a32 a33  , and the three vectors u =   a11 a21 a31  , v =   a12 a22 a23   and w =   a13 a23 a33   then det(A) is the oriented volume of the parallelepiped formed by ( u, v, w) Oriented volume is positive if ( u, v, w) forms a right-handed co-ordinate system. Otherwise

  • riented volume is negative.
  • Q. How to determine (

u, v, w)’s handedness?

  • A. Check if (

u × v) · w is > < 0

54

slide-55
SLIDE 55

Determinants of n × n matrices

  • Consider the n × n matrix A =

    a11 a12 a13 . . . a21 a22 a23 . . . a31 a32 a33 . . . . . . . . . . . . . . .    , and the vectors u1 =     a11 a21 a31 . . .    , u2 =     a12 a22 a23 . . .    , u3 =     a13 a23 a33 . . .    , . . . then det(A) is the oriented volume of the n-dimensional parallelepiped

  • Q. What is the determinant when, e.g.,

u3 = λ u1 + µ u2?

55

slide-56
SLIDE 56

Determinants of n × n matrices

  • Consider the n × n matrix A =

    a11 a12 a13 . . . a21 a22 a23 . . . a31 a32 a33 . . . . . . . . . . . . . . .    , and the vectors u1 =     a11 a21 a31 . . .    , u2 =     a12 a22 a23 . . .    , u3 =     a13 a23 a33 . . .    , . . . then det(A) is the oriented volume of the n-dimensional parallelepiped

  • Q. What is the determinant when, e.g.,

u3 = λ u1 + µ u2?

  • A. 0 (use the oriented volume argument!)

56

slide-57
SLIDE 57

Introduction to transformations

57

slide-58
SLIDE 58

Remember...

58

slide-59
SLIDE 59

Remember...

  • Operations defined: they can transform vectors!

− use them to project, scale, reflect, shear, rotate.... objects (objects means objects one point at a time)

  • Point transformations: P → P ′ (also, active transformations)

[point (x, y, z) represented as vector   x y z   drawn from the origin]

59

slide-60
SLIDE 60

That brings us to... active vs. passive transformations

60

slide-61
SLIDE 61

That brings us to... active vs. passive transformations

point transformation co-ordinate transformation (aka active transformation) (aka passive transformation)

61

slide-62
SLIDE 62

Point, or active transformations

62

slide-63
SLIDE 63

Translation

63

slide-64
SLIDE 64

Translation: a matrix operation?

  • We translate a point P (x, y, z) by (ax, ay, az)

i.e., x′ = x + ax, y′ = y + ay, z′ = z + az

  • Q. How do we express this transformation as a matrix operation?

[think of using (x, y, z) as a vector v from the origin]

64

slide-65
SLIDE 65

Translation: a matrix operation

  • We translate a point P (x, y, z) by (ax, ay, az)

i.e., x′ = x + ax, y′ = y + ay, z′ = z + az A.     x′ y′ z′ 1     =     1 ax 1 ay 1 az 1    

  • Mt(

a)

    x y z 1    ; a =   ax ay az  

65

slide-66
SLIDE 66

Translation: a matrix operation

  • We translate a point P (x, y, z) by (ax, ay, az)

i.e., x′ = x + ax, y′ = y + ay, z′ = z + az A.     x′ y′ z′ 1    

  • wt

=     1 ax 1 ay 1 az 1    

  • Mt(

a)

    x y z 1    

extended vector

; a =   ax ay az  

  • From now on, will use the extended vector to reach P from the origin

i.e., we add a fictitious dimension, meaning: ˆ x =     1    , ˆ y =     1    , ˆ z =     1    , ˆ f =     1    

66

slide-67
SLIDE 67

How to think about an extended vector for 2D

  • Note: A “real” vector

v, by construction, satisfies v · ˆ f = 0 e.g., the (2+1)D representation of a real vector in 2D is   vx vy  

67

slide-68
SLIDE 68

Summary

  • Why? The operations defined for matrices make them special

− matrix dimensions, special matrices (diagonal, identity, null)

  • Matrix operations (addition, scalar multiplication, subtraction,

matrix multiplication, transpose)

  • Determinants (only for square matrices!)
  • Adjoint/adjugate and inverse of matrices (only for square matrices!)
  • Geometric interpretation of determinants
  • Introduction to transformations

− translation and the fictitious coordinate

  • Next class: transformations (much more detailed), with matrices

68

slide-69
SLIDE 69

Finally, references...

  • Book chapter 5: Linear algebra (leave out Sec. 5.4)

69