Matrix multiplication as composition | Essence of linear algebra, chapter 4

It is my experience that proofs involving matrices can be shortened by 50% if one throws matrices out.
— Emil Artin Hey everyone! Where we last left off, I showed what linear
transformations look like and how to represent them using matrices. This is worth a quick recap, because it’s
just really important. But of course, if this feels like more than
just a recap, go back and watch the full video. Technically speaking, linear transformations
are functions, with vectors as inputs and vectors as outputs. But I showed last time how we can think about
them visually as smooshing around space in such a way the gridlines
stay parallel and evenly spaced, and so that the origin remains fixed. The key take-away was that a linear transformation is completely determined,
by where it takes the basis vectors of the space which, for two dimensions, means i-hat and
j-hat. This is because any other vector can be described
as a linear combination of those basis vectors. A vector with coordinates (x, y) is x times i-hat + y times j-hat. After going through the transformation this property, the grid lines remain parallel
and evenly spaced, has a wonderful consequence. The place where your vector lands will be
x times the transformed version of i-hat + y times the transformed version of j-hat. This means if you keep a record of the coordinates
where i-hat lands and the coordinates where j-hat lands you can compute that a vector which starts
at (x, y), must land on x times the new coordinates of
i-hat + y times the new coordinates of j-hat. The convention is to record the coordinates
of where i-hat and j-hat land as the columns of a matrix and to define this sum of the scaled versions
of those columns by x and y to be matrix-vector multiplication. In this way, a matrix represents a specific linear transformation and multiplying a matrix by a vector is, what
it means computationally, to apply that transformation to that vector. Alright, recap over. Onto the new stuff. Often-times you find yourself wanting to describe
the effect of applying one transformation and then another. For example, maybe you want to describe what happens when
you first rotate the plane 90° counterclockwise then apply a shear. The overall effect here, from start to finish, is another linear transformation, distinct from the rotation and the shear. This new linear transformation is commonly called the “composition” of the two separate transformations we applied. And like any linear transformation it can be described with a matrix all of its
own, by following i-hat and j-hat. In this example, the ultimate landing spot
for i-hat after both transformations is (1, 1). So let’s make that the first column of the
matrix. Likewise, j-hat ultimately ends up at the
location (-1, 0), so we make that the second column of the matrix. This new matrix captures the overall effect
of applying a rotation then a sheer but as one single action, rather than two
successive ones. Here’s one way to think about that new matrix: if you were to take some vector and pump it
through the rotation then the sheer the long way to compute where it ends up is to, first, multiply it on the left by the
rotation matrix; then, take whatever you get and multiply that
on the left by the sheer matrix. This is, numerically speaking, what it means to apply a rotation then a sheer
to a given vector. But, whatever you get should be the same as
just applying this new composition matrix that we just found, by
that same vector, no matter what vector you chose, since this new matrix is supposed to capture
the same overall effect as the rotation-then-sheer action. Based on how things are written down here I think it’s reasonable to call this new matrix,
the “product” of the original two matrices. Don’t you? We can think about how to compute that product
more generally in just a moment, but it’s way too easy to get lost in the forest
of numbers. Always remember, the multiplying two matrices
like this has the geometric meaning of applying one
transformation then another. One thing that’s kinda weird here, is that
this has reading from right to left; you first apply the transformation represented
by the matrix on the right. Then you apply the transformation represented
by the matrix on the left. This stems from function notation, since we write functions on the left of variables, so every time you compose two functions, you
for the rest of us. Let’s look at another example. Take the matrix with columns (1, 1) and (-2, 0) whose transformation looks like this, and let’s call it M1. Next, take the matrix with columns (0, 1)
and (2, 0) whose transformation looks like this, and let’s call that guy M2. The total effect of applying M1 then M2 gives us a new transformation. So let’s find its matrix. But this time, let’s see if we can do it without
watching the animations and instead, just using the numerical entries
in each matrix. First, we need to figure out where i-hat goes after applying M1 the new coordinates of i-hat, by definition, are given by that first column
of M1, namely, (1, 1) to see what happens after applying M2 multiply the matrix for M2 by that vector
(1,1). Working it out, the way that I described last
video you’ll get the vector (2, 1). This will be the first column of the composition
matrix. Likewise, to follow j-hat the second column of M1 tells us the first
lands on (-2, 0) then, when we apply M2 to that vector you can work out the matrix-vector product
to get (0, -2) which becomes the second column of our composition
matrix. Let me talk to that same process again, but
this time, I’ll show variable entries in each matrix, just to show that the same line of reasoning
works for any matrices. This is more symbol heavy and will require
some more room, but it should be pretty satisfying for anyone
who has previously been taught matrix multiplication the more rote way. To follow where i-hat goes start by looking at the first column of the
matrix on the right, since this is where i-hat initially lands. Multiplying that column by the matrix on the
left, is how you can tell where the intermediate
version of i-hat ends up after applying the second transformation. So, the first column of the composition matrix will always equal the left matrix times the
first column of the right matrix. Likewise, j-hat will always initially land
on the second column of the right matrix. So multiplying the left matrix by this second
column will give its final location and hence, that’s the second column of the
composition matrix. Notice, there’s a lot of symbols here and it’s common to be taught this formula
as something to memorize along with a certain algorithmic process to
kind of help remember it. But I really do think that before memorizing
that process you should get in the habit of thinking about
what matrix multiplication really represents: applying one transformation after another. Trust me, this will give you a much better
conceptual framework that makes the properties of matrix multiplication
much easier to understand. For example, here’s a question: Does it matter what order we put the two matrices
in when we multiply them? Well, let’s think through a simple example like the one from earlier: Take a shear which fixes i-hat and smooshes
j-hat over to the right and a 90° rotation. If you first do the shear then rotate, we can see that i-hat ends up at (0, 1) and j-hat ends up at (-1, 1) both are generally pointing close together. If you first rotate then do the shear i-hat ends up over at (1, 1) and j-hat is off on a different direction
at (-1, 0) and they’re pointing, you know, farther apart. The overall effect here is clearly different so, evidently, order totally does matter. Notice, by thinking in terms of transformations that’s the kind of thing that you can do in
your head, by visualizing. No matrix multiplication necessary. I remember when I first took linear algebra there’s this one homework problem that asked
us to prove that matrix multiplication is associative. This means that if you have three matrices
A, B and C, and you multiply them all together, it shouldn’t matter if you first compute A
times B then multiply the result by C, or if you first multiply B times C then multiply
that result by A on the left. In other words, it doesn’t matter where you
put the parentheses. Now if you try to work through this numerically like I did back then, it’s horrible, just horrible, and unenlightening
for that matter. But when you think about matrix multiplication
as applying one transformation after another, this property is just trivial. Can you see why? What it’s saying is that if you first apply
C then B, then A, it’s the same as applying C, then B then A. I mean, there’s nothing to prove, you’re just applying the same three things
one after the other all in the same order. This might feel like cheating. But it’s not! This is an honest-to-goodness proof that matrix
multiplication is associative, and even better than that, it’s a good explanation
for why that property should be true. I really do encourage you to play around more
with this idea imagining two different transformations thinking about what happens when you apply
one after the other and then working out the matrix product numerically. Trust me, this is the kind of play time that
really makes the idea sink in. In the next video I’ll start talking about
extending these ideas beyond just two dimensions. See you then!

100 thoughts on “Matrix multiplication as composition | Essence of linear algebra, chapter 4”

1. TensegrityEnergy says:

Help. Can anybody explain why the order of two identical linear transformations would result in different results? The example in this video is not clear to me. When you first sheer, only j-hat is repositioned due to sheering, but when you first rotate, not j-hat but i-hat is repositioned due to sheering. To me it does not really seem like you are just reversing the order of two identical linear transformations.

Can you please make a video on geometrical meaning of transpose of a matrix??
Square matrix in particular.

3. Renee Liu says:

I have been "studying" this for years and every time matrix comes up it gives me hives

But I start to see how it actually makes sense now. Thank you!

4. Renee Liu says:

Okay, I am gonna cancel my Netflix and subscribe to this.

5. Thakujigu Appaswamy says:

This has totally changed the way I saw Matrices!

6. Saravanan Rajabojan says:

I am having trouble understanding something here

M1M2 != M2M1 but A(BC) = (AB)C.

I know I seem to compare apples to oranges, but I am not able to understand why these are two different cases. Can someone help!

7. Victoria Boichenko says:

8:52–8:54 "It's horrible, just horrible" Ha-ha-ha —- Totally agree!

8. Samarth Sai says:

Isn't applying a then b THEN c different from applying c THEN b then a.

9. bobo xiang says:

about the(AB)C and A(BC), it confuse me, isn't what in the () be transformed first which is : B->A->C vs B->C->A??

10. Jae duk Seo says:

the matrix operation – linear – can be done via one operation.

11. Jae duk Seo says:

AB =/= BA but (AB)C == A(BC)

12. Mohamed Sherif says:

In 2:15 when he explained rotation then shear.
The animation is wrong? I mean the wrong vector was sheared?

13. Antonio Intini says:

Oh boy, I really love your work!

14. Ali Abdul-Kareem says:

after 4 years in college finally I understand why the heck matrix mul. is like this, thanks a lot.

15. Ali Abdul-Kareem says:

understanding this matrix mul. as shifting helps a lot !!! to understand why multiplying by identity matrix keeps the vector the same!
in another whole respective.

16. Aniruddh Muley says:

People should watch this instead of ASMR videos.

17. Tan Yuan Ho says:

My goodness,you make it so easy to understand!!!!

18. Fatimah Jabr says:

“It’s horrible ,just horrible” 8:52

I feel you man

WOW just WOW, Why do they never teach this in school

20. abbiramy vishwanathan says:

What is the intuition behind transpose of a matrix?

21. The Terrible Puddle says:

If I saw (AB)C on a test I'm sure I would have applied AB and then C…

22. 柳哥 says:

i can watch it as game of thrones

23. Krupanidhi Peterson says:

What is the geometric equivalent of adding matrices tho?

24. Ravirajsinh Zala says:

Hey, i want the ending music.

25. Lavender says:

bro im shook

26. Quantum Brotherhood says:

Believe me, I hated matrix multiplication before watching this video.
Now I’m almost loving it.

27. Vine Street says:

If I had 3blue1brown when I was in high school I would have gone on to get a PhD in Math and then become a mathematician. Now I’m just a vocational math enthusiast. Thanks so much for your service to math education. I hope your work get immortalized.

28. FluxTwee says:

I love the small details like how Composition was colored to look like it is a composition of a rotation and a shear.

29. Evan karag says:

message to the people who created the series:WE LOVE YOU.

30. Daegu Dude says:

my mind knows something amazing happened and I still don't know what it is.

31. Nathan2508 says:

Why did you take pains to state that you multiplied the vector by the matrices "on the left"?

32. mike stanly says:

This series is the best thing that has ever happened to me. All teachers need to teach like this FIRST, and then go into the memorization / methods of actually doing it.

33. Keyoor Abhyankar says:

But we just learnt that it's not associative! Can anybody explain me that

34. Karthik Rambhatla says:

09:11 🤣🤣 This series is enlightening 😍🙏. If he hasn't done this, I will never be getting these things on my own, in a life time

35. v naveen kumar says:

if we have a 3×3 matrix then we can represent the following diagrammatically but what if we have 100×100 or 10×10 matrix we can't imagine that there are those many dimensions but the innate idea behind the mathematicians is great …..they just imagined that the space around us itself is a representation of matrix….
can any one give me an answer to my doubt….

36. v naveen kumar says:

if you have AX=B where A [2X2] MATRIX , X[2X1] MATRIX then it transforms from one side to other side …but if you are multiplying one matrix(points in space )with other then its just a series of transformations…if it is 2X2 MATRIX THEN IT IS UNDERGOING 2 TRANSFORMATIONS IN THE BACKGROUND that's it …

37. pkli says:

Thank you for existing

38. EvB says:

I missed a week of school just after we started our vectors unit, I watched 4 of these videos before I went back and I'm ahead of everybody in the class. Thank you narrator.

39. Asish B says:

I cried a little when it hit me.

40. Manish Rijal says:

good news for manga readers too
4:26

41. Navanit Vikram says:

Can anyone explain why the transformed i and j vectors are written in columns instead of rows in the 2×2 matrices?

42. rahul bathini says:

can you explain how a vector multiplies by a vector it turns into a scalar??? like a 1xm and a mx1.Love the videos by the way

43. Aslan Bayramuqlany says:

9:05 what? aren't you supposed to do the operation in brackets first?

44. Jonprit Pritam says:

if we learn mathematics in this way then everyone will love to learn and not avoid

45. Ashish Kushwaha says:

I'm waiting for essence of probability, trigonometry, number theory and sets & functions

46. Kerbonkers says:

These set of videos opened my mind like i had never experienced before, as a linear algebra student, i feel bad for everyone that doesnt have the opportunity to watch these videos, thank you so much for essencially making people happier by being able to understand what it really means, your efforts are worth so much to society that it cant really be given a value, thanks dude.

47. SpaceSpye says:

Matrices can be fun?

48. NoriMori says:

Oh, so that's why matrices don't commute! Cliff Stoll mentioned that on the Numberphile Podcast, but after looking it up, I couldn't understand why they have that property!

49. Lumpalish says:

The graphics in this series are so great that I have fallen 3 times while watching it. Oops! 4 times…

50. Chainsaw Run says:

i esspesially like the brown

the video is really nice

51. ender tain says:

You're explanation is awesome

52. Captain Rhodes says:

wow someone who actually knows what a matrix is. for years i thought they were just random nonsense

53. Qiwei xiao says:

so awesome!!! Now I am a master of matrix 🙂

54. Harsha Hb says:

if everyone have taught the maths in primary schools as u do we would have had herd of mathematicians,….

55. Pratik says:

GREAT

56. Linux Authority says:

Education is what remains after one has forgotten what one has learned in school.

57. Nick Wertzberger says:

20 years after first being exposed to matrices, and getting a computer engineering degree, I finally understand matrix multiplication.

58. TheGamingViper X says:

I’m about to go in middle school and I still watch these high level math stuff because it’s really somewhat addicting to watch

59. Roshan Singh says:

Wrong logic for proving associative property through visualization of transformation. (AB)C cannot be thought of C transforming B then A. But logically, means C transforming the the resultant matrix from AB.

This feels like Khan Academy on High Voltage

61. Anna Lee says:

This is so amayzing

62. Monisha Damodaran says:

How do we know whether the transformation is shear or rotation by just looking at the matrix???

63. purple communist donkey says:

“Good news to the Hebrew readers…”

Arabic scripts: am i a joke to you?

64. Danica Rovó says:

I swear if there was a youtube Oscar this guy should get it

65. José Mendoza says:

OMG!!! that kind of lessons really make me understad linear algebra
thanks to take the time to do this 🙂

66. RAKSHIT SELOT says:

these r all 2*2 matrices examples ..what if the matrices is 2*3 or 4*4 .what does that mean graphically .

67. Anh N says:

crazy! I didn't even need this video, because it could be all deduced by the last one, but this was great to confirm the deduction and consolidate memory, thanks!

68. Anh N says:

I'm not sure if the associativity is as trivial as you say. with the brackets like this: (AB)C aren't we supposed to apply A on B first and then use the result and apply it on C? The way I see it it's not trivial and you just applied what results from associativity, you didn't prove it holds. But maybe I'm wrong.

I was never taught the reason behind matrix multiplication and how all of it is how it is. Thank you so much for posting high quality content, absolutely love it!

Now i see everything . Thank you.

71. Stephen Kersten says:

Where can we play w your visuals?

72. Christian Rolon Ruiz Díaz says:

BRILLANTE

73. Aakanksha Dimri says:

At 7:57 when Shear is applied to the rotated basis vectors. why does i(hat ) moves to 1,1 and J(hat) remains unchanged?

74. Chaitanya Bhardwaj says:

I really liked the idea of how you can imagine a matrix after watching this video. These videos are really mind blowing. They certainly don't teach us with this perspective and such details in schools. The idea of imagining 2D planes in a 3D space and what not! I mean, the highest I was taught in school was matrix transformation and multiplication, but just for the sake of it 😂.

75. eduardchante says:

Where is the donation's account?

If a matrix can be visualised as an entity for transformation of space then how a tensor can be visualised?

77. Teodora Nasz says:

I feel like associativity in general doesn't get proper respect. Thank you so much for your work!

78. Acatay Cetin says:

could you please visualize the diagonalization too?

79. santomon says:

i just find it so funny when these pi createures get angry

Matrix man…..

81. Folder says:

Thank you sir!!

82. CoolKat 31 says:

does a shear always turn 45 degrees to the right?
Im really confused with the m1m2 != m2m1

83. Eli Sagy says:

4:26 Yeah, go Hebrew readers!! 🙂

84. prabhu tej says:

at 4:50 can someone make me clear hw the transformation is done geometrically?(applying M2 after M1)

85. Andriy S says:

3:39 after rotation we have: green arrow – transformed i; red arrow – transformed j. right?
but applying shear matrix geometrically on the new transformed grid and I'm getting a different result then on video 3:40
I think the shear matrix (purple color) should be:
1 0
-1 1
Am I right? or better say Why am not right?

86. Sonu Gupta says:

Best channel

87. Feralz says:

7:07 This gave me cancer.

88. Vishank Patel says:

To prove the associativity of matrices,It be great if the transformations considered are simple. Think of each A,B and C as a 90° anticlockwise rotation, and it will be quite clear how it works!😄💎

89. Miguel Llancamil says:

it's so good that i'm crying

90. Vishank Patel says:

Sir, in the Rotation and then Shear transformation, shouldnt the j cap(red) be shifted by 45° rather than the i cap?

91. Mohamed Essam says:

Mind Blowing.

92. Shazeb Sayed says:

Thanks bro!

93. Pavan Aiyappa says:

I clicked on one video and now i'm not able to stop !! Now if you ask me what is Mathematics and what is Music ,answer would be same !!!

94. 弦之芥 says:

Amazing!!!!你简直是个天才！！我的天！！

Why the first time Shear affects j-hat but in the second one it affects i-hat?? 7:36
If shear affects i-hat or j-hat in the both times ,then there is no difference between M1*M2 and M2*M1 !!

96. Kevs Estrella says:

How did you do this mind blowing explanations sir?

97. Oswald Bourayne says:

I don't understand how you get the shear matrix (3:40), please could sb help ? 😀

98. Karthik Sridasyam says:

Doesn’t (AB)C imply that he’s transforming B then A, then that is transformed by C? Do the order of operations not apply because otherwise you would have to transform B then A prior to C.

99. Navneet Mishra says:

I can fkin jerk off on matrices

100. Pedro Jaraba says:

This is a fantastic complement to more math proof oriented books, it's important to grasp both approaches! Thanks a lot.