1 00:00:00,000 --> 00:00:00,670 2 00:00:00,670 --> 00:00:02,379 Well, after the last video, hopefully, we're a little 3 00:00:02,379 --> 00:00:04,330 familiar with how you add matrices. 4 00:00:04,330 --> 00:00:07,150 So now let's learn how to multiply matrices. 5 00:00:07,150 --> 00:00:11,449 And keep in mind, these are human-created definitions for 6 00:00:11,449 --> 00:00:12,839 matrix multiplication. 7 00:00:12,839 --> 00:00:15,000 We could have come up with completely different ways to 8 00:00:15,000 --> 00:00:15,449 multiply it. 9 00:00:15,449 --> 00:00:18,509 But I encourage you to learn this way because it'll help 10 00:00:18,510 --> 00:00:19,810 you in math class. 11 00:00:19,809 --> 00:00:22,099 And we will see later that there's actually a lot of 12 00:00:22,100 --> 00:00:24,730 applications that come out of this type of matrix 13 00:00:24,730 --> 00:00:25,289 multiplication. 14 00:00:25,289 --> 00:00:26,339 So let me think of two matrices. 15 00:00:26,339 --> 00:00:30,320 I will do two 2 by 2 matrices, and let's multiply them. 16 00:00:30,320 --> 00:00:34,500 Let's say-- let me pick some random numbers: 2, 17 00:00:34,500 --> 00:00:40,530 minus 3, 7, and 5. 18 00:00:40,530 --> 00:00:42,980 And I'm going to multiply that matrix, or that table of 19 00:00:42,979 --> 00:00:56,439 numbers, times 10, minus 8-- let me pick a good number 20 00:00:56,439 --> 00:01:03,979 here-- 12, and then minus 2. 21 00:01:03,979 --> 00:01:07,399 So now there might be a strong temptation-- and you know in 22 00:01:07,400 --> 00:01:11,330 some ways it's not even an illegitimate temptation-- to 23 00:01:11,329 --> 00:01:13,879 do the same thing with multiplication that we did 24 00:01:13,879 --> 00:01:17,519 with addition, to just multiply the corresponding 25 00:01:17,519 --> 00:01:20,579 terms. So you might be tempted to say, well, the first term 26 00:01:20,579 --> 00:01:23,159 right here, the 1, 1 term, or in the first row and first 27 00:01:23,159 --> 00:01:25,069 column, is going to be 2 times 10. 28 00:01:25,069 --> 00:01:26,969 And this term is going to be minus 3 times 29 00:01:26,969 --> 00:01:28,230 minus 8 and so forth. 30 00:01:28,230 --> 00:01:30,329 And that's how we added matrices so maybe it's a 31 00:01:30,329 --> 00:01:33,510 natural extension to multiply matrices the same way. 32 00:01:33,510 --> 00:01:36,180 And that is legitimate. 33 00:01:36,180 --> 00:01:38,530 One could define it that way, but that's not the way it is 34 00:01:38,530 --> 00:01:39,409 in the real world. 35 00:01:39,409 --> 00:01:40,379 And the way in the real world, 36 00:01:40,379 --> 00:01:42,469 unfortunately, is more complex. 37 00:01:42,469 --> 00:01:44,980 But if you look at a bunch of examples I 38 00:01:44,980 --> 00:01:45,670 think you'll get it. 39 00:01:45,670 --> 00:01:47,460 And you'll learn that it's actually fairly 40 00:01:47,459 --> 00:01:47,979 straightforward. 41 00:01:47,980 --> 00:01:48,984 So how do we do it? 42 00:01:48,984 --> 00:01:53,289 So this first term that's in the first row and its first 43 00:01:53,290 --> 00:01:58,050 column, is equal to essentially this first row's 44 00:01:58,049 --> 00:02:01,379 vector-- no, this first row vector-- 45 00:02:01,379 --> 00:02:04,789 times this column vector. 46 00:02:04,790 --> 00:02:08,229 Now what do I mean by that, right? 47 00:02:08,229 --> 00:02:11,320 So it's getting it's row information from the first 48 00:02:11,319 --> 00:02:14,169 matrix's row, and it's getting it's column information from 49 00:02:14,169 --> 00:02:16,319 the second matrix's column. 50 00:02:16,319 --> 00:02:17,189 So how do I do that? 51 00:02:17,189 --> 00:02:18,859 If you're familiar with dot product, it's essentially the 52 00:02:18,860 --> 00:02:20,930 dot product of these two matrices. 53 00:02:20,930 --> 00:02:24,819 Or without saying it that fancy, it's just this: it's 2 54 00:02:24,819 --> 00:02:31,889 times 10, so 2-- I'm going to write small-- times 10, plus 55 00:02:31,889 --> 00:02:39,639 minus 3 times 12. 56 00:02:39,639 --> 00:02:42,629 I'm going to run out of space. 57 00:02:42,629 --> 00:02:45,599 And so what's this second term over here? 58 00:02:45,599 --> 00:02:49,169 Well, we're still on the first row of the product vector but 59 00:02:49,169 --> 00:02:50,349 now we're on the second column. 60 00:02:50,349 --> 00:02:51,909 We get our column information from here. 61 00:02:51,909 --> 00:02:58,799 So let's pick a good color-- this is a slightly different 62 00:02:58,800 --> 00:03:00,530 shade of purple. 63 00:03:00,530 --> 00:03:04,110 So now this is going to be-- I'll do that in another 64 00:03:04,110 --> 00:03:10,580 color-- 2 times minus 8-- let me just write out the number-- 65 00:03:10,580 --> 00:03:18,810 2 times minus 8 is minus 16, plus minus 3 times minus 2-- 66 00:03:18,810 --> 00:03:21,159 what's minus 3 times minus 2? 67 00:03:21,159 --> 00:03:26,400 That is plus 6, right? 68 00:03:26,400 --> 00:03:28,870 So that's in row 1 column 2. 69 00:03:28,870 --> 00:03:30,590 It's minus 16 plus 6. 70 00:03:30,590 --> 00:03:31,830 And then let's come down here. 71 00:03:31,830 --> 00:03:33,920 So now we're in the second row. 72 00:03:33,919 --> 00:03:35,549 So now we're going to use-- we're getting our row 73 00:03:35,550 --> 00:03:37,930 information from the first matrix-- I know this is 74 00:03:37,930 --> 00:03:41,379 confusing and I feel bad for you right now, but we're going 75 00:03:41,379 --> 00:03:45,229 to a bunch of examples and I think it'll make sense. 76 00:03:45,229 --> 00:03:49,060 So this term-- the bottom left term-- is going to be this row 77 00:03:49,060 --> 00:03:50,310 times this column. 78 00:03:50,310 --> 00:03:58,009 So it's going to be 7 times 10, so 70, plus 7 times 10 79 00:03:58,009 --> 00:04:05,649 plus 5 times 12, plus 60. 80 00:04:05,650 --> 00:04:09,289 And then the bottom right term is going to be 7 times minus 81 00:04:09,289 --> 00:04:19,539 8, which is minus 56 plus 5 times minus 2. 82 00:04:19,540 --> 00:04:22,900 So that's minus 10. 83 00:04:22,899 --> 00:04:31,289 So the final product is going to be 2 times 10 is 20, minus 84 00:04:31,290 --> 00:04:41,040 36, so that's minus 16 plus 6, that's 10. 85 00:04:41,040 --> 00:04:42,220 90-- was that what I said? 86 00:04:42,220 --> 00:04:46,390 No, it was-- 70, plus 60, that's 130. 87 00:04:46,389 --> 00:04:55,579 And then minus 56 minus 10, so minus 66. 88 00:04:55,579 --> 00:04:56,399 So there you have it. 89 00:04:56,399 --> 00:04:59,019 We just multiplied this matrix times this matrix. 90 00:04:59,019 --> 00:05:00,359 Let me do another example. 91 00:05:00,360 --> 00:05:03,490 And I think I'll actually squeeze it on this side so 92 00:05:03,490 --> 00:05:06,105 that we can write this side out a little bit more neatly. 93 00:05:06,105 --> 00:05:18,629 So let's take the matrix and now 1, 2, 3, 4, times the 94 00:05:18,629 --> 00:05:27,709 matrix 5, 6, 7, 8. 95 00:05:27,709 --> 00:05:30,199 Now we have much more space to work with so this should come 96 00:05:30,199 --> 00:05:32,759 out neater. 97 00:05:32,759 --> 00:05:37,459 OK, but I'm going to do the same thing, so to get this 98 00:05:37,459 --> 00:05:40,349 term right here-- the top left term-- we're going to take-- 99 00:05:40,350 --> 00:05:43,070 or the one that has row 1 column 1-- we're going to take 100 00:05:43,069 --> 00:05:52,050 the row 1 information from here, and the column 1 101 00:05:52,050 --> 00:05:54,439 information from here. 102 00:05:54,439 --> 00:05:56,069 So you can view it as this row vector 103 00:05:56,069 --> 00:05:57,120 times this column vector. 104 00:05:57,120 --> 00:06:01,680 So it results, 1 times 5 plus 2 times 7. 105 00:06:01,680 --> 00:06:07,730 106 00:06:07,730 --> 00:06:08,379 Right? 107 00:06:08,379 --> 00:06:09,610 There you go. 108 00:06:09,610 --> 00:06:12,520 And so this term, it'll be this row vector times this 109 00:06:12,519 --> 00:06:15,740 column vector-- let me do that in a different color-- will be 110 00:06:15,740 --> 00:06:20,550 1 times 6 plus 2 times 8. 111 00:06:20,550 --> 00:06:21,370 Let me write that down. 112 00:06:21,370 --> 00:06:28,590 So it's 1 times 6 plus 2 times 8. 113 00:06:28,589 --> 00:06:33,269 114 00:06:33,269 --> 00:06:34,719 Now we go down to the second row. 115 00:06:34,720 --> 00:06:38,130 And we get our row information from the first vector-- let me 116 00:06:38,129 --> 00:06:44,149 circle it with this color-- and it is 3 times 5 117 00:06:44,149 --> 00:06:45,519 plus 4 times 7. 118 00:06:45,519 --> 00:06:52,799 119 00:06:52,800 --> 00:06:54,759 And then we are in the bottom right, so we're in the bottom 120 00:06:54,759 --> 00:06:57,069 row and second column. 121 00:06:57,069 --> 00:06:59,349 So we get our row information from here and our column 122 00:06:59,350 --> 00:07:00,930 information from here. 123 00:07:00,930 --> 00:07:03,860 So it's 3 times 6 plus 4 times 8. 124 00:07:03,860 --> 00:07:10,300 125 00:07:10,300 --> 00:07:13,680 And if we simplify, this is 5 plus-- 126 00:07:13,680 --> 00:07:15,949 Well actually, let me just remind you where all the 127 00:07:15,949 --> 00:07:16,629 numbers came from. 128 00:07:16,629 --> 00:07:18,199 So we have that green color, right? 129 00:07:18,199 --> 00:07:25,889 This 1 and this 2, that's this 1 and this 2, 130 00:07:25,889 --> 00:07:28,620 this 1 and this 2. 131 00:07:28,620 --> 00:07:28,754 Right? 132 00:07:28,754 --> 00:07:30,329 And notice, these were in the first row and they're in the 133 00:07:30,329 --> 00:07:31,659 first row here. 134 00:07:31,660 --> 00:07:33,640 And this 5 and this 7? 135 00:07:33,639 --> 00:07:39,919 Well, that's this 5 and this 7, and this 5 and this 7. 136 00:07:39,920 --> 00:07:42,800 So, interesting. 137 00:07:42,800 --> 00:07:45,410 This was in column 1 of the second matrix and this is in 138 00:07:45,410 --> 00:07:47,780 column 1 in the product matrix. 139 00:07:47,779 --> 00:07:51,029 And similarly, the 6 and the 8. 140 00:07:51,029 --> 00:07:55,609 That's this 6, this 8, and then it's used here, this 6 141 00:07:55,610 --> 00:07:57,540 and this 8. 142 00:07:57,540 --> 00:08:00,250 And then finally this 3 and the 4 in the brown, so that's 143 00:08:00,250 --> 00:08:03,980 this 3, this 4, and this 3 and this 4. 144 00:08:03,980 --> 00:08:05,290 And we could of course simplify all of it. 145 00:08:05,290 --> 00:08:10,180 This was 1 times 5 plus 2 times 7, so that's 5 plus 14, 146 00:08:10,180 --> 00:08:15,410 so this is 19. 147 00:08:15,410 --> 00:08:19,200 This is 1 times 6 plus 2 times 8, so it's 6 plus 148 00:08:19,199 --> 00:08:22,329 16, so that's 22. 149 00:08:22,329 --> 00:08:26,379 This is 3 times 5 plus 4 times 7. 150 00:08:26,379 --> 00:08:32,908 So 15 plus 28, 38, 43-- if my math is correct-- and then we 151 00:08:32,908 --> 00:08:36,250 have 3 times 6 plus 4 times 8. 152 00:08:36,250 --> 00:08:44,220 So that's 18 plus 32, that's 50. 153 00:08:44,220 --> 00:08:45,980 So now let me ask you-- just so you know that the product 154 00:08:45,980 --> 00:08:47,690 matrix-- just write it neatly-- is 155 00:08:47,690 --> 00:08:53,610 19, 22, 43, and 50. 156 00:08:53,610 --> 00:08:55,100 So now let me ask you a question. 157 00:08:55,100 --> 00:08:58,810 When we did matrix addition we learned that if I had two 158 00:08:58,809 --> 00:09:03,209 matrices-- it didn't matter what order we added them in. 159 00:09:03,210 --> 00:09:06,970 So if we said, A plus B-- and these are matrices; that's why 160 00:09:06,970 --> 00:09:09,340 I'm making them all bold-- we said this is the same thing as 161 00:09:09,340 --> 00:09:12,330 B plus A, based on how we define matrix 162 00:09:12,330 --> 00:09:15,520 addition, B plus A. 163 00:09:15,519 --> 00:09:17,059 So now let me ask you a question. 164 00:09:17,059 --> 00:09:22,969 Is multiplying two matrices, is AB-- that's just means 165 00:09:22,970 --> 00:09:26,460 we're multiplying A and B-- is that the same thing as BA? 166 00:09:26,460 --> 00:09:30,090 167 00:09:30,090 --> 00:09:30,820 Does it matter? 168 00:09:30,820 --> 00:09:33,800 Does the order of the matrix multiplication matter? 169 00:09:33,799 --> 00:09:36,309 And so, I'll tell you right now, it actually matters a 170 00:09:36,309 --> 00:09:37,089 tremendous amount. 171 00:09:37,090 --> 00:09:39,550 And actually there are certain matrices that you can add in 172 00:09:39,549 --> 00:09:42,039 one direction that you can't add in the other-- oh, that 173 00:09:42,039 --> 00:09:47,299 you can multiply in one way but you can't multiply in the 174 00:09:47,299 --> 00:09:48,199 other order. 175 00:09:48,200 --> 00:09:50,754 And well, I'll show you that in an example-- but just to 176 00:09:50,754 --> 00:09:52,799 show that this isn't even equal for most matrices, I 177 00:09:52,799 --> 00:09:56,639 encourage you to multiply these two matrices in the 178 00:09:56,639 --> 00:09:57,110 other order. 179 00:09:57,110 --> 00:09:58,950 Actually let me do that. 180 00:09:58,950 --> 00:10:00,629 Let me do that really fast just to prove 181 00:10:00,629 --> 00:10:01,439 the point to you. 182 00:10:01,440 --> 00:10:02,830 So let me delete all this top part. 183 00:10:02,830 --> 00:10:06,040 184 00:10:06,039 --> 00:10:13,829 Let me delete all of it, and actually I can delete to this. 185 00:10:13,830 --> 00:10:15,960 So hopefully, you know that when I multiply this matrix 186 00:10:15,960 --> 00:10:17,850 times this matrix, I got this. 187 00:10:17,850 --> 00:10:20,250 So let me switch the order-- and I'll do it fairly fast 188 00:10:20,250 --> 00:10:23,139 just so as to not bore you-- so let me switch the order of 189 00:10:23,139 --> 00:10:24,149 the matrix multiplication. 190 00:10:24,149 --> 00:10:26,754 This is good as this is another example-- so I'm going 191 00:10:26,754 --> 00:10:36,740 to multiply this matrix: 5, 6, 7, 8, times this matrix-- and 192 00:10:36,740 --> 00:10:40,399 I just switched the order; and we're testing to see whether 193 00:10:40,399 --> 00:10:46,699 order matters-- 1, 2, 3, 4. 194 00:10:46,700 --> 00:10:49,009 Let's do it-- and I won't do all the colors and everything, 195 00:10:49,009 --> 00:10:49,689 I'll just do it systematically. 196 00:10:49,690 --> 00:10:54,330 I think you just have to see a lot of examples here-- So this 197 00:10:54,330 --> 00:10:56,410 first term gets its row information from the first 198 00:10:56,409 --> 00:10:58,809 matrix, column information from the second matrix. 199 00:10:58,809 --> 00:11:06,339 So it's 5 times 1 plus 6 times 3, so it's 5 times 1-- 200 00:11:06,340 --> 00:11:09,129 Let me just write, actually edit. 201 00:11:09,129 --> 00:11:17,649 I'm going to skip a step here-- OK so it's 5 times 1 202 00:11:17,649 --> 00:11:23,480 plus 6 times 3, plus 18. 203 00:11:23,480 --> 00:11:25,110 What's the second term here? 204 00:11:25,110 --> 00:11:29,649 It's going to be 5 times 2 plus 6 times 4. 205 00:11:29,649 --> 00:11:40,189 So 5 times 2 is 10, plus 6 times 4 is 24. 206 00:11:40,190 --> 00:11:42,390 Right, now we just took this row times this 207 00:11:42,389 --> 00:11:44,679 column right here. 208 00:11:44,679 --> 00:11:48,029 OK now we're down here for the set-- so then we're doing this 209 00:11:48,029 --> 00:11:51,095 row, this element right here at the bottom left is going to 210 00:11:51,095 --> 00:11:52,960 use this row, and this column. 211 00:11:52,960 --> 00:12:00,410 So it's 7 times 1 plus 8 times 3. 212 00:12:00,409 --> 00:12:02,980 8 times 3 is 24. 213 00:12:02,980 --> 00:12:05,430 And then finally, to get this element we're essentially 214 00:12:05,429 --> 00:12:11,819 multiplying this row times this column, so it's 7 times 2 215 00:12:11,820 --> 00:12:21,810 is 14, plus 8 times 4, plus 32. 216 00:12:21,809 --> 00:12:30,019 So this is equal to 5 plus 18 is 23, 34. 217 00:12:30,019 --> 00:12:31,100 What's 7 plus 24? 218 00:12:31,100 --> 00:12:35,529 That's 31, 46. 219 00:12:35,529 --> 00:12:44,139 So notice, if we called this matrix A and this 220 00:12:44,139 --> 00:12:47,080 is matrix B, right? 221 00:12:47,080 --> 00:12:57,560 In the last example, we showed that A times B is equal to 19, 222 00:12:57,559 --> 00:13:02,639 22, 43, 50. 223 00:13:02,639 --> 00:13:06,549 And we just showed that, well, if you reverse the order, B 224 00:13:06,549 --> 00:13:10,224 times A is actually this completely different matrix. 225 00:13:10,225 --> 00:13:12,230 So the order in which you multiply 226 00:13:12,230 --> 00:13:15,139 matrices completely matters. 227 00:13:15,139 --> 00:13:16,330 So I'm actually running out of time. 228 00:13:16,330 --> 00:13:19,210 In the next video I going talk a little bit more about the 229 00:13:19,210 --> 00:13:22,259 types of matrix-- well, one, we know that order matters-- 230 00:13:22,259 --> 00:13:25,110 and in the next video I'll show that what type of 231 00:13:25,110 --> 00:13:27,460 matrices can be multiplied by each other. 232 00:13:27,460 --> 00:13:29,820 When we added or subtracted matrices, we just said, well 233 00:13:29,820 --> 00:13:31,850 they have to have the same dimensions because you're 234 00:13:31,850 --> 00:13:33,855 adding or subtracting corresponding terms. But 235 00:13:33,855 --> 00:13:37,039 you'll see with multiplication it's a little bit different. 236 00:13:37,039 --> 00:13:38,252 And we'll do that in the next video. 237 00:13:38,253 --> 00:13:39,790 See you soon. 238 00:13:39,789 --> 00:13:39,899