1 00:00:05,130 --> 00:00:08,300 One of the most important operations we can do with 2 00:00:08,300 --> 00:00:11,470 matrices is to learn how to multiply them together. That's 3 00:00:11,470 --> 00:00:14,957 what we're going to do now. And when we multiply matrices 4 00:00:14,957 --> 00:00:18,444 together, we find that we combine the elements in the two 5 00:00:18,444 --> 00:00:21,931 matrices in rather a strange way, and the easiest way to 6 00:00:21,931 --> 00:00:25,101 explain that is by example, so let's have a look. 7 00:00:26,040 --> 00:00:29,793 Suppose we've got a row of a matrix 37. 8 00:00:31,650 --> 00:00:36,057 And we want to combine it or multiply it with a column of 9 00:00:36,057 --> 00:00:37,074 another matrix 29. 10 00:00:38,790 --> 00:00:42,222 And what we do is we combine these numbers in a rather 11 00:00:42,222 --> 00:00:46,226 strange way. What we do is we pair off the elements in the row 12 00:00:46,226 --> 00:00:49,658 of the first matrix with the column with the column in the 13 00:00:49,658 --> 00:00:52,804 Second matrix, and we pair them off and we multiply the 14 00:00:52,804 --> 00:00:55,664 corresponding elements together. So we pair off the three with 15 00:00:55,664 --> 00:00:58,460 the two. The seven with the 9. 16 00:00:59,250 --> 00:01:02,310 And we multiply the paired elements together so we 17 00:01:02,310 --> 00:01:03,670 have 3 * 2. 18 00:01:06,290 --> 00:01:08,546 I mean multiply the seven with the 9. 19 00:01:10,750 --> 00:01:12,388 And we add the results together. 20 00:01:13,390 --> 00:01:18,542 So we have 3 * 2 which is 6 and 7 * 9, which is 63 21 00:01:18,542 --> 00:01:22,084 and we add them together and we get the answer 69. 22 00:01:25,560 --> 00:01:29,004 So we have this rather strange way in which we have combined 23 00:01:29,004 --> 00:01:32,448 the elements in the row of the first matrix with the column 24 00:01:32,448 --> 00:01:33,596 in the Second matrix. 25 00:01:34,620 --> 00:01:38,652 Let's have a look at another example. Suppose we have a row 26 00:01:38,652 --> 00:01:39,660 which is 425. 27 00:01:41,020 --> 00:01:45,947 And we're going to learn how to multiply it with a column 368. 28 00:01:48,670 --> 00:01:53,416 And again, what we do is we pair the elements off elements in the 29 00:01:53,416 --> 00:01:57,823 row of the first matrix with the column of the Second matrix. We 30 00:01:57,823 --> 00:01:59,179 have 4 * 3. 31 00:02:03,200 --> 00:02:05,060 2 * 6. 32 00:02:07,370 --> 00:02:09,230 5 * 8. 33 00:02:12,050 --> 00:02:17,003 And we add these products together, so with 4 * 3 which is 34 00:02:17,003 --> 00:02:23,861 12 two times 6 which is 12 and 5 * 8 which is 40. And if we add 35 00:02:23,861 --> 00:02:26,909 these up will get 12 and 12 is 36 00:02:26,909 --> 00:02:29,970 24. And 40 which is 64. 37 00:02:34,190 --> 00:02:37,742 So this is a rather strange way in which we've combined the 38 00:02:37,742 --> 00:02:40,998 elements in the first matrix with the elements in the second 39 00:02:40,998 --> 00:02:43,958 matrix, but it's the basis of matrix multiplication, as we'll 40 00:02:43,958 --> 00:02:47,214 see shortly Now, suppose we have to general matrices A&B, say. 41 00:02:48,900 --> 00:02:52,050 And we want to find the product of these two 42 00:02:52,050 --> 00:02:54,885 matrices. In other words, we want to multiply A&B 43 00:02:54,885 --> 00:02:55,200 together. 44 00:02:56,470 --> 00:03:00,694 Now suppose that this matrix A. The first matrix has P, 45 00:03:00,694 --> 00:03:04,534 rossion, Q columns, so it's a P by Q matrix. 46 00:03:06,270 --> 00:03:09,663 And the second matrix be. Let's suppose that Scott 47 00:03:09,663 --> 00:03:13,810 are rows and S columns, so it's an arby S matrix. 48 00:03:15,820 --> 00:03:19,746 Now it turns out that we can only form this product. We can 49 00:03:19,746 --> 00:03:21,256 only multiply the two matrices 50 00:03:21,256 --> 00:03:24,692 together. If the number of columns in the first matrix, 51 00:03:24,692 --> 00:03:28,304 which is Q is the same as the number of rows in the second 52 00:03:28,304 --> 00:03:31,658 matrix, these two numbers have got to be the same. Q Must equal 53 00:03:31,658 --> 00:03:35,012 R and the reason for that will become apparent when we start to 54 00:03:35,012 --> 00:03:38,366 do the calculation. But you've got to be able to pair up the 55 00:03:38,366 --> 00:03:41,204 elements in the first matrix with the elements in the Second 56 00:03:41,204 --> 00:03:44,816 matrix and will only be able to do that if the number of columns 57 00:03:44,816 --> 00:03:48,428 in the first is the same as the number of rows in the second. 58 00:03:49,960 --> 00:03:54,100 When that's the case, we can actually find the product AB and 59 00:03:54,100 --> 00:03:57,895 the answer is another matrix. And let's suppose this answer is 60 00:03:57,895 --> 00:04:02,380 matrix C and the size of matrix. See, we can determine in advance 61 00:04:02,380 --> 00:04:07,210 from the sizes of matrix A&B, the size of matrix C will be P 62 00:04:07,210 --> 00:04:11,967 by S. So it's got the same number of rows as the first 63 00:04:11,967 --> 00:04:16,088 matrix and columns as the second matrix, so this will be an R. 64 00:04:16,088 --> 00:04:18,624 This will be a P by S matrix. 65 00:04:20,690 --> 00:04:25,622 Let's have a look at a specific example. Suppose we want to 66 00:04:25,622 --> 00:04:27,266 multiply the matrix 37. 67 00:04:27,990 --> 00:04:29,670 45 68 00:04:32,040 --> 00:04:34,508 by the Matrix 29. 69 00:04:35,920 --> 00:04:39,077 And the first question we should ask ourselves is, do these 70 00:04:39,077 --> 00:04:42,234 matrices have the right size so that we can actually multiply 71 00:04:42,234 --> 00:04:47,470 them together? Well, this matrix is a two row two column matrix. 72 00:04:50,350 --> 00:04:53,374 And the second matrix is 2 rows one column. 73 00:04:55,960 --> 00:04:59,951 And we note that the number of columns here in the first matrix 74 00:04:59,951 --> 00:05:03,942 is the same as the number of rows in the second matrix. So 75 00:05:03,942 --> 00:05:07,626 these two numbers are the same, so we can do this multiplication 76 00:05:07,626 --> 00:05:11,924 and the size of the answer. The size of the result that will get 77 00:05:11,924 --> 00:05:15,915 is obtained by the number of rows in the 1st and columns in 78 00:05:15,915 --> 00:05:19,906 the second. So the size of the answer that we're looking for is 79 00:05:19,906 --> 00:05:24,204 a 2 by 1 matrix. So you see right at the beginning we can 80 00:05:24,204 --> 00:05:27,046 tell how many. Elements are going to be in our answer. 81 00:05:27,046 --> 00:05:29,770 There's going to be a number there, and a number there so 82 00:05:29,770 --> 00:05:31,586 that we have a 2 by 1 matrix. 83 00:05:32,920 --> 00:05:36,169 Now to determine these numbers, we use the same 84 00:05:36,169 --> 00:05:39,779 operations as we've just seen. We take the first row 85 00:05:39,779 --> 00:05:43,750 here and we pair the elements with those in the first 86 00:05:43,750 --> 00:05:44,111 column. 87 00:05:45,380 --> 00:05:50,308 We multiply the paired elements together and add the result. So 88 00:05:50,308 --> 00:05:53,892 we want 3 * 2, which is 6. 89 00:05:55,540 --> 00:06:02,125 We want 7 * 9 which is 63 and we add the results together. 6 90 00:06:02,125 --> 00:06:07,832 and 63 is 69, so the element that goes in the first position 91 00:06:07,832 --> 00:06:13,539 in our answer is 69. That's 3 * 2 at 7 * 9. 92 00:06:15,380 --> 00:06:19,043 The element that's going in this position here is obtained by 93 00:06:19,043 --> 00:06:22,373 working with the 2nd row and this first column here. 94 00:06:23,120 --> 00:06:25,871 Again, we pair the elements up 4 95 00:06:25,871 --> 00:06:28,670 * 2. Which is 8th. 96 00:06:29,950 --> 00:06:36,541 5 * 9 which is 45, and we add the results together. 45 97 00:06:36,541 --> 00:06:38,062 + 8 is. 98 00:06:39,600 --> 00:06:40,610 53 99 00:06:43,270 --> 00:06:46,810 So the result is 6953, so the result of multiplying these two 100 00:06:46,810 --> 00:06:50,350 matrices together is another matrix which is a 2 by 1 matrix 101 00:06:50,350 --> 00:06:53,890 and the elements are obtained in the way I've just shown you. 102 00:06:54,490 --> 00:06:56,116 Let's have a look at another 103 00:06:56,116 --> 00:07:01,054 example. This time I'm going to try to multiply together the two 104 00:07:01,054 --> 00:07:06,010 matrices A&B where a is this two by two Matrix 2453 and B. Is 105 00:07:06,010 --> 00:07:09,550 this two by two Matrix three 6 -- 1 nine? 106 00:07:10,380 --> 00:07:13,339 And again, the first question we should ask ourselves is, do 107 00:07:13,339 --> 00:07:16,298 these matrices have the right size so that we can actually 108 00:07:16,298 --> 00:07:21,893 multiply them together? Well, matrix a this matrix A is a two 109 00:07:21,893 --> 00:07:25,916 row two column matrix. So that's two by two. 110 00:07:27,550 --> 00:07:30,960 Matrix B is 2 rows and two columns, so that's also 111 00:07:30,960 --> 00:07:31,890 two by two. 112 00:07:33,290 --> 00:07:36,631 And you can see that these two numbers are the same. That is, 113 00:07:36,631 --> 00:07:39,715 the number of columns in the first is the same as the 114 00:07:39,715 --> 00:07:42,799 number of rows in the second. So we can perform the matrix 115 00:07:42,799 --> 00:07:43,056 multiplication. 116 00:07:44,280 --> 00:07:47,604 The size of the answer we can determine right at the start. 117 00:07:47,604 --> 00:07:51,205 The size of the matrix that we get is determined by the number 118 00:07:51,205 --> 00:07:54,806 here and the number there two by two. So what we can decide 119 00:07:54,806 --> 00:07:58,130 before we do any calculation at all is that this answer matrix 120 00:07:58,130 --> 00:07:59,792 is a two by two matrix. 121 00:08:00,470 --> 00:08:03,198 Be 2 rows and two columns, so we're looking for four 122 00:08:03,198 --> 00:08:04,438 numbers to pop in there. 123 00:08:05,970 --> 00:08:09,389 Let's try and figure out how we work out, what the answer is. 124 00:08:10,940 --> 00:08:15,269 When we want to find the element that goes in here, observe that 125 00:08:15,269 --> 00:08:18,599 this is the first row first column of the answer. 126 00:08:20,140 --> 00:08:23,781 And the number in the first row first column comes from 127 00:08:23,781 --> 00:08:26,760 looking at the first row and 1st Column here. 128 00:08:28,370 --> 00:08:32,491 If we pair off the elements in the first row and 1st Column 129 00:08:32,491 --> 00:08:35,027 will have 2 * 3 which is 6. 130 00:08:36,410 --> 00:08:40,960 4 * -- 1, which is minus four, and we add them together. 131 00:08:44,870 --> 00:08:49,430 When we come to this element here, this element is in the 132 00:08:49,430 --> 00:08:50,950 first row, second column. 133 00:08:51,610 --> 00:08:55,558 So we use the first row, second column in the original matrices. 134 00:08:56,270 --> 00:09:03,155 2 * 6 which is 12 and 4 * 9 Four nines of 36. And 135 00:09:03,155 --> 00:09:05,909 we add those paired products together. 136 00:09:08,610 --> 00:09:13,303 When we want the element that's in the 2nd row first column, we 137 00:09:13,303 --> 00:09:17,996 use the 2nd row in the first matrix and 1st column in the 138 00:09:17,996 --> 00:09:22,328 Second Matrix. Again, pairing the elements off 5 * 3 is 15. 139 00:09:23,790 --> 00:09:28,122 3 * -- 1 is minus three. When we add the paired 140 00:09:28,122 --> 00:09:28,844 elements together. 141 00:09:30,730 --> 00:09:35,570 Finally. The element that's in the 2nd row, second column of 142 00:09:35,570 --> 00:09:39,860 the answer is obtained by using the elements in the 2nd row of 143 00:09:39,860 --> 00:09:42,830 the first matrix, second column of the Second matrix. 144 00:09:43,810 --> 00:09:50,984 5 * 6 which is 30 and 3 * 9, which is 27, and we add the 145 00:09:50,984 --> 00:09:52,250 paired elements together. 146 00:09:53,480 --> 00:09:57,596 So finally, just to tidy it up, we've got 6 subtract 4 147 00:09:57,596 --> 00:09:58,625 which is 2. 148 00:10:00,540 --> 00:10:03,606 12 + 36, which is 48. 149 00:10:05,750 --> 00:10:12,533 15 subtract 3 which is 12 and 30 + 27 which is 57, so we can find 150 00:10:12,533 --> 00:10:18,119 the matrix product AB in this case and the result is a two by 151 00:10:18,119 --> 00:10:21,874 two matrix. Let's have a look at another example. Suppose 152 00:10:21,874 --> 00:10:24,654 we're asked to find the product of these two matrices. 153 00:10:25,990 --> 00:10:29,270 And again, we should ask all these matrices of the 154 00:10:29,270 --> 00:10:32,550 appropriate size. The first matrix here has two rows, one 155 00:10:32,550 --> 00:10:34,846 column, it's a 2 by 1 matrix. 156 00:10:35,760 --> 00:10:40,154 And the second matrix has two rows and two columns, so it's a 157 00:10:40,154 --> 00:10:44,210 two by two matrix. Now in this case, you'll see that the 158 00:10:44,210 --> 00:10:48,604 number of columns in the first matrix is not the same as the 159 00:10:48,604 --> 00:10:52,322 number of rows in the second matrix. Those two numbers are 160 00:10:52,322 --> 00:10:55,026 not equal, so we cannot multiply these matrices 161 00:10:55,026 --> 00:10:58,406 together. We say the product of these matrices doesn't exist, 162 00:10:58,406 --> 00:11:01,110 so we stop there. We can't calculate that. 163 00:11:02,540 --> 00:11:07,950 Let's have another example. Suppose we want to try to 164 00:11:07,950 --> 00:11:11,737 find the product of the matrices 3214. 165 00:11:14,180 --> 00:11:17,700 With the matrix XY. Now this is the first example we've 166 00:11:17,700 --> 00:11:20,900 looked at where we've had symbols rather than numbers in 167 00:11:20,900 --> 00:11:23,780 our matrix, but the operation the process is, the 168 00:11:23,780 --> 00:11:25,380 calculations are just the same. 169 00:11:26,430 --> 00:11:29,466 First of all, we should ask can we multiply these together? Are 170 00:11:29,466 --> 00:11:30,731 they of the right size? 171 00:11:31,660 --> 00:11:34,188 This is a two row two column matrix. 172 00:11:35,970 --> 00:11:38,562 And this is a two row one column matrix. 173 00:11:40,030 --> 00:11:43,969 And these numbers are the same in here the number of columns in 174 00:11:43,969 --> 00:11:48,211 the first is the same as the number of rows in the second. So 175 00:11:48,211 --> 00:11:50,938 we can actually perform the matrix multiplication and the 176 00:11:50,938 --> 00:11:55,786 answer we get will be a 2 by 1 matrix, so we know the shape of 177 00:11:55,786 --> 00:11:59,725 the answer. It's a two row one column matrix, so it looks the 178 00:11:59,725 --> 00:12:01,846 same shape as this one. This one 179 00:12:01,846 --> 00:12:04,348 here. Two rows, one column. 180 00:12:06,340 --> 00:12:09,750 Let's actually work out what the elements in the answers are. 181 00:12:10,600 --> 00:12:15,176 As before, we take the first row and pair the elements with the 182 00:12:15,176 --> 00:12:21,620 first column. So it's 3 multiplied by X 2 * y and we add 183 00:12:21,620 --> 00:12:26,130 the resulting products, so we get three X + 2 Y. 184 00:12:33,190 --> 00:12:37,138 The element that's down here, which is in the 2nd row, first 185 00:12:37,138 --> 00:12:41,086 column of our answer, is obtained by using the 2nd row in 186 00:12:41,086 --> 00:12:43,060 the first matrix and the first 187 00:12:43,060 --> 00:12:47,612 column here. Multiply the pad elements together and add so 188 00:12:47,612 --> 00:12:54,344 it's 1 * X which is X 4 * y, which is 4 Y and we add the 189 00:12:54,344 --> 00:13:00,328 products together and we get X + 4 Y. So the result we found is a 190 00:13:00,328 --> 00:13:02,198 two row one column matrix. 191 00:13:03,770 --> 00:13:06,914 In this case, the answers got symbols in as well, but that's 192 00:13:06,914 --> 00:13:09,534 the result of finding the product of these two matrices. 193 00:13:09,534 --> 00:13:12,940 Now we can go on and look at more examples and trying to 194 00:13:12,940 --> 00:13:15,298 find products of matrices of different sizes and shapes, 195 00:13:15,298 --> 00:13:18,180 and we'll do some more of that in the next video.