 So we gaan start of by introducing vectors. I've opened an ipython notebook here. I've called my file chapter one underscore zero underscore vectors. And here we go. In this first cell you can see I've just made it a heading one. So it prints out nice and bold and all I've typed in is an introduction to vectors. And in my second cell was this normal mark down. And let me show you what that mark down looks like. It's this basic html. Importing the required python and then superscript. And this is the html code for the trademark sign. And I'm putting it as superscript libraries. If I were to run that cell, there we go. Importing the required python libraries nicely printed. So here we go. We're going to use sympy to do our vector analysis in. And to do that, I need to import sympy. But not only sympy, some subsets of sympy. All sorts of things that I want to import before we can start talking about vectors. So let's look at this first line. I say from sympy import the following. So these are just functions, code or whatever you want to call it inside of sympy that I want to import. So that I don't have to refer to sympy.sign, sympy.cosign. Or if I wanted to use an abbreviation for sympy, sym. So I wouldn't have to write sympy.sign, sym.cosign, et cetera, et cetera, all the time. So these are all, these functions within sympy that I want to use in this program. I'm going to use sign, cosine, tangent, exponent, square root. Innet underscore printing, we'll see what that is again, and symbols. And sympy has some, a subset of libraries called physics.vector. If you were to type from sympy.physics.you'll see there's a lot of stuff there. And I'm just using vector. And from that I want to import everything. It's a bit lazy thing to do. Because I'm going to take up memory and take up time to import all of these. But for now we're not doing anything too serious with vectors. So we can do that. From the ipython.core.display library, I want to import this function called image with a capital I. See what that will do. And then from the warnings library, I want to import filter warnings. And then this last instance, you'll see that I'm using the Anaconda version of Python on the Macian. I'm using the 2.7.8 version. And the only function that I'm going to use is the print function. And the print function between the 2.x and 3.x versions of Python differ. Even though this is 2.7.8, I'm going to use the print format that is used in the 3.x series. So I can do this. This is very neat from future import print underscore function. And there's two underscores there and two underscores there. So I can now use Python 3 code as far as the print function is concerned inside my Python 2.7 here. And it'll still work. Now remember I imported in it printing. There I have in it underscore printing open and close parenthesis. And that's going to initialize pretty printing for me. We using Sympi as a computer algebra system. So we want nice LaTeX printer to the screen. We want to see those nice mathematical symbols. So I'm initializing it there. And many times in the iPython notebook you'll write some code that will execute, but it makes these ugly pink warnings. And I had seen those up here. So I'm going to set filter warnings, which I imported it there from the warnings library. We're going to set filter warnings, open and close parenthesis, open and close quotation marks. I like to use single quotation marks and I'm going to set it to ignore. So we're not going to have any of those ugly things. So in that cell let's just play that. In this cell let's just play that so that code is executed. So let's get to a vector. What is a vector? Well a vector is this mathematical object that contains a magnitude and a direction. Specified in a specific reference frame. Very important to have a reference frame. Otherwise your magnitude and your direction might not mean much. So you've got to have this reference frame. So for now in this first chapter, actually this .0 version of this chapter, we're just going to introduce vectors. Now we're not going to deal with vectors much. We're going to deal with vector based functions. But in order for us to understand vector based functions, we need to have this quick refresher course on a vector. Very importantly we're going to state that a vector can be defined as an object that is not invariant to access transformation. So when you transform axes you're going to have a different object. This is opposed to a scalar quantity which only has magnitude and is invariant to access transformation. It's not going to change the value if we transform axes. It's not going to make a lot of sense now. We'll get to it. Now the figure below shows a vector. Now let's just go down. There's our figure. Now unfortunately there's my vector in red. What you will have to imagine is at the top here it has a little arrow sign. So this red is an arrow pointing up. Apologies for the arrow not being there. It's a bit big for the screen here but it starts at the origin and it goes up to a point that seems to be 3,6. 3,6 is the point there. It's not a point 3,6. X,y 3,6. It is a vector going from the origin to the point 3,6. What can we note about this? Well, it looks like it goes three units on the x-axis and six units on the y-axis. And that is how we construct this. So it certainly has in this coordinate system. Look, this is my reference frame. It's a Cartesian coordinate system in two space. It's a X and a Y coordinate system. In this reference frame I have this direction. It seems to slope up in that direction and it has a magnitude because it has a certain length. So I could put an angle down here so it will have a direction and it will have a length and there's my vector but it seems to be comprised of these two components an X component and a Y component that should be very familiar to you. In Python, before we define a vector we have to define a reference frame. In the Sympi.physics.vector library I have imported everything and one of those everythings, one of the functions is a reference frame. Capital R, capital F and I'm going to assign it to this computer variable called C. So I'm going to create a little space in memory I'm going to call that space C and to that I'm going to attach the following object, a reference frame open and close parentheses and I call it C. Try and call these things the same thing otherwise it might get confusion and I use C for Cartesian but I could have put any string there that I wanted. So I have this reference frame called C to which I can now refer. Now I'm going to create, let's just run that so it's executed, creating a vector. So again I'm creating a computer variable there I'm calling it vector I could have called it anything I could have called it my dog is cute whatever I want I can use any string there or any number there are keywords of course and you can't start with funny symbols oh there's all sorts of rules to these names doesn't matter I've just called mine vector so I'm creating a space in memory and I'm calling it vector and into that little space in memory I'm putting this object and this is a vector that I'm putting in there now look how I refer C remember C is my coordinate system and it has a C dot X and a C dot Y component so my reference frame in the X direction my reference frame in the Y direction isn't that beautiful now that is built into the Sympi library and I can just use it and I'm saying go 3 times in the X direction so 1, 2, 3 units plus 6 times that star remember that's shift 8 most keyboards and in the Y direction so that's what I have now let's execute that and now for now putting that into memory so look at this print and this is the difference between the versions 2 and 3 in Python I've got these parentheses but because I've imported everything from the future or at least the print function from the future I can use this version here which looks like Python 3 so print open and close parentheses open and close these quotation marks meaning that I've got to put a string in between the vector is expressed as colon space so this is my print command so I'm going to print that to the screen and in the new line I'm going to print this whatever is held in memory in this bucket called vector remember which was this up here which was this vector so let's run this piece of code and that's beautiful and I have 3 X C hat subscript X plus 6 C hat subscript Y what does that mean well that is the way SimPy makes its notation that little hat refers to the fact that it's a unit vector a unit vector has a length of 1 and it points in a certain direction so it actually only shows me direction and this is our vector we're going 3 along the X axis and 3 along the Y axis so it's actually 3 times C hat subscript X plus 6 times C hat these hat in physics we refer to this hat as a unit vector it has a length of 1 in a certain direction this direction will be in X and this in Y and it's called C here because I called my reference frame C now note something else that this vector is simply the addition of 2 vectors 1 of magnitude 3 in the direction of the X axis oh there's a horrible spelling mistake let's make it, let's correct it now in the direction of the X axis and look at this beautiful example it's just the HTML code that I have here let's run that because we've called the cell a mark down type of cell so if we go back to our figure here look I'm just going I'm adding 2 vectors it seems 3 in the X direction so 3 times this unit vector and 6 times the unit vector in that direction and if I add those 2 so if this was 1 I had a little arrow there so this we call the tail and this we call the head and I take a second one and it's tail is by the first one's head and there's the head at the top and if I were to combine these 2 by going from the first one's tail to the last one's head I seem to get that vector and that's beautiful because that brings us right into vector addition and subtraction so let's make another vector and again just a computer variable a little space in memory I'm calling that bucket that space memory another underscore vector I could have called it whatever I wanted within the limitations of what you can call these things and that equals 2 times again I'm using my Cartesian reference frame that I stipulated above so twice in the X direction plus 1 in the Y direction so let's run that code it's in memory now and I'm going to print to the screen the addition of the 2 vectors are so it's my print command my open and close parentheses my open and close quotation marks if I have quotation marks everything in between will be a string and it will print directly as I've typed it there even with that space and on a new line I will add these 2 vectors vector plus another vector so remember the one was 3 in the X direction and 6 in the Y direction and this one's going to be 2 in the X direction 1 in the Y direction and if I add them let's run this block of code run it and lo and behold it's now 5 in the X direction and 7 in the X direction so what happened we just added the 2 components to each other the X to the X and the Y to the Y that's all we've done that's how you add there's the plus mark we add 2 vectors now in some pie this was a computer variable this vector and another vector so please please don't get confused I'm only calling them this so that I can refer to them out of computer memory remember mathematics doesn't work like that mathematics one we want an actual symbol that we can write down that's got nothing to do with a computer variable that's a mathematical variable so we must tell some pie that we will now want to instead of this X1 being a computer memory variable I want it to be a mathematical variable and for that we use this symbols that come straight from the some pie library symbols so I'm going to say X1, X2, Y1, Y2 those are now going to be symbols open and close parentheses open and close single quotation marks I can put a comma after that but you can just put a space X1, X2, XC so if X1 is first make X1 first there because the order is important the first one will refer to the first one the second one to the second one this is just telling python every time I now type X1 I want you not to see it as a computer variable name I want you to see it as a mathematical symbol so let's just run that piece of code now let's make two new computer variables I've called that one V1 and V2 these are still computer variables as I said I could have written there my dog is black and white whatever I want I can call it like that call it so I've just called it V1 and V2 to refer to vector 1 and vector 2 but I'm going to to these two buckets in memory spaces in memory with the bucket names V1 and V2 so these computer variables I'm attaching these two following vectors X1 which is now not a computer variable but a mathematical variable X1 times in the X direction and Y1 in the Y direction and X2 and Y2 let's run that block of code and let's print it to the screen so now I can just call that bucket in memory and whatever is in memory there which is this bit here which is this bit we'll now print to the screen and so let's run this code and see it there already it's beautiful look at that now X sub 1 is written so nicely X sub 1 it looks like you've written it by hand in your paper notebook with pencil isn't that beautiful that's what the init printing does the pretty printing in Lartek so it's X sub 1 in the X direction and Y sub 1 in the Y direction and if I run V2 beautifully that's X sub 2 in the X direction and Y sub 2 and now let's just add these two again my error in spelling there in there today has been a horrible day as far as spelling is concerned let's run that there we go now I'm going to say V1 and V2 remember V1 is that vector V2 is that vector I'm just referring to their computer variable names and if I add them look what SimPy does it shows you that it's just taking the X components and adding them together and taking the Y components and adding them together that's how we do vector addition and the same is going to go for vector subtraction which one you put first which one you put second is important and it's just going to subtract those components in that direction in the reference frame that you use from each other so vector addition and vector subtraction is very easy we can also multiply a scalar remember I said a scalar is just a magnitude just a value doesn't have a direction I can multiply that by a vector again I'm going to introduce this variable A call it symbols A so I'm creating another mathematical variable and in this time I'm going to call it A and I'm just going to use it as a constant you can use it whatever you want but now I'm going to say A times V1 let's just run this bit of code so it executes and now run this bit of code so that it executes look what it did it took my X1 and Y1 which is my initial vector V1 and it took and it multiplied A to each of the components it is a scalar multiplication this constant it just gets multiplied inside of the two components the next thing is the magnitude of a vector now look back at our little picture up here remember Pythagoras what was going to be the magnitude or length of this line well it's this one squared plus that one squared equals this I put a new squared if I take the square root of that what am I going to get lo en behold I'm going to get the length of this same is going to happen here to a vector if I get a vector's magnitude except it's very easy to do in Python I'm just going to say V1 now that's the name the computer variable name but inside of that little bucket in memory is a vector and I'm going to say dot magnitude open and close parentheses and lo en behold if I were to run that look at this pretty it's the square root of the one component squared plus the other component squared all that is is Pythagoras nothing else and that works beautifully for a vector because my Cartesian coordinate system here has a 90 degree angle between the two axes let's introduce another mathematical symbol I'm going to call it Z1 and if you write it like that Python will do it as an underscore I'm going to make a new vector call it V3 space in memory so this is a computer variable but it's X1 in the X direction plus Y1 times the Y direction plus Z1 times the Y direction plus Z1 times the Z direction and then just print it to the scheme by just simply typing on a new line V3 if I were to do that look at X1 in the X direction Y1 in the Y Z1 in the Z direction and lo en behold if I were to calculate the magnitude of that I can now just call V3 dot once you put the dot and you hit the tab button let's do that I'm going to do that for you well let's take this out if I were to type V3 look I want to show you if I were to type V3 dot and then the tab key look at all the stuff I can call on that vector arguments cross differentiate do it dot DT express magnitude is the one I want magnitude I can double click on it open and close parentheses and if I were to execute that I'm going to get X1 squared Y1 squared Z1 squared the square root of that that is still in three dimensions going to be the length or magnitude of my vector now remember we talked about the unit vector that is to take a vector remember a vector has a magnitude and a direction and I'm going to take that vector and I'm just going to get its unit vector in other words I'm going to change the magnitude to 1 but still in the direction of that's four if you think of a scalar say the number five what is five well this is five times a unit value of one if I put five ones together I get five it's five times one now the same is happening here I can take a vector and it has a direction and a magnitude and a direction as opposed to a scalar which is this magnitude but I can keep the direction but just bring the magnitude down to one and how do we do that you might remember you might be familiar with it well we just take a vector and we divide each component by the magnitude of that vector in other words you can also write one over the magnitude times the vector because the magnitude remember is a scalar one over a scalar and we know what a scalar times a vector is we've done that remember we said A times V1 so I'm just going to multiply that inside of each component so remember here V3 was a three dimensional vector and each component is just divided by the magnitude of that whole vector and this new vector is a unit vector it's still going to point in exactly the same direction as V3 but if I were to calculate from this if I were to calculate the magnitude of this whole vector it was going to equal a magnitude of one Python it's very easy I'm going to say v3.normalize open and close parentheses and if I were to execute that line of code beautifully there it shows you it is the length of that the magnitude of that vector it's just divided it becomes the denominator for each of the components lastly I just want to quickly look at the equality of vectors and this is remember this is how we define vectors let me just make the screen a bit smaller so we can try and fit this in there we go there are two lines there again apologies there should be an arrow head there and an arrow head there now look at these two vectors they have equal magnitude and they have the same direction even though they are in completely different spots in the Cartesian coordinate plane here if I were to drag this one down to that one put the tail this is the tail if I were to put that at the origin these two would lie exactly on top of each other and these are equal they are exactly the same they are not even equal they are exactly the same vector these two remember that was an arrow please just draw that in your imagination these are exactly the same because no matter where we draw it we do just move it down so that it's tail falls on the origin so if they have equal magnitude and equal direction two vectors are exactly the same please remember that so that's all for the introduction to vectors for most of you that's just a reminder just a little bit of a refresher on vectors and now we can go on to using vectors in vector based functions and that's exciting stuff