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 • Geometric interpretation of determinants • Introduction to transformations 2
Spatial transformations − part II of the course 3
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
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
Bigger scheme of things: three upcoming maths lectures 6
Bigger scheme of things: three upcoming maths lectures 7
Bigger scheme of things: three upcoming maths lectures • It’s been a choice to make a clean separation this way! 8
What is a matrix? 9
What is a matrix? 10
What is a matrix? • You’ll store it on a computer as a two-dimensional array: arr[3][3] 11
Why matrices? • Example: (more about that in the next lecture) 12
Matrices 13
Matrices • Dimension of the above matrix: m × n − when m = n , the matrix is called a square matrix − a ij ( i ∈ [1 , m ] , j ∈ [1 , n ]) are the matrix elements/coefficients − shorthand notation A = { a ij } 14
Matrices • Dimension of the above matrix: m × n − when m = n , the matrix is called a square matrix − a ij ( i ∈ [1 , m ] , j ∈ [1 , n ]) are the matrix elements/coefficients − shorthand notation A = { a ij } • A d -dimensional vector is a d × 1 matrix − an m × n matrix: n vertical concatenation of m -dimensional vectors 15
Matrices • Dimension of the above matrix: m × n − when m = n , the matrix is called a square matrix − a ij ( i ∈ [1 , m ] , j ∈ [1 , n ]) are the matrix elements/coefficients − shorthand notation A = { a ij } • 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
Special matrices • Diagonal matrix: square matrix with a ij = 0 for i � = j ; e.g., (a diagonal matrix is by definition a square matrix) 17
Special matrices • Diagonal matrix: square matrix with a ij = 0 for i � = j ; e.g., (a diagonal matrix is by definition a square matrix) • Identity matrix: diagonal matrix with a ii = 1, e.g., (denoted by I , an identity matrix is also by definition a square matrix) 18
Special matrices • Diagonal matrix: square matrix with a ij = 0 for i � = j ; e.g., (a diagonal matrix is by definition a square matrix) • Identity matrix: diagonal matrix with a ii = 1, e.g., (denoted by I , an identity matrix is also by definition a square matrix) • Null matrix (denoted by Ø or O ): a ij = 0, e.g., 19
Matrix operations 20
Addition of matrices 21
Addition of matrices • Can only add matrices of same dimensions! 22
Scalar multiplication of matrices 23
Addition and scalar multiplication of matrices 24
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
Matrix multiplication • A and B are m × n and n × p dimensional matrices respectively then C = AB is an m × p -dimensional matrix 26
Matrix multiplication • A and B are m × n and n × p dimensional matrices respectively then C = AB is an m × p -dimensional matrix n � • matrix elements c ij = a ik b kj k =1 on a computer: c ij = 0; for ( k = 1; k < = n ; k ++ ) c ij += a ik b kj e.g., 27
Vector dot product as a matrix multiplication u 1 v 1 u 2 v 2 • Vectors � u = . and � v = . . . u d v d v 1 v 2 u · � v = [ u 1 u 2 . . . u d ] . = � v · � u = u 1 v 1 + u 2 v 2 + . . . + u d v d � . v d 28
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
Transpose of a matrix 30
Transpose of a matrix • A T = transpose( A ); ( A T ) T = A 31
Determinants and cofactors (only for square matrices!) 32
Determinants • Determinant of matrix A ≡ det( A ), or | A | ; a scalar quantity • Also as • Determinants and cofactors are inextricably linked 33
Determinant (1 × 1 matrices) • Determinant of a 1 × 1 matrix is the value of its element e.g., A = [ − 5], det( A ) = − 5 34
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) 35
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) = a 21 cof( a 21 ) + a 22 cof( a 22 ) 36
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) = a 21 cof( a 21 ) + a 22 cof( a 22 ) = a 11 cof( a 11 ) + a 21 cof( a 21 ) 37
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) = a 21 cof( a 21 ) + a 22 cof( a 22 ) = a 11 cof( a 11 ) + a 21 cof( a 21 ) = a 12 cof( a 12 ) + a 22 cof( a 22 ) 38
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) cof( a ij ) = ( − 1) i + j det(minor( a ij )) minor( a ij ) 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
Determinant (2 × 2 matrices) � � a 11 a 12 • Consider the 2 × 2 matrix A = a 21 a 22 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) cof( a ij ) = ( − 1) i + j det(minor( a ij )) minor( a ij ) 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( a 11 ) = det( a 22 ) = a 22 ; cof( a 12 ) = − det( a 12 ) = − a 21 det( A ) = a 11 a 22 − a 12 a 21 ; note also that det( A ) = det( A T ) • Example: 40
Determinant (3 × 3 matrices) a 11 a 12 a 13 • Consider the 3 × 3 matrix A = a 21 a 22 a 23 a 31 a 32 a 33 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) + a 13 cof( a 13 ) 41
Determinant (3 × 3 matrices) a 11 a 12 a 13 • Consider the 3 × 3 matrix A = a 21 a 22 a 23 a 31 a 32 a 33 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) + a 13 cof( a 13 ) = a 21 cof( a 21 ) + a 22 cof( a 22 ) + a 23 cof( a 23 ) 42
Determinant (3 × 3 matrices) a 11 a 12 a 13 • Consider the 3 × 3 matrix A = a 21 a 22 a 23 a 31 a 32 a 33 det( A ) = a 11 cof( a 11 ) + a 12 cof( a 12 ) + a 13 cof( a 13 ) � � � � � � a 22 a 23 a 21 a 23 a 21 a 22 � � � � � � = a 11 � − a 12 � + a 13 � � � � � � a 32 a 33 a 31 a 33 a 31 a 32 � � � � = a 11 a 22 a 33 − a 11 a 23 a 32 + a 12 a 23 a 31 − a 12 a 21 a 33 + a 13 a 21 a 32 − a 13 a 22 a 31 = det( A T ) • Example: 43
Determinant (3 × 3 matrices), Sarrus’ rule 44
Determinant (3 × 3 matrices), Sarrus’ rule • Does not work for 2 × 2, 4 × 4, ... matrices 45
Adjoint/adjugate and inverse (only for square matrices!) 46
Cofactor matrix and adjoint/adjugate • Cofactor matrix C = { c ij } of matrix A = { a ij } i.e., c ij = cof( a ij ) example: • Adjoint/adjugate( A ) ≡ adj( A ) = transpose(cof(A)) 47
Inverse of a matrix • Inverse of A ≡ A − 1 = adj( A ) | A | • Has the property AA − 1 = A − 1 A = I (identity matrix) • Inverse does not exist if | A | = 0; then A is a singular matrix 48
Geometric interpretation of determinants 49
Determinants of 2 × 2 matrices � � a 11 a 12 • Consider the 2 × 2 matrix A = , a 21 a 22 � � � � a 11 a 12 and the two vectors � u = and � v = a 21 a 22 then det( A ) is the oriented area of the parallelogram formed by ( � v ) u,� Oriented area is positive if � u to � v requires a counterclockwise rotation. Otherwise oriented area is negative. 50
Determinants of 3 × 3 matrices a 11 a 12 a 13 • Consider the 3 × 3 matrix A = , a 21 a 22 a 23 a 31 a 32 a 33 a 11 a 12 a 13 and � and the three vectors � u = , � v = w = a 21 a 22 a 23 a 31 a 23 a 33 then det( A ) is the oriented volume of the parallelepiped formed by ( � w ) u,� v, � Oriented volume is positive if ( � u , � v , � w ) forms a right-handed co-ordinate system. Otherwise oriented volume is negative. 51
Recommend
More recommend