WEBVTT 00:00:00.000 --> 00:00:00.670 00:00:00.670 --> 00:00:02.380 Well, after the last video, hopefully, we're a little 00:00:02.380 --> 00:00:04.330 familiar with how you add matrices. 00:00:04.330 --> 00:00:07.150 So now let's learn how to multiply matrices. 00:00:07.150 --> 00:00:11.450 And keep in mind, these are human-created definitions for 00:00:11.450 --> 00:00:12.840 matrix multiplication. 00:00:12.840 --> 00:00:15.000 We could have come up with completely different ways to 00:00:15.000 --> 00:00:15.450 multiply it. 00:00:15.450 --> 00:00:18.510 But I encourage you to learn this way because it'll help 00:00:18.510 --> 00:00:19.810 you in math class. 00:00:19.810 --> 00:00:22.100 And we will see later that there's actually a lot of 00:00:22.100 --> 00:00:24.730 applications that come out of this type of matrix 00:00:24.730 --> 00:00:25.290 multiplication. 00:00:25.290 --> 00:00:26.340 So let me think of two matrices. 00:00:26.340 --> 00:00:30.320 I will do two 2 by 2 matrices, and let's multiply them. 00:00:30.320 --> 00:00:34.500 Let's say-- let me pick some random numbers: 2, 00:00:34.500 --> 00:00:40.530 minus 3, 7, and 5. 00:00:40.530 --> 00:00:42.980 And I'm going to multiply that matrix, or that table of 00:00:42.980 --> 00:00:56.440 numbers, times 10, minus 8-- let me pick a good number 00:00:56.440 --> 00:01:03.980 here-- 12, and then minus 2. 00:01:03.980 --> 00:01:07.400 So now there might be a strong temptation-- and you know in 00:01:07.400 --> 00:01:11.330 some ways it's not even an illegitimate temptation-- to 00:01:11.330 --> 00:01:13.880 do the same thing with multiplication that we did 00:01:13.880 --> 00:01:17.520 with addition, to just multiply the corresponding 00:01:17.520 --> 00:01:20.580 terms. So you might be tempted to say, well, the first term 00:01:20.580 --> 00:01:23.160 right here, the 1, 1 term, or in the first row and first 00:01:23.160 --> 00:01:25.070 column, is going to be 2 times 10. 00:01:25.070 --> 00:01:26.970 And this term is going to be minus 3 times 00:01:26.970 --> 00:01:28.230 minus 8 and so forth. 00:01:28.230 --> 00:01:30.330 And that's how we added matrices so maybe it's a 00:01:30.330 --> 00:01:33.510 natural extension to multiply matrices the same way. 00:01:33.510 --> 00:01:36.180 And that is legitimate. 00:01:36.180 --> 00:01:38.530 One could define it that way, but that's not the way it is 00:01:38.530 --> 00:01:39.410 in the real world. 00:01:39.410 --> 00:01:40.380 And the way in the real world, 00:01:40.380 --> 00:01:42.470 unfortunately, is more complex. 00:01:42.470 --> 00:01:44.980 But if you look at a bunch of examples I 00:01:44.980 --> 00:01:45.670 think you'll get it. 00:01:45.670 --> 00:01:47.460 And you'll learn that it's actually fairly 00:01:47.460 --> 00:01:47.980 straightforward. 00:01:47.980 --> 00:01:48.985 So how do we do it? 00:01:48.985 --> 00:01:53.290 So this first term that's in the first row and its first 00:01:53.290 --> 00:01:58.050 column, is equal to essentially this first row's 00:01:58.050 --> 00:02:01.380 vector-- no, this first row vector-- 00:02:01.380 --> 00:02:04.790 times this column vector. 00:02:04.790 --> 00:02:08.229 Now what do I mean by that, right? 00:02:08.229 --> 00:02:11.320 So it's getting it's row information from the first 00:02:11.320 --> 00:02:14.170 matrix's row, and it's getting it's column information from 00:02:14.170 --> 00:02:16.320 the second matrix's column. 00:02:16.320 --> 00:02:17.190 So how do I do that? 00:02:17.190 --> 00:02:18.860 If you're familiar with dot product, it's essentially the 00:02:18.860 --> 00:02:20.930 dot product of these two matrices. 00:02:20.930 --> 00:02:24.820 Or without saying it that fancy, it's just this: it's 2 00:02:24.820 --> 00:02:31.890 times 10, so 2-- I'm going to write small-- times 10, plus 00:02:31.890 --> 00:02:39.640 minus 3 times 12. 00:02:39.640 --> 00:02:42.630 I'm going to run out of space. 00:02:42.630 --> 00:02:45.600 And so what's this second term over here? 00:02:45.600 --> 00:02:49.170 Well, we're still on the first row of the product vector but 00:02:49.170 --> 00:02:50.350 now we're on the second column. 00:02:50.350 --> 00:02:51.910 We get our column information from here. 00:02:51.910 --> 00:02:58.800 So let's pick a good color-- this is a slightly different 00:02:58.800 --> 00:03:00.530 shade of purple. 00:03:00.530 --> 00:03:04.110 So now this is going to be-- I'll do that in another 00:03:04.110 --> 00:03:10.580 color-- 2 times minus 8-- let me just write out the number-- 00:03:10.580 --> 00:03:18.810 2 times minus 8 is minus 16, plus minus 3 times minus 2-- 00:03:18.810 --> 00:03:21.160 what's minus 3 times minus 2? 00:03:21.160 --> 00:03:26.400 That is plus 6, right? 00:03:26.400 --> 00:03:28.870 So that's in row 1 column 2. 00:03:28.870 --> 00:03:30.590 It's minus 16 plus 6. 00:03:30.590 --> 00:03:31.830 And then let's come down here. 00:03:31.830 --> 00:03:33.920 So now we're in the second row. 00:03:33.920 --> 00:03:35.550 So now we're going to use-- we're getting our row 00:03:35.550 --> 00:03:37.930 information from the first matrix-- I know this is 00:03:37.930 --> 00:03:41.380 confusing and I feel bad for you right now, but we're going 00:03:41.380 --> 00:03:45.230 to a bunch of examples and I think it'll make sense. 00:03:45.230 --> 00:03:49.060 So this term-- the bottom left term-- is going to be this row 00:03:49.060 --> 00:03:50.310 times this column. 00:03:50.310 --> 00:03:58.010 So it's going to be 7 times 10, so 70, plus 7 times 10 00:03:58.010 --> 00:04:05.650 plus 5 times 12, plus 60. 00:04:05.650 --> 00:04:09.290 And then the bottom right term is going to be 7 times minus 00:04:09.290 --> 00:04:19.540 8, which is minus 56 plus 5 times minus 2. 00:04:19.540 --> 00:04:22.900 So that's minus 10. 00:04:22.900 --> 00:04:31.290 So the final product is going to be 2 times 10 is 20, minus 00:04:31.290 --> 00:04:41.040 36, so that's minus 16 plus 6, that's 10. 00:04:41.040 --> 00:04:42.220 90-- was that what I said? 00:04:42.220 --> 00:04:46.390 No, it was-- 70, plus 60, that's 130. 00:04:46.390 --> 00:04:55.580 And then minus 56 minus 10, so minus 66. 00:04:55.580 --> 00:04:56.400 So there you have it. 00:04:56.400 --> 00:04:59.020 We just multiplied this matrix times this matrix. 00:04:59.020 --> 00:05:00.360 Let me do another example. 00:05:00.360 --> 00:05:03.490 And I think I'll actually squeeze it on this side so 00:05:03.490 --> 00:05:06.106 that we can write this side out a little bit more neatly. 00:05:06.106 --> 00:05:18.630 So let's take the matrix and now 1, 2, 3, 4, times the 00:05:18.630 --> 00:05:27.710 matrix 5, 6, 7, 8. 00:05:27.710 --> 00:05:30.200 Now we have much more space to work with so this should come 00:05:30.200 --> 00:05:32.760 out neater. 00:05:32.760 --> 00:05:37.460 OK, but I'm going to do the same thing, so to get this 00:05:37.460 --> 00:05:40.350 term right here-- the top left term-- we're going to take-- 00:05:40.350 --> 00:05:43.070 or the one that has row 1 column 1-- we're going to take 00:05:43.070 --> 00:05:52.050 the row 1 information from here, and the column 1 00:05:52.050 --> 00:05:54.440 information from here. 00:05:54.440 --> 00:05:56.070 So you can view it as this row vector 00:05:56.070 --> 00:05:57.120 times this column vector. 00:05:57.120 --> 00:06:01.680 So it results, 1 times 5 plus 2 times 7. 00:06:01.680 --> 00:06:07.730 00:06:07.730 --> 00:06:08.380 Right? 00:06:08.380 --> 00:06:09.610 There you go. 00:06:09.610 --> 00:06:12.520 And so this term, it'll be this row vector times this 00:06:12.520 --> 00:06:15.740 column vector-- let me do that in a different color-- will be 00:06:15.740 --> 00:06:20.550 1 times 6 plus 2 times 8. 00:06:20.550 --> 00:06:21.370 Let me write that down. 00:06:21.370 --> 00:06:28.590 So it's 1 times 6 plus 2 times 8. 00:06:28.590 --> 00:06:33.270 00:06:33.270 --> 00:06:34.720 Now we go down to the second row. 00:06:34.720 --> 00:06:38.130 And we get our row information from the first vector-- let me 00:06:38.130 --> 00:06:44.150 circle it with this color-- and it is 3 times 5 00:06:44.150 --> 00:06:45.520 plus 4 times 7. 00:06:45.520 --> 00:06:52.800 00:06:52.800 --> 00:06:54.760 And then we are in the bottom right, so we're in the bottom 00:06:54.760 --> 00:06:57.070 row and second column. 00:06:57.070 --> 00:06:59.350 So we get our row information from here and our column 00:06:59.350 --> 00:07:00.930 information from here. 00:07:00.930 --> 00:07:03.860 So it's 3 times 6 plus 4 times 8. 00:07:03.860 --> 00:07:10.300 00:07:10.300 --> 00:07:13.680 And if we simplify, this is 5 plus-- 00:07:13.680 --> 00:07:15.950 Well actually, let me just remind you where all the 00:07:15.950 --> 00:07:16.630 numbers came from. 00:07:16.630 --> 00:07:18.200 So we have that green color, right? 00:07:18.200 --> 00:07:25.890 This 1 and this 2, that's this 1 and this 2, 00:07:25.890 --> 00:07:28.620 this 1 and this 2. 00:07:28.620 --> 00:07:28.755 Right? 00:07:28.755 --> 00:07:30.330 And notice, these were in the first row and they're in the 00:07:30.330 --> 00:07:31.660 first row here. 00:07:31.660 --> 00:07:33.640 And this 5 and this 7? 00:07:33.640 --> 00:07:39.920 Well, that's this 5 and this 7, and this 5 and this 7. 00:07:39.920 --> 00:07:42.800 So, interesting. 00:07:42.800 --> 00:07:45.410 This was in column 1 of the second matrix and this is in 00:07:45.410 --> 00:07:47.780 column 1 in the product matrix. 00:07:47.780 --> 00:07:51.030 And similarly, the 6 and the 8. 00:07:51.030 --> 00:07:55.610 That's this 6, this 8, and then it's used here, this 6 00:07:55.610 --> 00:07:57.540 and this 8. 00:07:57.540 --> 00:08:00.250 And then finally this 3 and the 4 in the brown, so that's 00:08:00.250 --> 00:08:03.980 this 3, this 4, and this 3 and this 4. 00:08:03.980 --> 00:08:05.290 And we could of course simplify all of it. 00:08:05.290 --> 00:08:10.180 This was 1 times 5 plus 2 times 7, so that's 5 plus 14, 00:08:10.180 --> 00:08:15.410 so this is 19. 00:08:15.410 --> 00:08:19.200 This is 1 times 6 plus 2 times 8, so it's 6 plus 00:08:19.200 --> 00:08:22.330 16, so that's 22. 00:08:22.330 --> 00:08:26.380 This is 3 times 5 plus 4 times 7. 00:08:26.380 --> 00:08:32.909 So 15 plus 28, 38, 43-- if my math is correct-- and then we 00:08:32.909 --> 00:08:36.250 have 3 times 6 plus 4 times 8. 00:08:36.250 --> 00:08:44.220 So that's 18 plus 32, that's 50. 00:08:44.220 --> 00:08:45.980 So now let me ask you-- just so you know that the product 00:08:45.980 --> 00:08:47.690 matrix-- just write it neatly-- is 00:08:47.690 --> 00:08:53.610 19, 22, 43, and 50. 00:08:53.610 --> 00:08:55.100 So now let me ask you a question. 00:08:55.100 --> 00:08:58.810 When we did matrix addition we learned that if I had two 00:08:58.810 --> 00:09:03.210 matrices-- it didn't matter what order we added them in. 00:09:03.210 --> 00:09:06.970 So if we said, A plus B-- and these are matrices; that's why 00:09:06.970 --> 00:09:09.340 I'm making them all bold-- we said this is the same thing as 00:09:09.340 --> 00:09:12.330 B plus A, based on how we define matrix 00:09:12.330 --> 00:09:15.520 addition, B plus A. 00:09:15.520 --> 00:09:17.060 So now let me ask you a question. 00:09:17.060 --> 00:09:22.970 Is multiplying two matrices, is AB-- that's just means 00:09:22.970 --> 00:09:26.460 we're multiplying A and B-- is that the same thing as BA? 00:09:26.460 --> 00:09:30.090 00:09:30.090 --> 00:09:30.820 Does it matter? 00:09:30.820 --> 00:09:33.800 Does the order of the matrix multiplication matter? 00:09:33.800 --> 00:09:36.310 And so, I'll tell you right now, it actually matters a 00:09:36.310 --> 00:09:37.090 tremendous amount. 00:09:37.090 --> 00:09:39.550 And actually there are certain matrices that you can add in 00:09:39.550 --> 00:09:42.040 one direction that you can't add in the other-- oh, that 00:09:42.040 --> 00:09:47.300 you can multiply in one way but you can't multiply in the 00:09:47.300 --> 00:09:48.200 other order. 00:09:48.200 --> 00:09:50.755 And well, I'll show you that in an example-- but just to 00:09:50.755 --> 00:09:52.800 show that this isn't even equal for most matrices, I 00:09:52.800 --> 00:09:56.640 encourage you to multiply these two matrices in the 00:09:56.640 --> 00:09:57.110 other order. 00:09:57.110 --> 00:09:58.950 Actually let me do that. 00:09:58.950 --> 00:10:00.630 Let me do that really fast just to prove 00:10:00.630 --> 00:10:01.440 the point to you. 00:10:01.440 --> 00:10:02.830 So let me delete all this top part. 00:10:02.830 --> 00:10:06.040 00:10:06.040 --> 00:10:13.830 Let me delete all of it, and actually I can delete to this. 00:10:13.830 --> 00:10:15.960 So hopefully, you know that when I multiply this matrix 00:10:15.960 --> 00:10:17.850 times this matrix, I got this. 00:10:17.850 --> 00:10:20.250 So let me switch the order-- and I'll do it fairly fast 00:10:20.250 --> 00:10:23.140 just so as to not bore you-- so let me switch the order of 00:10:23.140 --> 00:10:24.150 the matrix multiplication. 00:10:24.150 --> 00:10:26.755 This is good as this is another example-- so I'm going 00:10:26.755 --> 00:10:36.740 to multiply this matrix: 5, 6, 7, 8, times this matrix-- and 00:10:36.740 --> 00:10:40.400 I just switched the order; and we're testing to see whether 00:10:40.400 --> 00:10:46.700 order matters-- 1, 2, 3, 4. 00:10:46.700 --> 00:10:49.010 Let's do it-- and I won't do all the colors and everything, 00:10:49.010 --> 00:10:49.690 I'll just do it systematically. 00:10:49.690 --> 00:10:54.330 I think you just have to see a lot of examples here-- So this 00:10:54.330 --> 00:10:56.410 first term gets its row information from the first 00:10:56.410 --> 00:10:58.810 matrix, column information from the second matrix. 00:10:58.810 --> 00:11:06.340 So it's 5 times 1 plus 6 times 3, so it's 5 times 1-- 00:11:06.340 --> 00:11:09.130 Let me just write, actually edit. 00:11:09.130 --> 00:11:17.650 I'm going to skip a step here-- OK so it's 5 times 1 00:11:17.650 --> 00:11:23.480 plus 6 times 3, plus 18. 00:11:23.480 --> 00:11:25.110 What's the second term here? 00:11:25.110 --> 00:11:29.650 It's going to be 5 times 2 plus 6 times 4. 00:11:29.650 --> 00:11:40.190 So 5 times 2 is 10, plus 6 times 4 is 24. 00:11:40.190 --> 00:11:42.390 Right, now we just took this row times this 00:11:42.390 --> 00:11:44.680 column right here. 00:11:44.680 --> 00:11:48.030 OK now we're down here for the set-- so then we're doing this 00:11:48.030 --> 00:11:51.095 row, this element right here at the bottom left is going to 00:11:51.095 --> 00:11:52.960 use this row, and this column. 00:11:52.960 --> 00:12:00.410 So it's 7 times 1 plus 8 times 3. 00:12:00.410 --> 00:12:02.980 8 times 3 is 24. 00:12:02.980 --> 00:12:05.430 And then finally, to get this element we're essentially 00:12:05.430 --> 00:12:11.820 multiplying this row times this column, so it's 7 times 2 00:12:11.820 --> 00:12:21.810 is 14, plus 8 times 4, plus 32. 00:12:21.810 --> 00:12:30.020 So this is equal to 5 plus 18 is 23, 34. 00:12:30.020 --> 00:12:31.100 What's 7 plus 24? 00:12:31.100 --> 00:12:35.530 That's 31, 46. 00:12:35.530 --> 00:12:44.140 So notice, if we called this matrix A and this 00:12:44.140 --> 00:12:47.080 is matrix B, right? 00:12:47.080 --> 00:12:57.560 In the last example, we showed that A times B is equal to 19, 00:12:57.560 --> 00:13:02.640 22, 43, 50. 00:13:02.640 --> 00:13:06.550 And we just showed that, well, if you reverse the order, B 00:13:06.550 --> 00:13:10.225 times A is actually this completely different matrix. 00:13:10.225 --> 00:13:12.230 So the order in which you multiply 00:13:12.230 --> 00:13:15.140 matrices completely matters. 00:13:15.140 --> 00:13:16.330 So I'm actually running out of time. 00:13:16.330 --> 00:13:19.210 In the next video I going talk a little bit more about the 00:13:19.210 --> 00:13:22.260 types of matrix-- well, one, we know that order matters-- 00:13:22.260 --> 00:13:25.110 and in the next video I'll show that what type of 00:13:25.110 --> 00:13:27.460 matrices can be multiplied by each other. 00:13:27.460 --> 00:13:29.820 When we added or subtracted matrices, we just said, well 00:13:29.820 --> 00:13:31.850 they have to have the same dimensions because you're 00:13:31.850 --> 00:13:33.855 adding or subtracting corresponding terms. But 00:13:33.855 --> 00:13:37.040 you'll see with multiplication it's a little bit different. 00:13:37.040 --> 00:13:38.253 And we'll do that in the next video. 00:13:38.253 --> 00:13:39.790 See you soon. 00:13:39.790 --> 00:13:39.900