Announcements Wednesday, October 10 The second midterm is on Friday, October 19 That is one week from this Friday The exam covers 35, 36, 37, 39, 41, 42, 43, 44 (through today s material) WeBWorK 42, 43 are due today at 11:59pm The quiz on Friday covers 42, 43 You can go to other instructors office hours; see Canvas announcements
Section 44 Matrix Multiplication
Motivation Recall: we can turn any system of linear equations into a matrix equation Ax b This notation is suggestive Can we solve the equation by dividing by A? x?? b A Answer: Sometimes, but you have to know what you re doing Today we ll study matrix algebra: adding and multiplying matrices These are not so hard to do The important thing to understand today is the relationship between matrix multiplication and composition of transformations
More Notation for Matrices Let A be an m n matrix We write a ij for the entry in the ith row and the jth column It is called the ijth entry of the matrix The entries a 11, a 22, a 33, are the diagonal entries; they form the main diagonal of the matrix A diagonal matrix is a square matrix whose only nonzero entries are on the main diagonal The n n identity matrix I n is the diagonal matrix with all diagonal entries equal to 1 It is special because I nv v for all v in R n a 11 a 1j a 1n a i1 a ij a in a m1 a mj a mn jth column ith row ( ) a a 11 a 12 a 11 a 12 13 a a 21 a 22 a 21 a 22 23 a 31 a 32 a 11 0 0 0 a 22 0 0 0 a 33 1 0 0 I 3 0 1 0 0 0 1
More Notation for Matrices Continued The zero matrix (of size m n) is the ( ) m n matrix 0 with all zero entries 0 0 0 0 0 0 0 The transpose of an m n matrix A is the n m matrix A T whose rows are the columns of A In other words, the ij entry of A T is a ji A ( ) a 11 a 12 a 13 a 21 a 22 a 23 flip A T a 11 a 21 a 12 a 22 a 13 a 23
Addition and Scalar Multiplication You add two matrices component by component, like with vectors ( ) ( ) ( ) a11 a 12 a 13 b11 b 12 b 13 a11 + b 11 a 12 + b 12 a 13 + b 13 + a 21 a 22 a 23 b 21 b 22 b 23 a 21 + b 21 a 22 + b 22 a 23 + b 23 Note you can only add two matrices of the same size You multiply a matrix by a scalar by multiplying each component, like with vectors ( ) ( ) a11 a 12 a 13 ca11 ca 12 ca 13 c a 21 a 22 a 23 ca 21 ca 22 ca 23 These satisfy the expected rules, like with vectors: A + B B + A (A + B) + C A + (B + C) c(a + B) ca + cb (c + d)a ca + da (cd)a c(da) A + 0 A
Matrix Multiplication Beware: matrix multiplication is more subtle than addition and scalar multiplication must be equal Let A be an m n matrix and let B be an n p matrix with columns v 1, v 2, v p: B v 1 v 2 v p The product AB is the m p matrix with columns Av 1, Av 2,, Av p: The equality is a definition AB def Av 1 Av 2 Av p In order for Av 1, Av 2,, Av p to make sense, the number of columns of A has to be the same as the number of rows of B Note the sizes of the product! Example ( ) 1 2 3 1 3 2 2 4 5 6 3 1 ( 1 2 3 4 5 6 ( 14 ) 10 32 28 ) 1 2 3 ( ) 1 2 3 3 2 4 5 6 1
The Row-Column Rule for Matrix Multiplication Recall: A row vector of length n times a column vector of length n is a scalar: ( ) a1 a n b 1 b n r m a 1b 1 + + a nb n Another way of multiplying a matrix by a vector is: r 1 r 1x Ax x r mx On the other hand, you multiply two matrices by AB A c 1 c p Ac 1 Ac p It follows that r 1 r 1c 1 r 1c 2 r 1c p AB c 1 c p r 2c 1 r 2c 2 r 2c p r m r mc 1 r mc 2 r mc p
The Row-Column Rule for Matrix Multiplication The ij entry of C AB is the ith row of A times the jth column of B: c ij (AB) ij a i1 b 1j + a i2 b 2j + + a in b nj This is how everybody on the planet actually computes AB Diagram (AB C): a 11 a 1k a 1n b 11 b 1j b 1p c 11 c 1j c 1p a i1 a ik a in b k1 b kj b kp c i1 c ij c ip a m1 a mk a mn b n1 b nj b np c m1 c mj c mp jth column ij entry Example ( ) 1 2 3 1 3 ( ) ( ) 2 2 1 1 + 2 2 + 3 3 14 4 5 6 3 1 ( ) 1 2 3 1 3 ( ) ( ) 2 2 4 5 6 4 1 + 5 2 + 6 3 32 3 1 ith row
Composition of Transformations Why is this the correct definition of matrix multiplication? Definition Let T : R n R m and U : R p R n be transformations The composition is the transformation T U : R p R m defined by T U(x) T (U(x)) This makes sense because U(x) (the output of U) is in R n, which is the domain of T (the inputs of T ) [interactive] x U T U U(x) T T U(x) R p R n R m Fact: If T and U are linear then so is T U Guess: If A is the matrix for T, and B is the matrix for U, what is the matrix for T U?
Composition of Linear Transformations Let T : R n R m and U : R p R n be linear transformations Let A and B be their matrices: A T (e 1) T (e 2) T (e n) B U(e 1) U(e 2) U(e p) Question U(e 1 ) Be 1 is the first column of B What is the matrix for T U? the first column of AB is A(Be 1 ) We find the matrix for T U by plugging in the unit coordinate vectors: T U(e 1) T (U(e 1)) T (Be 1) A(Be 1) (AB)e 1 For any other i, the same works: T U(e i ) T (U(e i )) T (Be i ) A(Be i ) (AB)e i This says that the ith column of the matrix for T U is the ith column of AB The matrix of the composition is the product of the matrices!
Composition of Linear Transformations Remark We can also add and scalar multiply linear transformations: T, U : R n R m T + U : R n R m (T + U)(x) T (x) + U(x) In other words, add transformations pointwise T : R n R m c in R ct : R n R m (ct )(x) c T (x) In other words, scalar-multiply a transformation pointwise If T has matrix A and U has matrix B, then: T + U has matrix A + B ct has matrix ca So, transformation algebra is the same as matrix algebra
Composition of Linear Transformations Example Let T : R 3 R 2 and U : R 2 R 3 be the matrix transformations ( ) 1 0 1 1 0 T (x) x U(x) 0 1 x 0 1 1 1 1 Then the matrix for T U is ( 1 1 0 0 1 1 ) 1 0 0 1 1 1 [interactive] ( ) 1 1 1 2
Composition of Linear Transformations Another Example Let T : R 2 R 2 be rotation by 45, and let U : R 2 R 2 scale the x-coordinate by 15 Let s compute their standard matrices A and B: ) T (e 1 ) 45 1 2 1 2 T (e 1) 1 ( 1 2 1 T (e 2) 1 ( ) 1 2 1 1 T 2 (e 2 ) 1 2 45 U(e 1 ) ( ) 15 U(e 1) 0 ( ) U(e 2 ) 0 U(e 2) 1 A 1 ( ) 1 1 2 1 1 B ( ) 15 0 0 1
Composition of Linear Transformations Another example, continued So the matrix C for T U is C AB 1 ( ) ( ) 1 1 15 0 2 1 1 0 1 ( ( ) ( ) ( ) ( ) ) 1 1 1 15 1 1 1 0 2 1 1 0 2 1 ( ) 15 1 1 1 1 2 15 1 Check: [interactive: e 1 ] [interactive: e 2 ] e 1 U(e 1 ) T (U(e 1 )) T U(e 1) 1 ( ) 15 2 15 e 2 U(e 2 ) T (U(e 2 )) T U(e2) 1 ( ) 1 2 1 C 1 ( ) 15 1 2 15 1
Composition of Linear Transformations Another example Let T : R 3 R 3 be projection onto the yz-plane, and let U : R 3 R 3 be reflection over the xy-plane Let s compute their standard matrices A and B: yz e 1 T (e 1 ) xy yz T (e 2 ) xy yz T (e 3 ) xy 0 0 0 A 0 1 0 0 0 1 yz U(e 1 ) xy yz U(e 2 ) xy yz U(e 3 ) e 3 xy 1 0 0 B 0 1 0 0 0 1
Composition of Linear Transformations Another example, continued So the matrix C for T U is 0 0 0 1 0 0 0 0 0 C AB 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 Check: we did this last time [interactive: e 1 ] [interactive: e 2 ] [interactive: e 3 ]
Poll Poll Do there exist nonzero matrices A and B with AB 0? Yes! Here s an example: ( ) ( ) 1 0 0 0 1 0 1 1 ( ( 1 0 1 0 ) ( 0 1 ) ( 1 0 1 0 ) ( ) ) 0 1 ( ) 0 0 0 0
Properties of Matrix Multiplication Mostly matrix multiplication works like you d expect Suppose A has size m n, and that the other matrices below have the right size to make multiplication work A(BC) (AB)C A(B + C) (AB + AC) (B + C)A BA + CA c(ab) (ca)b c(ab) A(cB) I ma A AI n A Most of these are easy to verify Associativity is A(BC) (AB)C It is a pain to verify using the row-column rule! Much easier: use associativity of linear transformations: S (T U) (S T ) U This is a good example of an instance where having a conceptual viewpoint saves you a lot of work Recommended: Try to verify all of them on your own
Properties of Matrix Multiplication Caveats Warnings! AB is usually not equal to BA ( ) ( ) ( 0 1 2 0 0 1 1 0 0 1 2 0 ) ( 2 0 0 1 In fact, AB may be defined when BA is not AB AC does not imply B C, even if A 0 ( ) ( ) ( ) 1 0 1 2 1 2 0 0 3 4 0 0 ) ( ) 0 1 1 0 ( 1 0 0 0 ) ( ) 1 2 5 6 ( ) 0 2 1 0 AB 0 does not imply A 0 or B 0 ( ) ( ) ( ) 1 0 0 0 0 0 1 0 1 1 0 0
Powers of a Matrix Suppose A is a square matrix Then A A makes sense, and has the same size Then A (A A) also makes sense and has the same size Definition Let n be a positive whole number and let A be a square matrix The nth power of A is the product A n A A A }{{} n times Example A ( ) ( ) ( ) ( ) 1 1 A 2 1 1 1 1 1 2 0 1 0 1 0 1 0 1 ( ) ( ) ( ) A 3 1 2 1 1 1 3 0 1 0 1 0 1 ( ) ( ) ( ) A n 1 n 1 1 1 1 n 0 1 0 1 0 1
Summary The product of an m n matrix and an n p matrix is an m p matrix I showed you two ways of computing the product Composition of linear transformations corresponds to multiplication of matrices You have to be careful when multiplying matrices together, because things like commutativity and cancellation fail You can take powers of square matrices