# Dot Product

## Dot Product

Transcript: So, let's see, so let's start right away with stuff that we will need to see before we can go on to more advanced things. So, hopefully yesterday in recitation, you heard a bit about vectors. How many of you actually knew about vectors before that? OK, that's the vast majority. If you are not one of those people, well, hopefully you'll learn about vectors right now. I'm sorry that the learning curve will be a bit steeper for the first week. But hopefully, you'll adjust fine. If you have trouble with vectors, do go to your recitation instructor's office hours for extra practice if you feel the need to. You will see it's pretty easy.

So, just to remind you, a vector is a quantity that has both a direction and a magnitude of length. So -- So, concretely the way you draw a vector is by some arrow, like that, OK? And so, it has a length, and it's pointing in some direction. And, so, now, the way that we compute things with vectors, typically, as we introduce a coordinate system. So, if we are in the plane, x-y-axis, if we are in space, x-y-z axis. So, usually I will try to draw my x-y-z axis consistently to look like this.

And then, I can represent my vector in terms of its components along the coordinate axis. So, that means when I have this row, I can ask, how much does it go in the x direction? How much does it go in the y direction? How much does it go in the z direction? And, so, let's call this a vector A. So, it's more convention. When we have a vector quantity, we put an arrow on top to remind us that it's a vector. If it's in the textbook, then sometimes it's in bold because it's easier to typeset.

If you've tried in your favorite word processor, bold is easy and vectors are not easy. So, the vector you can try to decompose terms of unit vectors directed along the coordinate axis. So, the convention is there is a vector that we call hat that points along the x axis and has length one. There's a vector called hat that does the same along the y axis, and the hat that does the same along the z axis.

And, so, we can express any vector in terms of its components. So, the other notation is between these square brackets. Well, in angular brackets. So, the length of a vector we denote by, if you want, it's the same notation as the absolute value. So, that's going to be a number, as we say, now, a scalar quantity. OK, so, a scalar quantity is a usual numerical quantity as opposed to a vector quantity. And, its direction is sometimes called dir A, and that can be obtained just by scaling the vector down to unit length, for example, by dividing it by its length.

So -- Well, there's a lot of notation to be learned. So, for example, if I have two points, P and Q, then I can draw a vector from P to Q. And, that vector is called vector PQ, OK? So, maybe we'll call it A. But, a vector doesn't really have, necessarily, a starting point and an ending point. OK, so if I decide to start here and I go by the same distance in the same direction, this is also vector A. It's the same thing. So, a lot of vectors we'll draw starting at the origin, but we don't have to.

So, let's just check and see how things went in recitation. So, let's say that I give you the vector <3,2,1>. And so, what do you think about the length of this vector? OK, I see an answer forming. So, a lot of you are answering the same thing. Maybe it shouldn't spoil it for those who haven't given it yet. OK, I think the overwhelming vote is in favor of answer number two. I see some sixes, I don't know. That's a perfectly good answer, too, but hopefully in a few minutes it won't be I don't know anymore.

So, let's see. How do we find -- -- the length of a vector three, two, one? Well, so, this vector, A, it comes towards us along the x axis by three units. It goes to the right along the y axis by two units, and then it goes up by one unit along the z axis. OK, so, it's pointing towards here. That's pretty hard to draw. So, how do we get its length? Well, maybe we can start with something easier, the length of the vector in the plane. So, observe that A is obtained from a vector, B, in the plane. Say, B equals three (i) hat plus two (j) hat.

And then, we just have to, still, go up by one unit, OK? So, let me try to draw a picture in this vertical plane that contains A and B. If I draw it in the vertical plane, so, that's the Z axis, that's not any particular axis, then my vector B will go here, and my vector A will go above it. And here, that's one unit. And, here I have a right angle. So, I can use the Pythagorean theorem to find that length A^2 equals length B^2 plus one. Now, we are reduced to finding the length of B. The length of B, we can again find using the Pythagorean theorem in the XY plane because here we have the right angle. Here we have three units, and here we have two units.

OK, so, if you do the calculations, you will see that, well, length of B is square root of (3^2 2^2), that's 13. So, the square root of 13 -- -- and length of A is square root of length B^2 plus one (square it if you want) which is going to be square root of 13 plus one is the square root of 14, hence, answer number two which almost all of you gave. OK, so the general formula, if you follow it with it, in general if we have a vector with components a1, a2, a3, then the length of A is the square root of a1^2 plus a2^2 plus a3^2.

OK, any questions about that? Yes? Yes. So, in general, we indeed can consider vectors in abstract spaces that have any number of coordinates. And that you have more components. In this class, we'll mostly see vectors with two or three components because they are easier to draw, and because a lot of the math that we'll see works exactly the same way whether you have three variables or a million variables.

If we had a factor with more components, then we would have a lot of trouble drawing it. But we could still define its length in the same way, by summing the squares of the components. So, I'm sorry to say that here, multi-variable, multi will mean mostly two or three. But, be assured that it works just the same way if you have 10,000 variables. Just, calculations are longer. OK, more questions? So, what else can we do with vectors? Well, another thing that I'm sure you know how to do with vectors is to add them to scale them.

So, vector addition, so, if you have two vectors, A and B, then you can form, their sum, A plus B. How do we do that? Well, first, I should tell you, vectors, they have this double life. They are, at the same time, geometric objects that we can draw like this in pictures, and there are also computational objects that we can represent by numbers. So, every question about vectors will have two answers, one geometric, and one numerical.

OK, so let's start with the geometric. So, let's say that I have two vectors, A and B, given to me. And, let's say that I thought of drawing them at the same place to start with. Well, to take the sum, what I should do is actually move B so that it starts at the end of A, at the head of A. OK, so this is, again, vector B. So, observe, this actually forms, now, a parallelogram, right? So, this side is, again, vector A. And now, if we take the diagonal of that parallelogram, this is what we call A plus B, OK, so, the idea being that to move along A plus B, it's the same as to move first along A and then along B, or, along B, then along A. A plus B equals B plus A.

OK, now, if we do it numerically, then all you do is you just add the first component of A with the first component of B, the second with the second, and the third with the third. OK, say that A was B was , then you just add this way. OK, so it's pretty straightforward. So, for example, I said that my vector over there, its components are three, two, one. But, I also wrote it as 3i 2j k. What does that mean? OK, so I need to tell you first about multiplying by a scalar. So, this is about addition.

So, multiplication by a scalar, it's very easy. If you have a vector, A, then you can form a vector 2A just by making it go twice as far in the same direction. Or, we can make half A more modestly. We can even make minus A, and so on. So now, you see, if I do the calculation, 3i 2j k, well, what does it mean? 3i is just going to go along the x axis, but by distance of three instead of one. And then, 2j goes two units along the y axis, and k goes up by one unit. Well, if you add these together, you will go from the origin, then along the x axis, then parallel to the y axis, and then up. And, you will end up, indeed, at the endpoint of a vector.

OK, any questions at this point? Yes? Exactly. To add vectors geometrically, you just put the head of the first vector and the tail of the second vector in the same place. And then, it's head to tail addition. Any other questions? Yes? That's correct. If you subtract two vectors, that just means you add the opposite of a vector. So, for example, if I wanted to do A minus B, I would first go along A and then along minus B, which would take me somewhere over there, OK? So, A minus B, if you want, would go from here to here.

OK, so hopefully you've kind of seen that stuff either before in your lives, or at least yesterday. So, I'm going to use that as an excuse to move quickly forward. So, now we are going to learn a few more operations about vectors. And, these operations will be useful to us when we start trying to do a bit of geometry. So, of course, you've all done some geometry. But, we are going to see that geometry can be done using vectors.

And, in many ways, it's the right language for that, and in particular when we learn about functions we really will want to use vectors more than, maybe, the other kind of geometry that you've seen before. I mean, of course, it's just a language in a way. I mean, we are just reformulating things that you have seen, you already know since childhood. But, you will see that notation somehow helps to make it more straightforward.

So, what is dot product? Well, dot product as a way of multiplying two vectors to get a number, a scalar. And, well, let me start by giving you a definition in terms of components. What we do, let's say that we have a vector, A, with components a1, a2, a3, vector B with components b1, b2, b3. Well, we multiply the first components by the first components, the second by the second, the third by the third.

If you have N components, you keep going. And, you sum all of these together. OK, and important: this is a scalar. OK, you do not get a vector. You get a number. I know it sounds completely obvious from the definition here, but in the middle of the action when you're going to do complicated problems, it's sometimes easy to forget. So, that's the definition. What is it good for? Why would we ever want to do that? That's kind of a strange operation. So, probably to see what it's good for, I should first tell you what it is geometrically. OK, so what does it do geometrically?

Well, what you do when you multiply two vectors in this way, I claim the answer is equal to the length of A times the length of B times the cosine of the angle between them. So, I have my vector, A, and if I have my vector, B, and I have some angle between them, I multiply the length of A times the length of B times the cosine of that angle. So, that looks like a very artificial operation. I mean, why would want to do that complicated multiplication? Well, the basic answer is it tells us at the same time about lengths and about angles. And, the extra bonus thing is that it's very easy to compute if you have components, see, that formula is actually pretty easy. So, OK, maybe I should first tell you, how do we get this from that?

Because, you know, in math, one tries to justify everything to prove theorems. So, if you want, that's the theorem. That's the first theorem in 18.02. So, how do we prove the theorem? How do we check that this is, indeed, correct using this definition? So, in more common language, what does this geometric definition mean? Well, the first thing it means, before we multiply two vectors, let's start multiplying a vector with itself. That's probably easier. So, if we multiply a vector, A, with itself, using this dot product, so, by the way, I should point out, we put this dot here. That's why it's called dot product. So, what this tells us is we should get the same thing as multiplying the length of A with itself, so, squared, times the cosine of the angle.

But now, the cosine of an angle, of zero, cosine of zero you all know is one. OK, so that's going to be length A^2. Well, doesn't stand a chance of being true? Well, let's see. If we do AdotA using this formula, we will get a1^2 a2^2 a3^2. That is, indeed, the square of the length. So, check. That works. OK, now, what about two different vectors? Can we understand what this says, and how it relates to that? So, let's say that I have two different vectors, A and B, and I want to try to understand what's going on.

So, my claim is that we are going to be able to understand the relation between this and that in terms of the law of cosines. So, the law of cosines is something that tells you about the length of the third side in the triangle like this in terms of these two sides, and the angle here. OK, so the law of cosines, which hopefully you have seen before, says that, so let me give a name to this side.

Let's call this side C, and as a vector, C is A minus B. It's minus B plus A. So, it's getting a bit cluttered here. So, the law of cosines says that the length of the third side in this triangle is equal to length A2 plus length B2. Well, if I stopped here, that would be Pythagoras, but I don't have a right angle. So, I have a third term which is twice length A, length B, cosine theta, OK? Has everyone seen this formula sometime? I hear some yeah's. I hear some no's. Well, it's a fact about, I mean, you probably haven't seen it with vectors, but it's a fact about the side lengths in a triangle. And, well, let's say, if you haven't seen it before, then this is going to be a proof of the law of cosines if you believe this. Otherwise, it's the other way around.

So, let's try to see how this relates to what I'm saying about the dot product. So, I've been saying that length C^2, that's the same thing as CdotC, OK? That, we have checked. Now, CdotC, well, C is A minus B. So, it's A minus B, dot product, A minus B. Now, what do we want to do in a situation like that? Well, we want to expand this into a sum of four terms. Are we allowed to do that? Well, we have this dot product that's a mysterious new operation. We don't really know. Well, the answer is yes, we can do it. You can check from this definition that it behaves in the usual way in terms of expanding, vectoring, and so on.

So, I can write that as AdotA minus AdotB minus BdotA plus BdotB. So, AdotA is length A^2. Let me jump ahead to the last term. BdotB is length B^2, and then these two terms, well, they're the same. You can check from the definition that AdotB and BdotA are the same thing. Well, you see that this term, I mean, this is the only difference between these two formulas for the length of C. So, if you believe in the law of cosines, then it tells you that, yes, this a proof that AdotB equals length A length B cosine theta.

Or, vice versa, if you've never seen the law of cosines, you are willing to believe this. Then, this is the proof of the law of cosines. So, the law of cosines, or this interpretation, are equivalent to each other. OK, any questions? Yes? So, in the second one there isn't a cosine theta because I'm just expanding a dot product. OK, so I'm just writing C equals A minus B, and then I'm expanding this algebraically. And then, I get to an answer that has an A.B. So then, if I wanted to express that without a dot product, then I would have to introduce a cosine. And, I would get the same as that, OK? So, yeah, if you want, the next step to recall the law of cosines would be plug in this formula for AdotB.

And then you would have a cosine. OK, let's keep going. OK, so what is this good for? Now that we have a definition, we should figure out what we can do with it. So, what are the applications of dot product? Well, will this discover new applications of dot product throughout the entire semester,but let me tell you at least about those that are readily visible. So, one is to compute lengths and angles, especially angles. So, let's do an example.

Let's say that, for example, I have in space, I have a point, P, which is at (1,0,0). I have a point, Q, which is at (0,1,0). So, it's at distance one here, one here. And, I have a third point, R at (0,0,2), so it's at height two. And, let's say that I'm curious, and I'm wondering what is the angle here? So, here I have a triangle in space connect P, Q, and R, and I'm wondering, what is this angle here? OK, so, of course, one solution is to build a model and then go and measure the angle. But, we can do better than that. We can just find the angle using dot product. So, how would we do that? Well, so, if we look at this formula, we see, so, let's say that we want to find the angle here.

Well, let's look at the formula for PQdotPR. Well, we said it should be length PQ times length PR times the cosine of the angle, OK? Now, what do we know, and what do we not know? Well, certainly at this point we don't know the cosine of the angle. That's what we would like to find. The lengths, certainly we can compute. We know how to find these lengths. And, this dot product we know how to compute because we have an easy formula here. OK, so we can compute everything else and then find theta. So, I'll tell you what we will do is we will find theta --

-- in this way. We'll take the dot product of PQ with PR, and then we'll divide by the lengths. OK, so let's see. So, we said cosine theta is PQdotPR over length PQ length PR. So, let's try to figure out what this vector, PQ, well, to go from P to Q, I should go minus one unit along the x direction plus one unit along the y direction. And, I'm not moving in the z direction. So, to go from P to Q, I have to move by <-1,1,0>. To go from P to R, I go -1 along the x axis and 2 along the z axis. So, PR, I claim, is this. OK, then, the lengths of these vectors, well,(-1)^2 (1)^2 (0)^2, square root, and then same thing with the other one.

OK, so, the denominator will become the square root of 2, and there's a square root of 5. What about the numerator? Well, so, remember, to do the dot product, we multiply this by this, and that by that, that by that. And, we add. Minus 1 times minus 1 makes 1 plus 1 times 0, that's 0. Zero times 2 is 0 again. So, we will get 1 over square root of 10. That's the cosine of the angle. And, of course if we want the actual angle, well, we have to take a calculator, find the inverse cosine, and you'll find it's about 71.5°.

Actually, we'll be using mostly radians, but for today, that's certainly more speaking. OK, any questions about that? No? OK, so in particular, I should point out one thing that's really neat about the answer. I mean, we got this number. We don't really know what it means exactly because it mixes together the lengths and the angle. But, one thing that's interesting here, it's the sign of the answer, the fact that we got a positive number. So, if you think about it, the lengths are always positive. So, the sign of a dot product is the same as a sign of cosine theta. So, in fact, the sign of AdotB is going to be positive if the angle is less than 90°.

So, that means geometrically, my two vectors are going more or less in the same direction. They make an acute angle. It's going to be zero if the angle is exactly 90°, OK, because that's when the cosine will be zero. And, it will be negative if the angle is more than 90°. So, that means they go, however, in opposite directions. So, that's basically one way to think about what dot product measures. It measures how much the two vectors are going along each other. OK, and that actually leads us to the next application. So, let's see, did I have a number one there? Yes. So, if I had a number one, I must have number two.

The second application is to detect orthogonality. It's to figure out when two things are perpendicular. OK, so orthogonality is just a complicated word from Greek to say things are perpendicular. So, let's just take an example. Let's say I give you the equation x 2y 3z = 0. OK, so that defines a certain set of points in space, and what do you think the set of solutions look like if I give you this equation? So far I see one, two, three answers, OK.

So, I see various competing answers, but, yeah, I see a lot of people voting for answer number four. I see also some I don't knows, and some other things. But, the majority vote seems to be a plane. And, indeed that's the correct answer. So, how do we see that it's a plane? So, I should say, this is the equation of a plane. So, there's many ways to see that, and I'm not going to give you all of them. But, here's one way to think about it. So, let's think geometrically about how to express this condition in terms of vectors. So, let's take the origin O, by convention is the point (0,0,0).

And, let's take a point, P, that will satisfy this equation on it, so, at coordinates x, y, z. So, what does this condition here mean? Well, it means the following thing. So, let's take the vector, OP. OK, so vector OP, of course, has components x, y, z. Now, we can think of this as actually a dot product between OP and a mysterious vector that won't remain mysterious for very long, namely, the vector one, two, three. OK, so, this condition is the same as OP.A equals zero, right? If I take the dot product OPdotA I get x times one plus y times two plus z times three.

But now, what does it mean that the dot product between OP and A is zero? Well, it means that OP and A are perpendicular. OK, so I have this vector, A. I'm not going to be able to draw it realistically. Let's say it goes this way. Then, a point, P, solves this equation exactly when the vector from O to P is perpendicular to A. And, I claim that defines a plane. For example, if it helps you to see it, take a vertical vector. What does it mean to be perpendicular to the vertical vector? It means you are horizontal. It's the horizontal plane. Here, it's a plane that passes through the origin and is perpendicular to this vector, A.

OK, so what we get is a plane through the origin perpendicular to A. And, in general, what you should remember is that two vectors have a dot product equal to zero if and only if that's equivalent to the cosine of the angle between them is zero. That means the angle is 90°. That means A and B are perpendicular. So, we have a very fast way of checking whether two vectors are perpendicular. So, one additional application I think we'll see actually tomorrow is to find the components of a vector along a certain direction. So, I claim we can use this intuition I gave about dot product telling us how much to vectors go in the same direction to actually give a precise meaning to the notion of component for vector, not just along the x, y, or z axis, but along any direction in space.

So, I think I should probably stop here. But, I will see you tomorrow at 2:00 here, and we'll learn more about that and about cross products.