CHAPTER 04.01 - 04.05: PRIMER ON SIMULTANEOUS LINEAR EQUATIONS: Multiplying Two Matrices
In this segment, we'll talk about how we can multiply two matrices, multiplying two matrices. Now, unlike numbers, you cannot simply multiply any two numbers . . . you can multiply any two numbers, but you cannot multiply any two matrices. There are some limitations on what you can multiply so far as matrices are concerned. Now, how is the matrix multiplication defined? So if you have, let's suppose, a matrix A, and you want to multiply it by a matrix B, that's how the multiplication is shown, but that doesn't meant that you can take any matrix A and multiply it by some matrix B, there are certain limitations. And the limitation is as follows, let's suppose this has . . . A has m rows, and it has p columns, then B has to have p rows also. So you've got to understand that the matrix multiplication is only allowed if columns . . . if number of columns of A is same as number of columns . . . number of rows of B, so if the number of columns of A, which is p in this case, is not same as the number of rows in B, which is also p in this case, then you cannot do matrix multiplication. So, you've got to understand that matrix multiplication is not allowable in . . . between two matrices if the number of columns of the first matrix is not the same as the number of rows of the next matrix, which you are trying to multiply. And the resulting matrix, of course, will be m by n. So it'll be, the resulting matrix C will have m rows, which is the same as the number of rows in A, and n columns, which is the same as the number of columns in B. Now, how do we calculate the individual elements of C once we have established that, hey, we have the number of columns of A same as the number of rows of B, is that we calculate cij, that is any i-jth element of C, based on the value of i being 1 through m, and j being from 1 through n, is given by this formula here, summation k is equal to 1 to p, aij bkj, so that's how you are able to calculate, so you basically will have to . . . so when you're calculating your ith row, jth column, which that means is that you're going to take the ith row of the A matrix, and then you're going to multiply it by the corresponding elements of the jth column of the B matrix, so it's like a dot product, so, because if you . . . if you expand this, this is what you're going to get, you're going to get ai1 b1j, so the first element of this summation is basically the ith row, first column of A, being multiplied by the first row, jth column of B, and the next one is ai2 b2j, which is the ith row, second column of A, being multiplied by the second row, jth column element of B, and so on and so forth all the way up to aip bpj, so that's how the summation . . . summation goes. I can also rewrite this summation here by looking at . . . as a multiplication of two . . . two vectors, or two . . . a row vector and a column vector, so I can look at it like this, that, hey, what I'm doing is, in order to calculate cij, I am taking the ith row . . . I'm looking at the ith row of A, and I'm going to multiply it by the . . . by the jth column . . . and we're going to multiply it by the jth column of B, that's how we can look at it. So you can very well see that this is . . . this is taking the ith row of A and you're multiplying it by the jth . . . jth column of B. So what does this mean is that, since we have just defined what multiplication of matrices is, some people might say, hey, you are showing the definition of multiplication within a multiplication. This is nothing but as defined by that particular summation, and it's simply a dot product. So what you are doing is that you're going to take this element by this element, so ai1 will get multiplied by b1j, so this first with this one, then the second one with the second one will be ai2, b2j, and the last one will be aip bpj, just like we had previously shown. So you can also look at it that the ith row, jth column of C is basically a dot product of these two vectors, of the ith row if you write it as a vector, and if you write the B . . . the jth column of B as a vector, you just take the dot product of the two, and that's how you are able to find out what the matrix multiplication is. Now, this is going to be quite clear once we start . . . take an example, we'll be able to figure out how do we go about doing this.
So let's take an example and find out how do we multiply two matrices. So let's suppose somebody tells me that, hey, I'm going to give you two matrices, I'm going to give you A as follows, 5, 2, 3, 1, 2, 7, and then I'm going to give you another matrix called B, and the B matrix is as follows, 3, -2, 5, -8, 9, -10, and somebody's going to say, hey, go ahead and find out what the matrix multiplication of A times B is. Now, the first thing which you have to do is you have to figure out whether the number of columns of A are same as the number of rows of B, only then you can do the A times B multiplication. So you've got two rows, three columns here, and three rows, two columns here, so that means that, yes, I can multiply A by B, because I've got three columns here and three rows right here, so the matrix multiplication can be done, and the resulting matrix will be a 2 by 2 matrix, the rows . . . the number of rows of A, multiplied by the number of columns . . . and the number of columns of B, that's what I will get. So let's go ahead and find out what this . . . what this resulting matrix is. So, the matrix multiplication will be shown like this. So we'll have 5, 2, 3, 1, 2, 7, 3, 5, 9, -2, -8, -10. So in order to be able to find out the first row, first column . . . in order to be able to find out what the first row, first column of this resulting multiplication matrix is, I've got to take the first row here and the first column here. So that's how I'm going to be able to find the first row, first column, I take the first row of A and the first column of B, and then I multiply the individual corresponding elements, the dot product of these two vectors, so 5 will be multiplied by 3, 2 by 5, 3 by 9, so 5 will be multiplied by 3, 2 by 5, and 3 by 9, that's what I will get there. Now, when I want to find out what the first row, second column is, so if I want to find the . . . this one, this element here, which is the first row, second column, if I want to find the first row, second column, then I'll take the first row of A, and the second column of . . . of B, that's what I will do. So that'll be 5 times -2, 3 times -8, 3 times -10, so 5 times -2, 2 times -8, plus 3 times -10, that's how I'm going to get it. So you've got to, what you've got to understand is that whatever row and column element you are calculating, you basically, you've got to take the row of the first matrix and column of the second matrix to choose for the multiplication process, for the dot product process. Now, the second row, first column, then I say second row, first column of the resulting matrix, I've got to take the second row of the first matrix and the first column of the next matrix, so that'll be 1 times 3, 1 times 3, plus 2 times 5, that's 2 times 5, plus 7 times 9, plus 7 times 9, and that'll give me that element. Same thing here, I want to calculate my second row, second column now, so I'll take the second row of this and the second column of that, that'll be 1 times -2, that's 1 times -2, plus 2 times -8, 2 times -8, plus 7 times -10. So I have calculated all the elements of the multiplication matrix. So this will be a 2 by 2, the reason why it's a 2 by 2 is because this is two rows, three columns, and this is three rows, two columns, so it will result in a matrix which is 2 by 2. So, when I do the simple arithmetic operations now, the matrix which I obtain is as follows, I get 52, -56, 76, and -88. And that's the end of this segment. |