Let’s do some more matrix multiplication examples because I think it is all about seeing as many examples as possible. So let’s do what may seem to be more difficult problem and it might not be even clear that we can multiply these matrices. And maybe that’s the first thing we should think about.
So let’s say I wanted to multiply the matrix—relatively small so we don’t run out of space. 3 1 2 -2 0 5. Let’s say I want to multiply that times the matrix -1 0 2 3 5 5. I am just making up these numbers.
So the first thing you might be wondering is what can I even multiply these matrices? Because you know from the first video we did on matrices, you can’t add these two matrices. You know they—this term corresponds to this one. This one corresponds to this one but this term corresponds to nothing over here. So you could not add or subtract these matrices. So the question is, can I multiply these matrices?
Well what did we learn about multiplying matrices? We know that—for example if—you know, this is going to result in some matrix. However, we don’t know even what the dimensions are yet until we work through this example although, there’s a quick way of figuring it out.
So this first term here, the upper left term, where does it get its row information from and where does it get it column information from? Well it gets its row information from here. So it’s essentially this row times which column? Times this column, right? And we can actually take the dot product of this row vector and this column vector because they have the same length. This is a column vector but it has a length of three, right? It’s a three by one but it has three elements in it. And this is a one by three row vector but it also has three elements in it. So we actually can take the dot product and we can multiply these two. And similarly we can multiply these times this whole thing to get this term right here. And then we could multiply this thing times this thing to get this term and then this thing times that term to get that term.
So it actually turns out that you can—so what kind of a matrix is this? Let’s call that this is matrix—let me switch an arbitrary constant. So this is matrix A and what are its dimensions? Its dimensions are, it has two rows and three columns. So it’s a two by three matrix.
Now we’re multiplying it times B. And what are B’s dimensions? Well it has three rows. So it’s a three by—and how may columns does it have? Two matrix. So it turns out that we can multiply two matrices if kind of—you can kind of say that the number—if on the first matrix, the number of columns is equal to the number of rows in the second matrix.
So here two by three times three by two, we can multiply. For example, we could have multiplied—you know, if this is matrix c—I don’t know if—it takes worst time to keep bolding these things. And I don’t care how many rows it has. It have N rows. N × A columns. I can multiply it times matrix D. As long as matrix D has A rows.
As long as—you could kind of say these two inner numbers are the same, right? This three is the same as three and why does that matter? Well where’s the logic? Because this row will have three elements because there are three columns and each column vector here will have three elements because there are three rows. That’s the intuition—it comes from but if you had to do it real quick, you say two by three, three by two. This number is equal to that number. I can multiply.
So let me clear up some space and let’s do the multiplication. Let’s do some multiplication. I’m debating whether—where I should do it. I think I should do it down here maybe because I’ll have more space. So let me do it down here. I don’t have to erase anything else. So let me get some space ready. Okay. This will take up a lot of space.
So to get this row one column one element, what do I do? I multiply this vector times this vector. I take the dot product, right? So it’s 3 × -1. I’m just going to write it all up. 3 × -1 + 1 × 0 + 2 × 2 which is—that’s right; 2 × 2 there, we got the first term.
So the second term here—what am I going to do? I am going to multiply that vector times that row vector times this column vector. And I think you’re getting the hang of this and it’s really the hardest part about this is just not—you know, staying focused and not making a careless mistake and not getting confused with rows and columns and all that. So it’s a bit of a—you know, just kind of sends blood to your brain but it’s not that hard I think.
So what do we do? We multiply this row vector times this column vector to get row one, column two, right? Because this row; this row; row one, column two. 3 × 3, so it’s 3 × 3 + 1 × 5 + 2 × 5, right. We’re just kind of multiplying the corresponding terms, although—you know the third times the third term. The second term times the second term. The first term times the first term although—you know in this case, they’re kind of going down. In this case, they’re going left and right and we add them all up.
Okay. So now we’re in second row. And we get row information from the first vector. And let me do a red that I never use because I think it’s kind of tacky. Well this red right here. So I want to multiply this row of vector times this column vector. So it’s -2 × -1 + 0 × 0 + 5 × 2. We’re almost done. Let me see—I don’t like this color at all.
And now, we’re going to multiply this row because we’re in this bottom row. We’re in row two, column two. Row two. Column two, so it’s -2 × 3 + 0 × 5 + 5 × 5.And then, if we simplify—let’s see, this is—-3 + 0 + 4. So this is—if my math correct, this simplifies to 1. 9 + 5 is 14 + 10 is 24. This is 1 24 and then -2 ×— 2+ 10, this is just 12, right? It’s 12. And then -2 × 3, it’s 6 - 6 + 10, this is zero. So -6 + 10 is 4. So that’s interesting.
When I multiply the two by three vector times the three by two vectors, what did I get? I got a two by two—sorry—matrix. A two by three matrix—two by three times three by two matrixes, I got a two by two matrix.
And where do you a two by two? Well it’s kind of like, this got multiplied with this and we have leftovers of two by two matrix. So in general, actually before I go into the general, let me ask you a question. Could I have multiplied the matrices the other way? Could I have multiplied? So this right here, that is A × B or you can sometimes write as AB and we bold it all it up so we know they’re matrices.
So could we have multiplied B × A? Let me clear this down here and let’s try. Let’s see if we can multiply B × A. And I think you can already suspect since I’m asking the question. Maybe you can not. So let’s see. Let me clear up some space.
So let’s try to do it the other way around. Let’s try to multiply B × A. So B is -1 0 2 3 5 5 and A is—I am just switching the order. 3 1 2 -2 0 5. And I tend to put brackets around my matrices. Some people have these big parentheses. It’s just all notation. There’s nothing particular about notation.
So let’s see if we can multiply these. So we learned that you get row information from the first matrix and the column information from the second one. So this term in theory should be that row times what? Times—well actually, it turns out that you can multiply them because why? Because this is a three by two and this is a two by three, right? So we’re going to take that row times what? Times this column to get the first term, right?
So what is it going to be? It’s going to be -1. So I actually thought I was doing a counter example but they actually—because this two is the same as this or when you switch the row this is the same as this. It actually—you can multiply them. So I wanted to do a counter example but hey! Let’s just work through this because it never hurts to see another example. And as you can see I just did on the fly, so let’s do this. And actually I’ll—just as ahead of time, how large will this matrix be? Well that’s interesting. It’s actually going to be a three by three matrix. This is going to be a much bigger matrix.
So let’s work it all out and maybe you want to pause it and try it yourself. So it’s this row times this column. So -1 × 3, it’s -3—this is -3 ×—and then 3 × -2 is -6. And then it’s going to be this row times this column. So it’s -1 × 1 + 3 × 0. So that’s just -1, right? Because 3 × 0 is zero.
And then—so that’s—now it’s that one then the middle one and now we have the row one, column three. So row one, column three, so it’s that row times this column. You can tell this is often better than by a computer. -1 × 2 is -2 + 15, 3 × 5. So -2 +13. Let’s keep going. So now, we’re going to take—this is—I’m sweating. This is so computationally intensive.
Let me take this row times each of these columns. And actually we’re going to learn later, there are multiple ways of actually kind of thinking about how this multiplication happens or even multiple ways to compute it but this is the traditional way.
So this row times each of these columns, right? So 0 5. So 0 × 3 + 5 × -2, that’s -10. And 0 × 1 + 5 × 0, that’s easy. That’s zero. 0 × 2 + 5 × 5, that’s 25. Almost there. Almost done. Now, we’re going to take this row and multiply it times each of these columns.
So 2 × 3 +—so that’s 6 + -10, so that’s -4, right. 2 × 3 + 5 × -2. Yeah, that’s -4; 6 -—right. If 2 × 1 + 5 × 0, that’s 2. Then you have 2 × 2 + 5 × 5. So 4 + 25= 29. And of course that first term -3 -6. So this is -9.
So there you have it. We multiply the three by two matrix times the two by three matrix and we got a three by three matrix and where did that three by three came from? Because these are—these three are a number of rows in the first matrix and this three is a number of columns in the second matrix, which makes sense because we got our row information from the first matrix and our column information from the second matrix.
Now, let me actually show you an example that you can not multiply. So what if I wanted to multiply a—let me do a very simple example. What if I wanted to multiply the matrix 2 1 and really this is—all this is, is a row vector. And let’s say that I wanted to multiply this times—I want to multiply this times—I don’t know. So this is a two by one.
So then let me say I wanted to multiply this times—so, let me think of something—1 2 3 4 5 6. Now, can I multiply this? Well what do—and this is what? This is a three by two matrix. Can I multiply these two matrices?
Well, what do we have to do? We get our row information from here and our column information from here. Oh sorry. This isn’t two by one. This is one row, two columns. This is a one by two, right? That’s a one by two matrix.
So, can you multiply a one by two time a three by two matrix? So, we got our row information from here. So, we essentially have to multiply this times this column to get our first element. Then this times this column together, second element. And I don’t know what happens from there but let me—well, can we multiply? Can—just the way we have defined our multiplication of the dot product. Can we multiply?
You see 2 × 1 + 1 × 2 but then we don’t have anything to do with 3. So that way that we’ve defined matrix multiplication, you can not multiply these two matrices. And you didn’t have to go through that exercise. You could have looked at the dimension. One by two and this is a three by two. This two is not equal to this 3. The number of columns in the first are not equal to the number of rows in the second. So you can not multiply those two matrices.
So that is something interesting to think about. And they’re actually examples and it’s a good exercise for you to think about it where you can multiply them—you know, where you can multiply A × B but you can’t multiply B × A. So that—and I want you to think about examples where that happens.
But anyway, I am pushing 15 minutes. And I will see you in the next video.
Transcription by:
Scribe4you Transcription Services