If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Using matrices to transform the plane: Composing matrices

2X2 matrices can define transformations for the entire plane. In this worked example, we see how to find a single matrix that defines the same transformation as the composition of two other matrices. Created by Sal Khan.

Want to join the conversation?

  • blobby green style avatar for user Matej Šarlija
    Again, please rethink this section - this is a weird linear algebra lesson, stuck in precalculus before we even introduced any matrix operation properly or understanding.

    I can appreciate this, but you've probably lost a lot of people here.
    (14 votes)
    Default Khan Academy avatar avatar for user
  • starky ultimate style avatar for user WisePterodactyl
    At Sal stops the video to think about how Matrices work as compositions. Generally for some rudimentary functions f(x) = x+5 and g(x) = x-3, (f o g)(x) would implement g(x) into f(x) like (f o g)(x) = (x-3)+5. However, at when Sal composes B o A, he multiplies the columns of the B matrix by individual A entries, which appears backwards as B is being implemented into A, indicative of the composition A o B. I was wondering if somebody could explain the reasoning behind that choice and why it apparently flips or why my logic is flawed?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user kubleeka
      Function composition is written right-to-left, so the composition of B, then A is written as the matrix AB. In your example, f◦g(x) first applies g to x, then applies f to the result. We define matrix multiplication so as to match this convention.
      (4 votes)
  • piceratops ultimate style avatar for user ANB
    When I multiply these two matrices, it is giving me different values from when I compose a matrix from the two matrices. This makes me conclude matrix multiplication is different from matrix composition is that right?

    Edit: Matrix multiplication is the same thing as matrix composition. The key to understanding this is paying closer attention to the commutative property that does not exist in matrix multiplication. Matrix multiplication is read from the right to the left and the reason that I was getting results was because I was multiplying from left to right.

    Hope this helps someone who faced the same issue as me.
    (5 votes)
    Default Khan Academy avatar avatar for user
    • blobby green style avatar for user زينجر شريمبو
      matrix multiplication and matrix composition are two different operations on matrices that can produce different results.

      Matrix multiplication involves multiplying corresponding elements of two matrices and adding the results. It is denoted by *. The number of columns in the first matrix must equal the number of rows in the second matrix for multiplication to be defined.

      Matrix composition is the operation of applying one matrix transformation followed by another. It is denoted by ∘. The composition of matrices A and B, written A ∘ B, has the effect of first applying B and then applying A. So if v is a column vector, (A ∘ B)v = A(Bv).

      For example, let:

      A = [[1, 2],
      [3, 4]]

      B = [[5, 6],
      [7, 8]]


      A * B = [[19, 22],
      [43, 50]]

      A ∘ B = [[43, 46],
      [95, 106]]

      As you can see, while matrix multiplication produces a matrix of the product sums, matrix composition produces a matrix by applying the transformations in succession. The results are quite different!

      So in summary, the main differences between the two operations are:

      Matrix Multiplication:

      Denoted by *
      Defined only if the number of columns of the first matrix equals the number of rows of the second matrix.
      Calculates the product sums of corresponding elements.
      Matrix Composition:

      Denoted by ∘
      Applies the matrix transformations in succession.
      Defined for all matrices of appropriate sizes.
      Gives a different result than matrix multiplication.
      (1 vote)
  • leaf blue style avatar for user The Dreams Wind
    How matrix multiplication is different from the transformation composition in this context? Can we just say that if you want to apply transformation of matrix A first and matrix B second, you can just multiply BA matrix by your vector? And if so, why not using multiplication notation here? It sounds much more intuitive to me
    (3 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Romina M. Santoro
      Hi, The Dreams Wind
      To me, this video is kind of an introduction to matrix multiplication, which is taught (at least in the precalculus course) a few lessons later. I think the purpose of this lesson is for us to understand matrix multiplication before we even get to it, so that when we do learn it we're like, "Oh, I already knew this; I just didn't know I did. Matrix multiplication doesn't seem so daunting after all!"
      I don't know... that's my idea, heh.
      Good luck!
      (2 votes)
  • blobby green style avatar for user Okily Dokily
    Am I the only one who is having a hard time seeing how this is a composition? It seems like the first and the second step are totally different? We don't even do anything with the first matrix. 🧐🤔
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user jaydenou31
    just treat this 2x2 matrix as 2 of the 2x1 matrix (which means two separate vectors).

    [0;5] [2;-1] (';' means newline) is basically:
    [0;5]= 0*[1;0] + 1*[0;1]
    [2;-1] = 2*[1;0] + -1*[0;1]

    Applying transformation [-3,0 ; 1,4] only means :
    [0;5]'= 0*[-3;1] + 1*[0;4]
    [2;-1]'= 2*[-3;1] + -1*[0;4]
    (2 votes)
    Default Khan Academy avatar avatar for user
    • duskpin ultimate style avatar for user TotallyNotAFurryÒwÓ
      That's correct! The transformation matrix [−3 0; 1 4] can be applied to each of the vectors [0 5] and [2 −1] separately by multiplying each vector by the transformation matrix.

      So, we have:

      [0;5]' = [−3 0; 1 4] [0;5] = 0*[-3;1] + 1*[0;4] = [0;4]


      [2;-1]' = [−3 0; 1 4] [2;-1] = 2*[-3;1] + (-1)*[0;4] = [-6;-2]

      Therefore, the transformation matrix maps the vector [0 5] to [0 4] and the vector [2 −1] to [−6 −2].
      (2 votes)
  • female robot grace style avatar for user Orca
    This is not a question. I was watching the video and paused it to think about it, like Sal said :)) This is what I came up with:
    [0 , 5a] + [2b , -b] = [2b , 5a-b]
    If : [2b , 5a-b] = [x , y] then I have:
    2b* [1 , 0] + (5a-b)*[0 , 1]
    And if the transformation matrix B is applied to this point, I'll have:
    2b*[-3 , 1] + (5a-b)*[0 , 4] = [-6b , 2b]+[0 , 20a-4b] = [-6b , 20a-2b]
    So for any point [a , b] I can find the image under these two transformation put together as one formula!
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user birdlion88
    Sal said, for B of A, that you would apply the function A first then input it into B, but in the example, he inputted matrix B into A. Why is that?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • leaf grey style avatar for user smatlaldo
    If i have A∘B, why do multiply B with A, rather than A with B when it is literally A of B?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user Tanner P
      I’m not sure where you are coming from. If you have the composition A∘B, you will find it be applying A to the columns of B. Is that what you mean by multiply “A with B”?

      When Sal says “A of B”, he means something like f(g(x)), or “f of g”. That is a composition of functions, and multiplying matrices is something similar. A matrix is inputted, and a composition is outputted.
      (1 vote)
  • blobby green style avatar for user No_Solution
    To solve the composition of Matrix A and Matrix B, does the order matter at all? In other words, shouldn't A∘B produce the same result as B∘A?
    (2 votes)
    Default Khan Academy avatar avatar for user

Video transcript

- [Instructor] So what I have here is two different transformation matrices, and what we're going to think about in this video is can we construct a new matrix that's based on the composition of these transformations? Or a simpler way of saying that, a new transformation that's based on applying one of these transformations first, and then the other one right after that. So first, let's just review what's going on. If we have some random vector here, a, b, we know that we could view this as a times the one, zero vector, the unit vector in the x direction, plus b times the zero, one vector, the unit vector that goes in the vertical direction. Now, if you were to apply this transformational capital A here, it tells you instead of using one, zero and zero, one, use these two columns instead. So if you were to apply the transformation here, I guess we could call it a, b prime, that is going to be, if you apply capital A transformation matrix, it's going to be a times, not one, zero, you use zero, five instead. And then plus b times not zero, one, you use two, negative one instead. So that's just a little bit of review. But what we're gonna think about in this video is, what would be the transformation matrix for the composition? And I could write that as B of A right over here. And you might recognize this from function notation, where essentially it's saying you would apply the function A first, and then whatever the output of that is, you would then input that into B and you'd get the output of that. And that makes sense, because you can view transformation matrices really as functions, functions that map points on the coordinate plane. So, in this situation, what would be the transformation matrix that is a composition of these two? Pause this video and think about that. All right, well, what would happen is, we would first transform any point using these two vectors, the zero, five, the two, negative one, because that's the first transformation we do. And then we would apply this transformation to whatever the resulting vector is. Now, that seems pretty involved and we don't wanna write it in terms of A or B's, we just wanna write it in terms of a transformation matrix. So one way to think about it is, we can transform each of these vectors that you have in matrix A. Because remember, that says, what do you turn the vectors one, zero and zero, one into? So if we transform zero, five using the matrix B, and if we transform two, negative one using the matrix B and we put them in their respective columns, we should have the composition of this. So let me write it this way, create a little bit of space. So let's say that the composition B of A is equal to, I'll write a big two-by-two matrix right over here. The first thing we can do is apply transformation matrix B to the purple column right over here. And what is that going to tell us? Well, that's gonna be zero times negative three, one. So let me write it that way. It's going to be zero times negative three, one plus five times zero, four, zero, four. And this is going to give us a two by one vector right over here. So that you can view as filling up the first column of this transformation, this composition, I guess you could say. And then let's think about this second vector right over here, two, negative one. If you transform that using B, what are you going to get? You're going to get two times negative three, one. So right here, two times negative three, one, plus negative one, or maybe I just write it this way, minus one times zero, four. And this doesn't look like a matrix just yet, but if you work through it, it will become a matrix. For example, if I multiply, well, zero times all of this is going to be zero, and then five times zero is going to be, let me just write it this way. This would turn into five times zero is zero, five times four is 20. And then this matrix right over here is going to be two times negative three, one, is going to be negative six, two, and then we have minus zero, four. And now if we wanted to write this clearly as a two-by-two matrix, this would be equal to, and we get a little bit of a drum roll here, the first column is zero, 20. And then the second column is going to be, let's see, negative six minus zero is still negative six and two minus four is negative two. And we're done. We have just created a new transformation matrix. It's based on the composition B of A. So if you apply transformation A first to any vector and then apply transformation B to whatever you get there, that is equivalent to just applying this one two-by-two transformation matrix, B of A.