Transcript for:
Understanding Linear Transformations and Matrices

hey folks my name is nathan johnston and welcome to lecture 15 of introductory linear algebra now that we know what linear transformations are and we know how to represent them via matrices what we're going to do is we're just going to go through a whole bunch of examples of linear transformations that come up over and over and over again and we'll compute their standard matrices just to get comfortable with that procedure all right so let's get started let's start with sort of the simplest linear transformations that we're gonna see the zero and identity transformations so what these are well the zero transformation as its name source suggests it's the linear transformation that just sends every input vector to the zero vector as its output okay so it just squashes everything down to the zero vector and we denote it by sort of this capital o here that means zero linear transformation and then if we ask the question well what is the standard matrix of this zero linear transformation well it shouldn't be too surprising we're not actually going to go through the calculation but the standard matrix of the linear transformation zero is the zero matrix it's just the matrix that has a zero in every every single entry right because that matrix does the same thing if i do zero matrix times a vector i always get the zero vector as output it does the same thing as the linear transformation okay the identity transformation on the other hand it is the linear transformation that takes every input vector and just leaves it alone it outputs whatever the input was okay so it doesn't change anything and we denote this identity transformation just by i okay and again if we ask the question what is the standard matrix of this identity linear transformation then based on the naming that we've chosen here it shouldn't be too surprising that the standard matrix of the identity transformation is the identity matrix remember last week we learned about the identity matrix which was just the matrix that had ones down the diagonal and zeros everywhere else okay well the reason that matrix was special is because if we ever did that matrix times something it left that something alone okay and that's exactly what we want here we want something that leaves vectors alone doesn't change them okay so yeah so the matrix that does the same thing as the identity transformation is the identity matrix okay well let's ramp up just a little bit to something called diagonal transformations or diagonal matrices okay so what is a diagonal linear transformation well it's some linear transformation we're going to call it d for diagonal and what it does is it sort of doesn't mix the entries of the vectors that it acts on okay so it sends the vector v1 v2 up to vn to c1 times v1 c2 times v2 cn times vn where these c's those are just some fixed scalars they're numbers that are given to us okay so the the important point here is that like the output entry the first output entry it only depends on the first input entry the second output entry only depends on the second input entry and so on more general linear transformations can sort of mix and match things but for diagonal linear transformations they're sort of just uh there's only the only v entry that appears in this first entry is v1 the only v entry that appears in the second output entry is v2 and so on that's what makes it diagonal okay and the the reason that we call them diagonal is if you compute the standard matrix of these diagonal linear transformations what you get is a diagonal matrix you get a matrix that has something down the diagonal exactly these scalars down the diagonal in fact but then zeros everywhere else and remember that's what we call the diagonal matrix okay you can go through this calculation on your own very quickly if you want if you like remember the first column that is just whatever d does to the first standard basis vector so what does d do to e1 well you'd have one here and zeros everywhere else so you'll get a c1 here and zeros everywhere else that's why this first column is c1 then all the all zeros the second column is what you get if you plug e2 into d so you'll have zero one and then all zeros so you'll get zero c2 and then all zeros that's why you have this as your second column and so on down the line okay so that standard matrix is not difficult to compute it's just straight from the definition geometrically what these linear transformations are doing is well remember we can always imagine things that like in two-dimensional space as sort of a unit square grid and then the linear transformation is going to stretch and deform it in some way well i mean the the nice thing about diagonal linear transformations is they don't turn this just into some skewed ugly parallelogram grid but rather just sort of a stretched rectangular grid in other words they sort of respect coordinate axes like the x-axis here it just gets sent to the x-axis a stretched version of it but still just the x-axis and similarly the y-axis just gets mapped onto the y-axis it doesn't move it gets sort of stretched or shrunk depending on the value of c1 and c2 um but sort of it doesn't move so like it doesn't get deformed into a parallelogram grid it just gets stretched along the coordinate axes all right well let's look at another type of linear transformation called projection okay and there are a bunch of different types of projections i'm going to start off with sort of the simplest one just as sort of a motivating example here projection onto the x-axis okay so what i mean by this let's sort of draw the picture first by projection onto the x-axis i mean so like here i'm just going to draw a picture in two-dimensional case so you've got some vector well if i project that onto the x-axis what i mean is just sort of cast its shadow down onto the x-axis so we sort of squash away the y-component all right so what i want is i want a linear transformation that takes some vector v and spits out just v one zero it forgets about the y entry okay so well if i want to convince myself that this really is a linear transformation and i want to find its standard matrix then what i want to do is i want to find some matrix p such that p times v one v two just equals v one zero okay right because that's why i said over here i wanna send v one v two to v one zero so let's find a matrix that does that if i can find a matrix that does that then i know this must be a linear transformation okay well i mean you can just sort of stare at that equation a bit okay i want to find it right i want to find some 2x2 matrix here so i got to figure out what its four entries are and okay so i mean you just stare at that a little bit i want to leave the v1 alone so maybe i want a one in the top left entry i want to squash the v2 away so maybe i want to zero in the bottom right entry just play around a little bit and you're gonna find that this matrix does the job this matrix one zero zero one this matrix projects the vector down onto the x axis it squashes away the y coordinate without affecting the x coordinate all right and once we find a matrix that works then we know oh yes great this is a linear transformation and furthermore this is its standard matrix all right let's ramp that example up a little bit okay now let's ramp that up to projection onto just some line okay the line that we projected onto in the previous example was the x-axis now i'm going to project onto just some line doesn't have to be the x-axis or the y-axis just some line going through the origin all right so the way that we're going to do this is well i need some way of specifying what line we're talking about and perhaps the easiest way to specify a line is well via a unit vector remember unit vectors they specify a particular direction in space but they don't care about length okay and that's kind of what we want to do here we want to specify some direction some line we don't care you know how long that vector is on that line though okay so we're going to use a unit vector okay and the notation that we're going to use is if u is some unit vector online then p sub u is the function that projects all vectors onto that line in the direction of u all right so i want to show that this is a linear transformation and i want to find its standard matrix okay and the way that i'm going to do both of these tasks at once is i'm going to find a matrix that does the same thing as this linear transformation all right so i'm going to start off by drawing a picture here just to make sure that we understand exactly what we're looking for okay so i've drawn it in two-dimensional uh space but you know this the same thing works in n-dimensional space it doesn't matter what the dimension is okay so i've got some unit vector and then i've drawn the line in the direction of that unit vector here and that's the line that we're going to project on to okay and then here's just some vector v and i want to construct a linear transformation that projects this vector v down onto this line and again think of shadows when i say project down onto a line i mean sort of cast a shadow down on to that line at a right angle okay so just imagine what happens like if i cast this down onto that line well then i'm going to get like this vector that's pointing somewhere up here maybe okay so i'm just going to sort of draw a right angle triangle here okay so pu of v is this vector here that just score sort of gives the piece of v in the direction of this line while forgetting about the perpendicular piece all right so i want to come up with some formula or some matrix that tells me you know what vector is this how do i compute its coordinates all right and the trick here is to notice that p p u of e it points in the same direction as u okay so it's got to be a scalar multiple of u right if two vectors point in the same direction as each other their scalar multiples of each other so i've just got to find out what that scalar is and in particular because u has length 1 the scalar is just going to be the length of pu of v right like this vector here is just going to be whatever its length is times that direction vector there all right so let's compute that length let's compute the length of pu of v okay well this is a right angle triangle here which is great for computing lengths okay in particular if the length of this vector is well it's the length of v then i know the length of this adjacent side down here is going to be cosine of the angle times the length of that hypotenuse okay so that's all that i've drawn here the length of the adjacent side that's the length i want is the length of the hypotenuse times cosine of the angle between them okay and that's just a standard fact from trig that you learned hopefully a while back all right and now i'm just going to simplify this in particular cosine of theta well great we learned about angles a couple weeks ago cosine of theta remember that's just equal to uh the dot product of the two vectors divided by the product of their individual lengths okay we we came up with that formula for the angle between two vectors a couple weeks ago okay and now i'm going to know that hey length of v cancels with length of v and then length of u well u is a unit vector so that just equals one so after i cancel all of this junk out all that i'm left with is just whatever was on the top here v dotted with u okay so the length of this uh the length of this vector that i want this length of p u of e is actually just the dot product of v with u okay great that's enough that we could use it to figure out um that this really is a linear transformation because dot products yeah they're linear in each of the entries that's enough to get linear transformation okay but i want to go one step further and i want to find the standard matrix okay so what i'm going to do now is i'm going to say okay great p u of v it equals that length times the direction vector okay i'm just going to plug in now well what is the length it's v dotted with u okay and now i'm gonna do some manipulations here to get this in the form of matrix times v okay like this is a linear thing but it's not of the form matrix times v which is what i really want so i'm just gonna rearrange things a little bit i'm gonna do two things next i'm gonna bring this dot product over on to the right and i'm allowed to do that because it's a scalar right the dot product of two vectors is the scalar which you know commutes with stuff okay so i can bring that over to the right and the reason i'm doing that is i want the v on the right i want it to be a matrix times v so i want to move the v over and then the next thing that i'm going to do is i'm going i'm going to use this trick for converting dot products into matrix multiplication that we saw last week okay the trick was v dotted with u well that's just you take one of those as a column vector transpose it and multiply by the the other one as a column vector okay and remember that's a trick that we saw for converting matrix multiplication into dot products and vice versa okay and now all that's left to do is sort of regroup parentheses here i've got it as u times a bracket well let's just regroup it so that it's uu transpose times v okay so i've just regrouped parentheses here in other words i've used associativity of matrix multiplication and now this is exactly what i wanted this is something a matrix times v so we've got a formula for computing pu of v that we can actually use okay and i mean explicitly what this tells us is that the standard matrix of pu is whatever the matrix here is okay so the standard matrix of pu is u times u transpose and be a little bit careful here it's easy to get confused between expressions like u transpose times v and u times u transpose okay in this first one up here this is a row vector times a column vector and whenever you've got a row vector times a column vector the result is a number a scalar in particular it equals the dot product on the other hand if you have column vector times row vector that's what u times u transpose is that's a matrix okay the result is not a number it's a matrix because if you check the matrix dimensions that you're multiplying it's an n by one times a one by n the inner dimensions are one those agree and you're left with the outer dimensions which are n by n okay so the product down here really is a matrix don't confuse it with the dot product okay let's make use of the standard matrix calculation that we just did to do a sort of a more explicit computation now let's go through and let's find the standard matrix of the linear transformation acting on three-dimensional space that projects space onto the line in the direction of this vector here two one minus two okay so we just show we just showed how to find the standard matrix or in general let's just apply that formula now to this particular vector to make sure that we understand what's going on here okay the first thing that we've got to do is we've got to realize that this formula that we wrote down up here for the standard matrix of a projection it only works if u is a unit vector okay if this here is a unit vector it has to have length one so the first thing that we've got to do is we've got to normalize this vector that we were given we can normalize w so rescale it so that has length one and the way you do that is you divide by its length so i've got to know what's length is so let's compute that the length of w is the square root of the sum of the squares of its entries which in this case works out to root nine which of course is just three okay so the length of w is three so i'm just gonna divide w by three to get a unit vector pointing in the same direction okay so the unit vector that i'm gonna use is just the same as w except all the entries divided by 3. okay and now i can just use the formula that we computed up in the previous example the standard matrix of pu is just u times u transpose which is just well great u here remember we're always thinking of u like vectors as column vectors so here's u as a column vector times u transpose which turns into a row vector and this seems a little bit weird we haven't done a matrix multiplication explicitly like this before but it is the standard matrix multiplication rule you're just doing rows of the first matrix dot producted with columns of the second matrix it's just weird here because the rows and the columns only have one entry each but really all it is is okay the top left entry of the product is going to be top row dotted with first column so it's going to be two times two next entry is going to be top row dotted with next entry and then top row dotted with this entry okay so you're gonna get four a two and a minus four in the top row okay and then similarly for all the other entries right here's the 4 2 minus 4 in the top row and then 1 dotted with each of these gives me the middle row and then minus 2 dotted with each of these gives me the bottom row okay and this 1 9 coming out in front that's because of one-third times one-third okay you can pull both scalars out in front okay so this is the standard matrix that does the same thing as this linear transformation it projects onto the line in the direction of this vector okay so if we want to go one step farther and actually compute for example hey what is the projection what happens to the vector 1 2 3 after i project on to this line in other words if i apply this linear transformation to the vector 1 2 3 what do i get okay and before we had the standard matrix this is a nasty ugly calculation it's hard to even visualize okay like right we've got some vector in three-dimensional space and projecting it onto some other line is sort of at a right angle i want to figure out where it ends up i don't know that's hard for me to think about at least but thanks to standard matrices it's just oh well i plug this into the formula and get the answer so the way you do this the way you solve this computation here is well we already computed the standard matrix here it is i just multiply it by the input vector and that's all there is to it now you do matrix multiplication and you get your answer standard matrix times input vector okay and then you just do your matrix multiplication rule 4 2 minus 4 dotted with 1 2 3. that's a minus 4 up there 2 one minus two dotted with one two three that's a two minus two there and then minus four minus two four dotted with one two three that's four down there and the one ninth just carries through in the calculation all right so this is where the vector one two three ends up cool beans standard matrices are neat all right let's do another example again another very geometrically motivated example okay let's start talking about rotations okay and again sort of as our ease into the topic let's start off with rotations counterclockwise around the origin by 90 degrees okay pi over two radians all right so the question is is this a linear transformation and if it is what's its standard matrix okay and the way that we're answering we're going to answer both of these questions is we're going to find a matrix that does the same thing all right so the way that we're going to solve this the way we're going to find a matrix that does the same thing is well recall that if two vectors are orthogonal to each other then in two-dimensional space at least we know sort of how their entries are related okay we talked about this a couple weeks ago if you have one vector v1 v2 then a way you can find an orthogonal vector to it is you can just sort of flip the entries and throw a minus sign on one of them so minus v2 v1 is orthogonal to v1 b2 and because we're rotating the input vector counterclockwise by 90 degrees the output and input vectors must be orthogonal to each other all right so if the input is v1 v2 then the output must be minus v2 v1 not quite i mean there's a little bit that i'm glossing over there yeah this is a vector that is orthogonal to the input but there are lots of them right any scalar multiple of that is also orthogonal to the input vector so how do we know that this is actually the right answer why is it not like two times this vector for example okay well the trick here is to realize that rotations like if all i'm doing is rotating this vector then i shouldn't be changing its length right the the length of the output should also be the the same as the length of the input whereas if i you know multiplied this vector by two then the length of the output would be double what the length of the input was okay so we really do know that like the output really is just minus v2 v1 okay there's still something minor that i'm glossing over here and that is there's actually two vectors that are orthogonal to v1 v2 that have the same length as it there's this guy minus v2 v1 and there's also it's negative okay so how do i convince myself that the negative of this vector is not the right answer that's not the output and for that i'm just going to draw a picture okay if my input vector is v1 v2 remember i'm rotating counterclockwise by 90 degrees so my output vector is up here somewhere which has coordinates minus v2 v1 okay if instead it had coordinates v2 minus v1 it would be pointing down here which is the clockwise rotation by 90 degrees that's why there's two different vectors of the same length orthogonal to the input vector because there's a counterclockwise rotation and a clockwise rotation so because i want the counterclockwise rotation this is the right answer minus v2 v1 okay so that's how my linear transformation acts okay now i know what it does to vectors okay and once i have that now i've just got to find some some matrix that does the same thing i want to find some matrix that also sends v1 v2 to minus v2 v1 okay and once i do that then i'll know oh great there's a matrix that does the same thing as this linear transformation or this function so therefore it's a linear transformation and this is its standard matrix okay and again i'm just going to eyeball it hey can i find a matrix that sends this vector to this vector just play around with this problem a little bit it's good to fumble around with things like this and you'll find that oh well here's a matrix that works right because what happens when i multiply this matrix by v1 v2 this minus one here picks up the v2 and shifts it up and then the one zero here picks up the v1 and shifts it down right so this matrix works so this must be the standard matrix of the rotation counter clockwise by pi over two and it is a linear transformation because there's a matrix that does the same thing as it all right let's ramp up from this example a little bit now let's now look at rotations counterclockwise by any angle okay so just some angle theta in the previous example we have theta was pi over 2. let's just look at any angle now let's um let's find the standard matrix of this and i apologize we're going to gloss over the the proof of the fact that this actually is a linear transformation okay all of the previous linear transformations that we looked at we actually showed they were linear transformations but for this one i'm not going to okay we're just going to compute the standard matrix okay because i think it's instructive to look at this particular method of computing standard matrices okay from the definition remember if you know that it's a linear transformation already then the way to compute its standard matrix is you just apply that linear transformation to the first standard basis vector throw that in as the first column and then you apply that linear transformation to the second standard basis vector and throw that in this is the second column and because we're in two-dimensional space that's it there's only two columns all right so i'm going to draw a picture here i want to figure out what this linear transformation does to e1 so i've drawn a u1 here and i want to figure out what it does to e2 i've drawn that here and once i have the answer to those two questions i just throw them as columns into a matrix and i'm done all right so here we go let's figure out what it does to these two standard basis vectors well remember like just what we said is this rotating counterclockwise by an angle of theta so that's why i've drawn here okay e1 gets rotated up here and e2 gets rotated over here and the angle in both of those cases is just theta and to make me be actually be able to compute the coordinates of these vectors here i'm going to sort of draw on right angle triangles here okay now i know that the lengths of these hypotenuses are both equal to one right because all i did was i took the standard basis vectors and i rotated them i did not change them okay so this length is still one this length is still one okay next up the adjacent sides both have length equal to cosine of theta right and that's just a standard trig fact right i mean like this adjacent side here is going to have length cos theta the opposite sides are going to have length equal to sine of theta okay so that tells me all i need to know that gives me the coordinates of these two vectors here that tells me this point up here what's cos theta units over in the x direction and sine theta units up this point over here well it's cosine theta units up so that's its y coordinate and it's sine theta units over to the left so its x coordinate is minus sine theta all right so yeah so what i just said for r theta of e1 coordinates are cos theta sine theta and then r theta of e2 coordinates are minus sine theta cos theta okay so that gives me the two columns that i need to be able to construct the standard matrix just throw them in now okay so r theta the standard matrix of r theta it's just formula and then plug in those two columns first column is cos theta sine theta so that's where this is coming from second column is minus sine theta cos theta that's where this is coming from and that's it that's our standard matrix okay so no matter what theta is no matter what angle you're rotating by you can rotate a vector just by multiplying by this matrix here all right so let's do an example of that so what vector is obtained if we rotate this vector it doesn't matter what it is it's the vector 1 3 and we're going to rotate it by pi over 4 radians in other words 45 degrees we're going to rotate it by that much counterclockwise and then we're going to ask the question you know what vector do you get what are its coordinates all right so geometrically what we're doing is we've got this vector v equals 1 3 and i'm asking what happens if i rotate it counterclockwise by pi over 4. so what are the coordinates of this vector over here where the angle between them is pi over 4. what are its coordinates well the way that we answer that question is we just realize that linear transformation applied to vector is the same as matrix times vector okay and we already computed this standard matrix in the previous example it's just cos of angle minus sign of angle sine of angle cosine of angle and this time we're plugging in the particular angle pi over 4 that we're using okay so before i actually do this matrix multiplication i'm going to simplify each of these remember that cosine of pi over 4 is 1 over root 2 and sine of pi over 4 is also 1 over root 2. okay so when i make those substitutions the matrix i'm multiplying by is just this guy right here and now just do your matrix multiplication okay so 1 over root 2 times 1 plus minus 1 over root 2 times 3 all together is minus 2 over root 2 and 1 over root 2 times 1 plus 1 over 2 times 3 all together is 4 over root 2. i'm just going to simplify that a tiny little bit and what i get is minus root 2 is my top entry and 2 over 2 times root 2 as my bottom entry so that's the coordinates at this point here all right and that's it all there is to it and those are all the specific examples of linear transformations that i want to get to uh in this class so i will see you next class when we do one final thing with linear transformations we talk about what happens if you do linear transformations one after each other okay so what if you apply a linear transformation and then apply another linear transformation what happens okay so i'll see you next class for that