 there we go it's a new year and let's just do matrix multiplication we've seen matrix addition and I very quickly wanted to show you matrix addition so we get away from this systems of linear equation idea of linear algebra and see matrices as this abstract thing that we can just manipulate and play with and do really fantastic things with and today we're going to talk about matrix multiplication and it's a bizarre thing there's going to be a little recipe that we follow to do this which is done without you know much explanation in the beginning we don't know why this recipe is chosen but this is the way matrix multiplication works and I think let's just look at the sizes of these here we have a two by two matrix remember two rows two columns two rows two columns let's look at these two rows and three columns two rows and three columns and here we have one two three rows and only two columns so the way matrix multiplication works just as I said we had with matrix addition that the two has to be of identical dimension yeah something something different happens in this and it's to do with the way that we do this matrix multiplication let's just look here at the matrix a b a and b and we multiply them and we can write a b or a dot b you're going to multiply them in that order remember if I were to say six times three that's six times three and then you also have by the commutative property three times six so let's look at this order two times three two by three matrix and a three by two matrix and the only way that you can multiply matrices just take my word for it now without any explanation is if you put them in this order it's a two by three and a three by two is if the column count in the first one and the row count in the second one are identical it's the only way that you can do matrix multiplication and look at this commutative property it's the a first and the b second if the column count here equals the row count there so these inner ones then you can multiply and the result will be a two by two matrix so the row count here and the column count there it'll be two rows and two columns so this was a three by three matrix it would have ended up as a two by three but here's a two and a two so it's gonna end up as a two by two I want to show you on paper because remember I hate this paper thing that's not the way the real world works but gotta learn how to do this by hand initially at least I think I want to just show you a very easy way and just another thing just think about it I mean if these were part of linear system of equations this will be x plus 2y plus minus 1 and it will be 2x plus 5y how do you multiply those things too so just see these for now as an abstract thing this matrix so an easy way to do this is you take the first one and you write it on your piece of paper far away from anything else what do we have a one two and a negative one and we're gonna have a three one and a four so there's neat two little rows and three little columns and I said to you the answer is going to be a two by two so let's do this there's going to be this two by two solution here that we're looking for so you've got to fill that in and what we're going to do is there's two columns there there's two columns there we're going to write that one neatly up here so that's negative two and a five so that they line up with these two these two line up with those and that's all you need four and a negative three and a two and a one very simplistic after you've done many of these in your head which you shouldn't really have to do because matrices we deal with in your life are enormous and you know to do that magic multiplication you're not going to do that on paper you're not going to do that in your head so learn how this works so that you just get it now to get to this first one row one column one you see it very neatly lines up with three elements in this row and three elements in that column hence those two having to line up now you get it why this needs to happen because this is where we define magic multiplication so there's three elements there there's three elements there and all we're going to do is pair them up so this one and that negative two this two and that four this negative one and that two they pay up we just multiply them as this multiplication and then we just add the three multiplications so one and negative two is negative two plus eight that gives us six six minus two gives us four let's see again so that's minus two another minus two so that is negative four plus eight gives me four so I just multiply this one by that one the second one by the second one the third one by the third one those multiplications and I just add them up whether they'd be positive or negative values so for this second one it's still if you look at it it's in this row and it's in that column so we get to pay up these three elements so that's five minus six is negative one minus another one gives us negative two this one is very neatly with a second row in the first column it lines up this way and it lines up that way so that's negative six plus four is negative two plus eight gives me a six and the last one that is 15 15 minus three is 12 12 plus four is 16 and there's my solution and lo and behold it's a two by two matrix so you get it very simple to do if you do it this way because you can see that this one corresponds to this column here and this row here it's element by element multiplication and you just add up you know what this multiplication is a negative two plus eight gives me a six minus another two gives me four so let's look at this it's a bit simpler and let's just do a times b let's do it in the same way we're going to have a times b and that is going to equal let's write it far away a one and a two and a negative one and a three and here we're going to have the two and the one and the zero and the one so again two elements here line up with two elements there for this one two or two two or two we see these in a two this column this row they're the same and the result is going to be a two by two so let's do this so two times one that's this two two times one's two plus zero one times one is one plus two is three and we have minus two and we have three so there we go it's a two by two matrix that is my solution let's just check negative two for that one negative one three see there's a little mistake so this this one is this row and that column so that's negative one and that's a three so that's a two just three that i don't make simple arithmetical errors you get it what i want to do here very quickly is this what is b times a so by the commutative property let's swap those two around so now we're going to have the two and the one and the zero and the one and here we're going to have the one and the two and the negative one and the three let's do that multiplication so we see for this one here that's two minus one is one it's already different we have four and three is seven we have zero and negative one that's negative one we have zero and three that's three look at that a times b does not equal b times a so when it comes to matrix multiplication for the vast majority of instances the commutative property of multiplication does not hold it really does not hold second thing we have to remember is you can only multiply certain matrices with each other so if you see matrix multiplication as some binary operator on some set of elements that set is only defined under certain circumstances so if i have a set of all different kinds of matrices the ones that i could multiply here would be ones that at least the row column the row number the column number and the row number the column of the first one the row number the second one they have to be identical otherwise you cannot get a result when you multiply also remember that for the vast majority of cases the commutative property does not hold let's go to mathematics this i mean matrix multiplication is a beautiful thing so let's go to math america and just have a look and see how easy that is and you can then well imagine if you have to do some large matrix multiplication large matrices hundreds of rows hundreds of columns and even larger you're not going to do that behind by hand as long as you understand this simple principle and you can do a few ones by hand the only mistake you're going to make is simple little arithmetical errors and we can all make those this is really not difficult but with these if you write it in this very simplistic way as i showed you the first one of the pair you write here the second one of the pair there and then these things line up very neatly and it's and it's so easy to do let's go to math america and have a look so here we are in math america we are continuing with us with our matrices we're going to do just look at multiplying two matrices by each other so we have this binary operation called multiplication and we have two elements from a set set of certain matrices and we're going to multiply them with each other you'll see these other ones that we had on the board ab and then the other ab i'm just going to call them m1 m2 m3 and m4 here in math america just just to make things simpler when we do type our code so let's just create these two matrices so you'll see here there's a number one on this side so the cell was one of those numbered text cells so here we are just in a normal code cell so i'm going to call it m1 you see the different color there remember how to create matrices we're going to do them row by row so the first row for m1 was going to be 1 comma 2 comma minus 1 we close our our curly braces it is a list and it's a list inside of a bigger list so nested list it's the way that we go to create them and the second row is 3 comma 1 comma 4 we close that row and we close the whole we close the whole matrix there i'm going to just hit enter there let's go to m2 and the way we're going to do m2 exactly the same it's just a three other three one four one two negative one three one four was the first matrix the second one is going to be let's have a look negative 2 and 5 we close that because it's just two elements in that row second row is 4 comma negative 3 close curly brace the next curly braces and a 2 comma 1 and close the whole matrix so negative 2 and 5 4 negative 3 2 and 1 let's just carry on we do all of them m3 let's just do that one it's 1 comma 2 and in the second row we have negative 1 comma 3 close and close and then the last one m4 and it has 2 comma 1 and it has 0 comma 1 and the second one i'm going to put a semicolon there right at the end hold down shift and hit enter or shift in return now see what happened here the semicolon was just after the second one so unlike other languages which might suppress all of that output it only suppressed the last one so we can actually see all of the others so if you don't want to suppress to the screen remember to put semicolons after each and every one of these rows let's look at our matrices i'm going to say m1 and i'm going to put it in matrix form i used a tab completion there shift enter shift return and beautiful there 1 2 negative 1 and 3 1 4 let's look at the dimensions the dimensions of matrix m1 let's have a look at that the dimensions and we see it's a two by three two rows and three columns this is weird on the board let's look at the dimensions of m2 and we see it's a three two so we know we can do m1 times m2 but we cannot do or it's possible now if you look at it the other way around three times two and a two times three yes we can do that and you'll notice that the solution of that is going to be a three by three matrix we didn't do on the board we might do it here so let's go ahead and just do that m1 and it's very simple dot m2 and the dot is just a full stop and let's just put the solution in matrix form and lo and behold there we have it four negative two six and sixteen just as we had on the board let's look at what m2 dot m3 is going to be and we'll say put that in matrix form please and there we see three by two matrix now let's let's have a look at this oh it's not m by m1 let's have a look at that there we go three by three matrix just as we said if the m2 comes first its column count which is two must equal the row count of the second one which is m1 and that's two and the result will be these outside and it's a three by three matrix and you see the solution very well there just to belabor the point let's do that m3 dot m4 and we put that in matrix matrix form and we see that there and if we do m4 times m3 and we do that in matrix form we see the solutions are not the same we can even ask that m3 dot m4 is that equal to remember that's double equal sign that asks the question m4 dot m3 and we see the answer the solution is false it cannot you know it does not commute under these circumstances one thing we didn't do on the board that I just wanted to show you is just what happens if we do scalar multiplication so imagine I just had three times three times m3 let's have a look at that and let's put that in matrix form let's say three times m3 and we put that in matrix form to the screen please and look what happens let's just see what m3 was again so you can see clearly there it was one two negative one and three and you can see what happens with scalar multiplication each element in the matrix is multiplied by this scalar whatever the scalar is so three times one is three three times two or six three times negative one is negative three and three times three is nine so scalar multiplication is very easy I mean that's that's this easy easy easy to do so there you go on the board and more importantly in Mathematica in a computer using a computer programming language you can it's so easy to do matrix multiplication