# Linear transformation examples: Scaling andÂ reflections

## Video transcript

We've talked a lot about
linear transformations. What I want to do in this video,
and actually the next few videos, is to show you how
to essentially design linear transformations to do things
to vectors that you want them to do. So we already know that
if I have some linear transformation, T, and it's a
mapping from Rn to Rm, then we can represent T-- what T does
to any vector in x, or the mapping of T of x in Rn to Rm--
we could represent it as some matrix times the vector
x, where this would be an m by n matrix. And we know that we can always
construct this matrix, that any linear transformation
can be represented by a matrix this way. And we can represent it by
taking our identity matrix, you've seen that before, with
n rows and n columns, so it literally just looks
like this. So it's a 1, and then it has n
minus 1, 0's all the way down. Then it's a 0, 1, and
everything else is 0's all the way down. And so essentially you just
have 1's down as diagonal. It's an n by n matrix. All of these are 0's,
just like that. You take your identity matrix
and you perform the transformation on each
of its columns. We call each of these columns
the standard basis Rn. So this is column e1,
this is column e2, and it has n columns. en. And each of these columns are
of course members of Rn because this is n rows
and n columns matrix. And we know that A, our matrix
A, can be represented as the transformation being operated
on each of these columns. So the transformation on e1, and
the transformation on e2, so forth and so on,
all the way to the transformation to en. And this is a really useful
thing to know because it's very easy to operate any
transformation on each of these basis vectors that only
have a 1 in its corresponding dimension, or with respect to
the corresponding variable, and everything else is 0. So all of this is review. Let's actually use this
information to construct some interesting transformations. So let's start with some
set in our Rn. And actually everything I'm
going to do is going to be in R2, but you can extend a lot
of this into just general dimensions. But we're dealing with
R2 right here. Obviously, it's only 2
dimensions right here. Let's say we have a triangle
formed by the points, let's say the first point
is right here. Let's say it's the point 3, 2. And then you have the point,
let's say that your next point in your triangle, is the point,
let's just make it the point minus 3, 2. I shouldn't have written
that as a fraction. I don't know why I did that. 3, 2. Then you have the point
minus 3, 2. And that's this point
right here. Minus 3, 2. And then let's say, just for
fun, let's say you have the point, or the vector-- the
position vector, right? 3, minus 2. Which is right here. Now each of these are position
vectors, and I can draw them. I could draw this 3, 2 as in
the standard position by drawing an arrow like that. I could do the minus 3,
2 in its standard position like that. And 3, minus 2 I could
draw like that. But more than the actual
position vectors, I'm more concerned with the positions
that they specify. And we know that if we take
the set of all of the positions or all of the position
vectors that specify the triangle that is essentially
formed by connecting these dots. The transformation of this set--
so we're going to apply some transformation of that--
is essentially, you can take the transformation of each of
these endpoints and then you connect the dots in
the same order. And we saw that several
videos ago. But let's actually design
a transformation here. So let's say we want to-- let's
just write down and words what we want to
do with whatever we start in our domain. Let's say we want to reflect
around the x-axis. Reflect around-- well
actually let's reflect around the y-axis. We essentially want
to flip it over. We want to flip it
over that way. So I'm kind of envisioning
something that'll look something like that when
we flip it over. So we're going to reflect
it around the y-axis. And let's say we want to stretch
in y direction by 2. In y direction times 2. So what I envision, we're
going to flip it over like this. What I just drew here. And then we want to stretch
it, so we're going to first flip it. That's kind of a step 1. And then step 2 is we're
going to stretch it. So instead of looking like this,
it'll be twice as tall, so it'll look like this. Without necessarily
stretching the x. So how can we do that? So the first idea of reflecting around the y axis, right? So what we want is, this point,
that was a minus 3 in the x-coordinate right there, we
want this point to have its same y-coordinate. We want it to still
have a 2 there. And I'm calling the second
coordinate here our y-coordinate. I could call that our x2
coordinate, but we're used to dealing with the y coordinate
when we graph things. So I'll just keep calling
it the y-coordinate. But we want is this negative
3 to turn to a positive 3. Because we want this point
to end up over here. And we want this positive 3
here to end up becoming a negative 3 over here. And we want this positive 3 for
the x-coordinate to end up as a negative 3 over there. So you can imagine all
we're doing is we're flipping the sign. This reflection around y, this
is just equivalent to flipping the sign, flipping the sign
of the x-coordinate. So this statement right here is
equivalent to minus 1 times the x-coordinate. So let's call that times x1. Because this is x1. And then stretching in
the y direction. So what does that mean? That means that whatever height
we have here-- so this next step here is whatever
height we have here-- I want it to be 2 times as much. So right here this coordinate
is 3, 2. If I didn't do this first
step first, I'd want to make it 3, 4. I want to make it 2 times
the y-coordinate. So the next thing I want to do
is I want to 2 times-- well I can either call it, let me just
call it the y-coordinate. It's a little bit different
convention that I've been using, but I'm just calling
these vectors-- instead of calling them x1, and x2, I'm
saying that my vectors in R2-- the first term I'm calling the
x term, or the x entry, and the second term I'm calling
the y entry. But it's the same idea that
we've been doing before. I'm just switching to this
notation because we're used to thinking of this as the y-axis
access as opposed to the x1 and x2 axis. So how do we construct
this transformation? I mean, I can write it down in
kind of transformation words. I could say-- I could define
my transformation as T of some vector x. Let me write it this way. T of some vector x, y is going
to be equal to-- I want to take minus 1 times the x, so
I'm going to minus the x. And I'm going to multiply
2 times the y. So that's how I could just write
it in transformation language, and that's pretty
straight forward. But how would I actually
construct a matrix for this? So what you do is, you
just take your-- we're dealing in R2. So you start off with the
identity matrix in R2, which is just 1, 0, 0, 1. And you apply this
transformation to each of the columns of this identity
matrix. So if you apply the
transformation to this first column, what do you get? So what we're going to do is
to create a new matrix, A. And say that is equal to the
transformation of-- let me write it like this--
Transformation of 1, 0. That is going to be our new
column, we're just going to transform this column. And the second column is going
to be the transformation of that column. So it's a transformation
of 0, 1. Just like that. And so what are these
equal to? The transformation of 1, 0. So let me write it down
here in green. So A is equal to? What's the transformation
of 1, 0 where x is 1? Where we just take the minus
of the x term, so we get minus 1. And then 2 times the y term. So 2 times 0 is just 0. Now do the second term. The minus of the 0 term
is just minus 0. So that just stays 0. Then you multiply 2
times the y term. So 2 times y is going to be
equal to 2 times 1, so it's equal to 2. So now we can describe this
transformation-- so now we could say the transformation
of some vector, x, y. We can describe it as a
matrix-vector product. It is equal to minus 1, 0,
0, 2, times our vector. Times x, y. And let's apply it to verify
that it works. To verify that our
matrix works. So this first point, and I'll
try to do it color coded, let's do this first
point right here. This is minus 3, 2. So that's minus 3, 2. So what is minus 3, 2-- I'll
do it right over here. I could just look at that. So what minus 1, 0, 0,
2, times minus 3, 2? Well this is just a straight
up matrix-vector product. Minus 1 times minus 3 is
positive 3 plus 0 times 2. So plus 0. So this is 3. And then 0 times minus 3 is 0. Plus 2 times 2. This is 3, 4. So that point right there will
now become the point 3, 4. It now becomes that
point right there. Let's look at this point right
here, the point 3, 2. So let's take our transformation
matrix, minus 1, 0, 0, 2, times 3, 2. This is equal to minus 1 times
3 is minus 3 plus 0 times 2. So it's just minus 3. And you have 0 times
3, which is 0. Plus 2 times 2, which is 4. 0 plus-- so you got
that point. So this point, by our
transformation, T, becomes minus 3, 4. So minus 3, 4. And I kind of switch
in my terminology. I said, becomes, or you could
say it's mapped to if you want to use the language that I used
when I introduced the ideas of functions and
transformation. This point is mapped to
this point in R2. And then finally let's look at
this point right here, apply our transformation matrix
that we've engineered. Let's multiply minus 1, 0, 0,
2, times this point right here, which is 3, minus 2. Which is equal to minus
1 times 3 is minus 3. And then 0 times minus
2 is just 0. So this just becomes minus 3. And then 0 times 3 is 0. 2 times minus 2 is minus 4. So minus 3, minus 4. So this point right here becomes
minus 3, minus 4. Becomes that point
right there. And we know that the set in R2
that connects these dots, by the same transformation, will
be mapped to the set in R3 that connects these dots. We've seen that already. I think that was 3 videos ago. So the image of this set that
I've drawn here, this triangle is just a set of points
specified by a set of vectors. The image of that set of
position vectors specifies these points right here. Specifies the points that
I'm drawing right here. Let me see if I'm
doing it right. There you go, just like that. And low and behold, it has done
what we wanted to do. We flipped it over, so that we
got this side onto the other side, like that. And then we stretched it. And we stretched it in
the y direction. And we we see that it has
stretched by a factor of 2. We flipped it first, and
then we stretched it by factor of 2. And, in general, any of these
operations can be performed-- I mean, you can always go
back to the basics. You can always say, look I can
write my transformation in this type of form, then
I can just apply that to my basis vectors. Or the columns in my
identity matrix. But a general theme is any of
these transformations that literally just scale in either
the x or y direction, and when I-- or, well, you could
say, scale. They can either shrink
or expand in the x or y direction. Or flip in the x or y direction,
creating a reflection. These are going to be
diagonal matrices. Diagonal matrices. And why are they diagonal
matrices? Because they only have non-zero terms along their diagonals. This is the 2 by 2 case. If I did a 3 by 3, it would be
0's everywhere, except along the diagonal. And it makes a lot of sense
because this first term is essentially what you're
doing to the x1 term. The second term is what you're
doing to the x2 term. Or the y term in our example. If I had multiple terms, if this
was a 3 by 3, that would be what I would do to
the third dimension. Then the next term would
be what I would do the fourth dimension. So you could expand this idea
to an arbitrary Rn. Anyway, the whole point of this
video is to introduce you to this idea of creating
custom transformations. And I think you're already
starting to realize that this could be very useful if you
want to do-- especially in computer programming-- if
you're going to do some graphics or create some type
of multi-dimensional games.