Matrix multiplication (part 2) More on multiplying matrices.
⇐ Use this menu to view and help create subtitles for this video in many different languages.
You'll probably want to hide YouTube's captions if using these subtitles.
- 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 a 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-- I'll do
- it relatively small so we don't run out of space.
- 3, 1, 2, minus 2, 0, 5.
- Let's say I want to multiply that times the matrix, minus
- 1, 0, 2, 3, 5, 5.
- I'm just making up these numbers.
- So the first thing you might be wondering is, well can I
- even multiply these matrices?
- Because you know from the first video we did on
- matrices, that you can't add these two matrices.
- This term corresponds to this one; this one corresponds to
- this one; but this term corresponds to nothing over
- here so you couldn't 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 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 is a
- quick way for 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 its
- column information from?
- Well, it gets its row information from here.
- So it is 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 3, right?
- But it's a 3 by 1, it has three elements in it.
- And this is a 1 by 3 row vector, but it also has three
- elements in it.
- So we actually can take the dot product or we can
- multiply these two.
- And similarly we can multiply this times this whole thing to
- get this term right here.
- And we can 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 it that this is matrix-- let me switch to
- [UNINTELLIGIBLE].
- So this is matrix A.
- And what are it's dimensions?
- It has 2 rows, 1, 2, and 3 columns.
- So it's a 2 by 3 matrix.
- We're multiplying it times B.
- And what are B's dimensions?
- Well, it has 3 rows, 1, 2, 3.
- So it is a 3 by-- and how many columns does it have?
- 1, 2-- 2 matrix.
- So it turns out that we can multiply two matrices.
- You can 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, 2 by 3 times 3 by 2, we can multiply.
- For example, we could have multiplied, if
- this is matrix C.
- I don't know if I take so much time to keep
- bolding these things.
- And I don't care how many rows it has.
- It can have n rows, n times a columns.
- I can multiply it times matrix D, as long as
- matrix D has a rows.
- As long as you can say these two inner numbers are the
- same, right?
- This 3 is the same as 3.
- And why does that matter, what was the logic?
- Because this row will have 3 elements because there's 3
- columns, and each column vector here will have 3
- elements, because there's 3 rows.
- That's where intuition comes from, but if you had to do it
- really quickly you say 2 by 3, 3 by 2, 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 where I should do it, actually I think I should
- do it down here maybe because I'll have more space.
- So let me do it down there; I don't have to
- erase anything else.
- So let me get some space ready.
- OK, this will take up a lot of space.
- So to get this row 1, column 1 element, what do I do?
- I multiply this vector times this vector.
- I take the dot product, right?
- So it's 3 times negative 1-- I'm just going to write it all
- -- 3 times minus 1, plus 1 times 0, plus 2 times 2.
- There, we got the first term.
- So the second term here, what am I going to do?
- I'm going to multiply that vector times that row vector
- times this column vector.
- And I think you're getting the hang of this, and really the
- hardest part about this is staying focused and not making
- a careless mistake.
- And not getting it confused with rows and
- columns and all that.
- It just 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 1, column 2, right?
- Because this row, row 1, column 2.
- 3 times 3, plus 1 times 5, plus 2 times 5, right.
- We're just multiplying the corresponding terms, the third
- term times the third term, the second term times the second
- term, the first term times the first term.
- Although, in this case they're going down, in this case
- they're going left and right.
- Oh, we add them all up.
- OK, so now we're in the second row, and we get our row
- information from the first vector-- and let me do a red
- that I never use because I think it's kind of tacky, this
- red right here.
- So I'm going to multiply this row vector
- times this column vector.
- So it's minus 2 times minus 1, plus 0 times 0,
- plus 5 times 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 2, column 2, to row 2, column 2.
- So it's minus 2 times 3, plus 0 times 5, plus 5 times 5.
- And then if we simplify, let's see, this is minus 3 plus 0,
- plus 4, so this-- if I have my math correct--
- simplifies to 1.
- 9 plus 5 is 14, plus 10 is 24.
- This is 1, 24, and then minus 2 times minus 1 is 2, plus 10,
- so this is 12.
- And then minus 2 times 3 is minus 6, plus 10-- this is 0--
- so minus 6 plus 10 is 4.
- So that's interesting.
- When I multiplied a 2 by 3 vector times a 3 by 2 vector,
- what did I get?
- I got a 2 by 2 matrix.
- A 2 by 3 matrix, a 2 by 3 times 3 by 2 matrix, I got a 2
- by 2 matrix.
- And where do you see a 2 by 2?
- Well, it's like this got multiplied with this, and what
- we have left over is a 2 by 2 matrix.
- So in general-- well 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
- times B, or you can sometimes write this AB, and we'd bold
- it all up so we know it's matrices.
- So could we have multiplied B times A?
- Let me clear this down here and let's try.
- Let's see if we can multiply B times A.
- I think you can already suspect that, since I'm asking
- the question, maybe you cannot.
- Let's clear up some space.
- Let's try to do it the other way around, let's try to
- multiply B times A.
- So B is minus 1, 0, 2, 3, 5, 5.
- And A is-- I'm switching the order-- 3, 1,
- 2, minus 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 you can multiply these.
- So we learned that you get the 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?
- Well, actually, it turns out that you can multiply them.
- Why?
- Because this is a 3 by 2, and this is a 2 by 3, 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 minus 1.
- So I actually thought I was doing a counter example, but
- actually because this too is the same as this, or when you
- switch the row this is the same as this, 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 you can see that I just do this on the fly.
- So let's do this.
- And actually ahead of time, how large will this matrix be?
- Well, this is interesting.
- It's actually going to be a 3 by 3 matrix,
- a much bigger matrix.
- Let's work it all out, and maybe you want to pause it and
- try it yourself.
- This row times this column, so minus 1 times 3, it's minus 3,
- 3 times minus 2 is minus 6.
- And then it's going to be this row times this column.
- So it's minus 1 times 1 plus 3 times 0, so that's
- just minus 1, right?
- Because 3 times 0 is 0.
- And then, that was that one, then there's the middle one,
- and now we get the row 1, column 3.
- So row 1, column 3.
- So it's that row times this column.
- You can tell, this is often better done by a computer.
- Minus 1 times 2 is minus 2 plus 15-- 3 times 5-- so minus
- 2 plus 5 is 13.
- Let's keep going.
- So now we're going to take--
- I'm sweating, this is so computationally intensive--
- We're taking this row times each of these columns.
- And actually we are going to learn later that there are
- multiple ways of actually thinking about how this
- multiplication happens, even multiple ways by computer, but
- this is the traditional way.
- So this row times each of these columns, right?
- So 0, 5, so 0 times 3 plus 5 times minus 2, that's minus
- 10, and it's 0 times 1 plus 5 times 0.
- That's easy, that's 0.
- 0 times 2 plus 5 times 5 is 25-- almost
- there, almost done.
- Now we're going to take this row and multiply it times each
- of these columns.
- So 2 times 3, that's 6, plus minus 10, so
- that's minus 4, right?
- 2 times 3 plus 5 times minus 2.
- Yes, that's minus 4, 6 minus 10, right?
- We have 2 times 1 plus 5 times 0, that's 2.
- Then you have 2 times 2 plus 5 times 5, so 4 plus 25 is 29.
- And of course that first term, minus 3 minus 6, so
- this is minus 9.
- So there you have it.
- We multiplied the 3 by 2 matrix times a 2 by 3 matrix,
- and we got a 3 by 3 matrix.
- And where did that 3 by 3 come from?
- Because this 3 is the number of rows in the first matrix,
- and this 3 is the 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 cannot 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, all this is, is a row vector.
- And let's say that I wanted to multiply this times-- I don't
- know, so this is a 2 by 1.
- So then let me say I want to multiply this times-- so let
- me think of something-- 1, 2, 3, 4, 5, 6.
- Now, can I multiply this?
- Well, what do we have?
- This is a 3 by 2 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 2 by 1, this is 1 row, two columns.
- This is a 1 by 2, right?
- That's a 1 by 2 matrix.
- So can you multiply the 1 by 2 times a 3 by 2 matrix?
- So we get our row information from here, so we essentially
- have to multiply this by this times this column to get our
- first element, then this times this column to
- get our second element.
- And I don't know what happens from there, but let me-- well,
- can we multiply?
- Just the way we have defined our multiplication, or the dot
- product, can we multiply?
- Let's see, 2 times 1 plus 1 times 2.
- Then we don't have anything to do with the 3.
- So the way that we've defined matrix multiplication, you
- cannot multiply these two matrices.
- And you didn't have to go through that exercise.
- You could've looked at the dimensions, 1 by 2, and this
- is a 3 by 2.
- This 2 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's 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 A times B,
- but you can't multiply B times A.
- So I want you think about examples where that happens.
- But anyway, I'm pushing 15 minutes, and I will see you in
- the next video.
Be specific, and indicate a time in the video:
At 5:31, how is the moon large enough to block the sun? Isn't the sun way larger?
|
Have something that's not a question about this content? |
This discussion area is not meant for answering homework questions.
Discuss the site
For general discussions about Khan Academy, visit our Reddit discussion page.
Flag inappropriate posts
Here are posts to avoid making. If you do encounter them, flag them for attention from our Guardians.
abuse
- disrespectful or offensive
- an advertisement
not helpful
- low quality
- not about the video topic
- soliciting votes or seeking badges
- a homework question
- a duplicate answer
- repeatedly making the same post
wrong category
- a tip or feedback in Questions
- a question in Tips & Feedback
- an answer that should be its own question
about the site
Share a tip
Suggest a fix
Have something that's not a tip or feedback about this content?
This discussion area is not meant for answering homework questions.