Graphics 2009/2010, period 1 Lecture 4 Matrices
m n matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse The system of m linear equations in n variables x 1, x 2,..., x n a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 22 x 2 + + a 2n x n = b 2. a m1 x 1 + a m2 x 2 + + a mn x n = b m can be written as a matrix equation by Ax = b, or in full a 11 a 12 a 1n x 1 b 1 a 21 a 22 a 2n x 2....... = b 2. a m1 a m2 a mn x n b m
m n matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse The matrix a 11 a 12 a 1n a 21 a 22 a 2n A =...... a m1 a m2 a mn has m rows and n columns, and is called an m n matrix.
Special cases Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse A square matrix (for which m = n) is called a diagonal matrix if all elements a ij for which i j are zero. If all elements a ii are one, then the matrix is called an identity matrix, denoted with I m (depending on the context, the subscript m may be left out). 1 0 0 0 1 0 I =...... 0 0 1 If all matrix entries are zero, then the matrix is called a zero matrix, denoted with 0.
Matrix addition Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse For two matrices A and B, we have A + B = C, with c ij = a ij + b ij : 1 4 7 10 8 14 2 5 + 8 11 = 10 16 3 6 9 12 12 18 Q: what are the conditions for the dimensions of the matrices A and B? Q: how do we define subtraction?
Matrix multiplication Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Multiplying a matrix with a scalar is defined as follows: ca = B, with b ij = ca ij. For example, 1 2 3 2 4 6 2 4 5 6 = 8 10 12 7 8 9 14 16 18
Matrix multiplication Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Multiplying two matrices is a bit more involved. We have AB = C with c ij = n k=1 a ikb kj. For example, ( 6 5 1 3 2 1 8 4 ) 1 0 0 ( ) 1 1 0 6 2 2 5 0 2 = 37 5 16 0 1 0
Matrix multiplication Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse AB = C with c ij = n k=1 a ikb kj. Q: what are the conditions for the dimensions of A and B? Q: what are the dimensions of C?
Properties of matrix multiplication Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Matrix multiplication is associative and distributive over addition: (AB)C = A(BC) A(B + C) = AB + AC (A + B)C = AC + BC However, matrix multiplication is not commutative: in general, AB BA.
Properties of matrix multiplication Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Matrix multiplication is not commutative: in general, AB BA. Also: if AB = AC, it doesn t necessarily follow that B = C (even if A is not the null matrix).
Identity and zero matrix revisited Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Identity matrix I m : 1 0 0 0 1 0 I =...... 0 0 1 Zero matrix 0:
Transposed matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse The transpose A T of an m n matrix A is an n m matrix that is obtained by interchanging the rows and columns of A: a 11 a 12 a 1n a 21 a 22 a 2n A =...... a m1 a m2 a mn a 11 a 21 a m1 A T a 12 a 22 a m2 =...... a 1n a 2n a mn
Transposed matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse Example: A = ( 1 2 ) 3 4 5 6 1 4 A T = 2 5 3 6
Transposed matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse For the transpose of the product of two matrices we have (AB) T = B T A T
Transposed matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse For the transpose of the product of two matrices we have (AB) T = B T A T
The dot product revisited Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse If we regard (column) vectors as matrices, we see that the inproduct of two vectors can be written as u v = u T v: 1 4 2 5 = ( 1 2 3 ) 4 5 = 32 3 6 6 (A 1 1 matrix is simply a number, and the brackets are omitted.)
Inverse matrices Matrices Definitions Diagonal, Identity, and zero matrices Addition Multiplication Transpose and inverse The inverse of a matrix A is a matrix A 1 such that AA 1 = I. Only square matrices possibly have an inverse. Note that the inverse of A 1 is A, so we have AA 1 = A 1 A = I
Solving systems of linear equations Inverting matrices Matrices are a convenient way of representing systems of linear equations: a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 22 x 2 + + a 2n x n = b 2 a m1 x 1 + a m2 x 2 + + a mn x n = b m If such a system has a unique solution, it can be solved with..
Solving systems of linear equations Inverting matrices Permitted operations in are interchanging two rows. multiplying a row with a (non-zero) constant. adding a multiple of another row to a row.
Solving systems of linear equations Inverting matrices Matrices are not necessary for, but very convenient, especially augmented matrices. The augmented matrix corresponding to the system of equations on the previous slides is a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2....... a m1 a m2 a mn b m
Solving systems of linear equations Inverting matrices : example Suppose we want to solve the following system: x + y + 2z = 17 2x + y + z = 15 x + 2y + 3z = 26 Q: what is the geometric interpretation of this system?
Solving systems of linear equations Inverting matrices : example Applying the rules in a clever order, we get 1 1 2 17 1 1 2 17 2 1 1 15 0 1 3 19 1 2 3 26 0 1 1 9 1 1 2 17 0 1 3 19 0 1 1 9 1 0 1 2 0 1 3 19 0 0 1 5 1 0 1 2 0 1 3 19 0 0 2 10 1 0 0 3 0 1 0 4 0 0 1 5
Solving systems of linear equations Inverting matrices : example The interpretation of the last augmented matrix 1 0 0 3 0 1 0 4 0 0 1 5 is the very convenient system of linear equations x = 3 y = 4 z = 5 Q: what is the geometric interpretation of this solution?
Solving systems of linear equations Inverting matrices Geom. interpretations: intersection of 2 planes Q: what is the geometric interpretation of this system? 1st: intersection of 2 planes
Solving systems of linear equations Inverting matrices Geom. interpretations: intersection of 3 planes
Solving systems of linear equations Inverting matrices Q: what if a system can not be reduced to a triangular form? Q: does this always mean that their is no valid solution?
Solving systems of linear equations Inverting matrices Note: In the literature you also find a slightly different procedure 1st step: Put 0 s in the lower triangle... 2nd step:.. then work your way back up 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Solving systems of linear equations Inverting matrices : inverting matrices The same procedure can also be used to invert matrices.
Solving systems of linear equations Inverting matrices : inverting matrices Example: 1 1 2 1 0 0 1 3 4 0 1 0 0 2 5 0 0 1 1 1 2 1 0 0 0 2 2 1 1 0 0 2 5 0 0 1 1 1 2 1 0 0 1 0 1 1 1 0 1 1 1 2 1 2 0 1 2 2 0 0 1 1 1 1 2 2 0 0 2 5 0 0 1 0 0 3 1 1 1 1 0 1 1 1 2 1 7 2 0 1 0 0 0 1 1 1 6 1 6 2 6 1 2 2 0 0 1 0 5 5 1 0 0 1 3 1 6 6 2 6 1 2 3 3 0 0 1 6 2 2 6 6
Solving systems of linear equations Inverting matrices : inverting matrices The last augmented matrix tells us that the inverse of 1 1 2 1 3 4 0 2 5 equals 7 1 2 1 5 5 2 6 2 2 2
Matrices Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II The determinant of a matrix is the signed volume spanned by the column vectors. The determinant det A of a matrix A is also written as A. For example, ( ) a11 a A = 12 a 21 a 22 det A = A = a 11 a 12 a 21 a 22 (a 12, a 22 ) (a 11, a 21 )
Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II : geometric interpretation In 2D: deta is the oriented area of the parallelogram defined by the 2 vectors. det A = A = a 11 a 12 a 21 a 22 (a 12, a 22 ) In 3D: deta is the oriented area of the parallelepiped defined by the 3 vectors. (a 11, a 21 )
Computing determinants Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II can be computed as follows: The determinant of a matrix is the sum of the products of the elements of any row or column of the matrix with their cofactors If only we knew what cofactors are...
Cofactors Matrices Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Take a deep breath... The cofactor of an entry a ij in an n n matrix a is the determinant of the (n 1) (n 1) matrix A that is obtained from A by removing the i-th row and the j-th column, multiplied by 1 i+j. Right: long live recursion! Q: what is the bottom of this recursion?
Cofactors Matrices Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Example: for a 4 4 matrix A, the cofactor of the entry a 13 is A = a 11 a 12 a 13 a 14 a 21 a 22 a 23 a 24 a 31 a 32 a 33 a 34 a 41 a 42 a 43 a 44 a 21 a 22 a 24 a c 13 = a 31 a 32 a 34 a 41 a 42 a 44 and A = a 12 a c 12 + a 22a c 22 + a 32a c 32 + a 42a c 42
and cofactors Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Example 0 1 2 3 4 5 6 7 8 = 0 4 5 7 8 1 3 5 6 8 + 2 3 4 6 7 = 0(32 35) 1(24 30) + 2(21 24) = 0.
Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Systems of linear equations and determinants Consider our system of linear equations again: x + y + 2z = 17 2x + y + z = 15 x + 2y + 3z = 26 Such a system of n equations in n unknowns can be solved by using determinants. In general, if we have Ax = b, then x i = Ai A. where Ai is obtained from A by replacing the i-th column with b.
Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Systems of linear equations and determinants In general, if we have Ax = b, then x i = Ai A. where Ai is obtained from A by replacing the i-th column with b.
Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II and systems of linear equations So for our system x + y + 2z = 17 2x + y + z = 15 x + 2y + 3z = 26 we have x = 17 1 2 15 1 1 26 2 3 1 1 2 2 1 1 1 2 3 y = 1 17 2 2 15 1 1 26 3 1 1 2 2 1 1 1 2 3 z = 1 1 17 2 1 15 1 2 26 1 1 2 2 1 1 1 2 3
and inverse matrices Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II can also be used to compute the inverse A 1 of an invertible matrix A: A 1 = 1 A à where à is the adjoint of A, which is the transpose of the cofactor matrix of A. The cofactor matrix of A is obtained from A by replacing every entry a ij by its cofactor a c ij.
Computing determinants differently Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II 3x3 matrices: a b c d e f g h i = a e f h i... = (aei + bfg + cdg) (hfa + idb + gec)
Computing determinants differently Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II 3x3 matrices: a b c d e f g h i = a e f h i... = (aei + bfg + cdg) (hfa + idb + gec) 2x2 matrices: a b c d = ad bc Note: This does not generalize to higher dimensions!
Computing determinants differently Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II can also be computed by a method that resembles : if A is obtained from A by exchanging two rows, then A = A. if A is obtained from A by multiplying a row with a scalar c, then A = c A. if A is obtained from A by adding a multiple of one row of A to another, then A = A. I = 1 if A contains any row or column with only zeros, then A = 0
Computing determinants differently Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II Example 0 1 2 3 4 5 6 7 8 = 1 2 0 1 2 6 8 10 6 7 8 = 1 2 0 1 2 6 7 8 6 7 8 = 1 2 0 1 2 0 0 0 6 7 8 = 1 2 0 = 0.
Volume Computing determinants: cofactors Solving systems of linear equations II Inverting matrices II Computing determinants II