 So if we go to the races, part 3, Introduction to Matrices. If you've watched the other videos, you know, when you just land up with this one, you know, go to the start, the first lectures on vectors, which for me is the ultimate basic fundamental thing of linear algebra. Now the second one's Matrices just, but there's so much to say about Matrices, I've split it into different videos. So you know, do the whole playlist if you just suddenly, and if YouTube just suddenly shows you this video, there's much more to it. And of course, if I do remember, in the description down below is going to be a link, or you just search for it on my YouTube channel on how to set up a Julia environment, which we've done here, and then how to open these Pluto notebooks and activate said environment, which you can see in the setup. So I'm not going to repeat myself because it's part of all these videos, I don't want to repeat it in all these videos and bore you to death. But anyway, we're activating our environment that contains the packages specifically to this project of linear algebra using Julia. And what that's all about is teaching you linear algebra, but also showing you a modern way of doing it, using code to check your work and to gain a deeper understanding and make it a hell of a lot more fun. So what we're going to use here is just a single one of the packages, the linear algebra package you've seen using linear algebra there. So this one's quite easy. I mean, the previous video where we used it to solve linear algebra to solve linear systems. I mean, it takes a while to get used to you just doing simple algebra, you're just writing it in a different way doing these elementary row operations. Anyway, so I promised you that matrices themselves, they are mathematical objects, which in some way has nothing to do with Gauss-Jordan elimination and solving systems of linear equations. They are mathematical objects in their own right. And so what we're going to do here in this video is just going to look at very simple stuff to do with them as mathematical objects. The first thing that we can do is just add and subtract two of them. So you see two matrices there in equation one, A and B, and you know now that the rows of values and columns of values and adding them, the way that we've defined as human beings the addition of two matrices is that we do it element wise. So the element in row one column one adds to the element in row one column two and element in row one column, row one column one and row one column one, what am I saying? And then the element in row one column two goes as to the element in row one column two of the other one. So you can see there A and B and then A plus B. And it's addition just as we did with grade one or whatever way you start your school career, a simple addition. Fundamental importance here is they've got both got to be of the same dimension or in computer language terms the same shape, in other words equal number of rows and equal number of elements. So I can't add one if it had more rows and more columns because what am I adding it to? You can't just say well just pad it with zeros, if you pad it with zeros it's a different matrix. So they've got to both have the same number of rows and same number of columns otherwise addition and subtraction are not defined. So if you get that little if your teacher or lecturer is kind of that mean and ask you to in a test to add these two matrices and they don't have the same don't pad the one with zeros and then try and give a solution you're right there. This addition is not defined because we cannot add by definition two matrices if they don't have the same number of rows and columns and a story, no calculation required. So problem one they create two two by three matrices in code and investigate the results of the addition. So I've just created one there we see that the column vectors there one two two four three three and I've saved that as the computer variable called matrix underscore one and you see the result there is a two by three array of 64 but integers along two axes and I've created another one which is three zero negative one four zero two and but I've created a row wise remember how to create these with the spaces in between and the semicolon meaning jump to the next row etc. And I've just said matrix one plus matrix two and if you look very carefully one plus three is four the two there plus the negative one there is one three plus zero is three so it's element wise addition and the same goes for subtraction I mean there's a bit more to it and we'll get to that one first but intuitively it's just subtracting the second one from the first one nothing going on there and then in problem two there I've said oh let's let's correct this I like to correct the errors as we go as I pick them up because we save these two get up so you can download them so the fewer mistakes that are in there the better so subtract the second matrix in problem one from the first matrix and investigate the results so it's matrix underscore one minus matrix underscore two and you can just see it's subtraction of those elements but what's happening in disguise is there isn't any there isn't really something well I can't say that but let's say it isn't really something called matrix subtraction it's actually just addition in disguise because what we're doing is scalar matrix multiplication now we've seen scalar vector multiplication we take a scalar we multiply each element of the vector we're doing exact same thing here taking a scalar we're multiplying each element in the matrix by that scalar such that we get equation three here we neatly written out so it's a m by n so it's all generic so whatever you want to make m and n you multiply scalar k by it it's each element multiplied by k so if we make k negative one a minus b is actually a plus negative one times b so it still remains matrix addition so it's actually the only thing as I say don't worry I'm just you know spitting out some words yeah a plus negative b it's a plus the scalar negative one times b you get it it's not the figure so that was what we do the scalar matrix multiplication three times matrix one that's just gonna give you three times each of the elements nothing's really nothing special only thing remember they've got it when you do addition or then this pseudo subtraction is they've got to be both of similar number of rows and columns otherwise you just write they're not defined okay that brings us to the fact that they added of there's an additive identity so if you think about drill numbers the additive identity is the element is zero because anything times here a plus zero or zero plus anything remains anything okay there is this idea of an additive identity for matrix addition that if you add this matrix this identity matrix additive identity matrix to any other matrix that matrix remains I'm I'm changed in because you know now that it's element wise addition and we're just dealing with numbers here of course this is going to be the matrix full of zeros and also there's this additive inverses and what the additive inverses does it says any matrix that I have I can get this unique additive inverse such as when I add the two I end up with the identity matrix and other it's all zeros and it's just the same as with numbers I mean the additive identity of three is negative three because if I add negative three to three I get the additive identity which is zero okay so in problem four I say add the preferably size zero matrix to the first matrix and remember in the first video I showed you these little shortcut functions the zeros function two comma three because it's got to be the same size remember and if I add that to matrix one matrix one doesn't change at all and this matrix addition we'll see that actually commutes so I could also say the zeros one plus matrix one it's gonna be the same thing and then every matrix has its unique additive identity negative for a it'd be negative a so that a plus negative this negative a equals the zero matrix or zeros so solution five is that the additive inverse of that and of course the edited inverse is that it's just negative one times that whole matrix and if I add those two together I get all zeros nothing nothing and what I say yes because of the inheritance and that's a very important little sentence I put in there because we're gonna talk about proofs now and before you run away we're not doing any proofs here and proofs in introducing proofs in linear algebra is both good and bad enough and I'll tell you why but what we're doing here is we just inheriting from adding and subtracting and multiplying real numbers and because we know that there's commutativity and associativity there we're also gonna get commutativity and associativity when it comes to matrix addition and let's just get back to the proofs a little bit I'm digressing but I think it's important is sometimes in the textbooks in your class you're just gonna be asked to do proofs as well and just thrown in the deep end of these proofs and that's just absolutely nonsense because you start hating proofs and you try just to memorize them and it's just just a shamble so if you want me to make a video on the proofs I definitely try and find some time to make those but what it boils down to is we inheriting from something else and what we're inheriting from when it comes to here is from an example of a field and an example of the field would be the real numbers now when I talk about field I'm talking about field rings and groups and that's part of something called linear abstract algebra or modern algebra an abstract algebra is one of probably one of the most beautiful subjects or topics in mathematics and it puts a firm ground into these things that we just at school learn to take on face value oh but we have this thing called additivity or multiplication on real numbers where there's some much deeper SHIT going on there and that is oh I should delete that I probably will leave it in but anyway there's a there's some deep stuff going on in abstract algebra and we establish these properties and we say if something obeys these properties then they are an example of this thing and one of these things in abstract algebra is a field and we have these properties of a field and then we check the real numbers actually obey all these properties therefore a real number must be a field and the way that we set up the reals now I managed to set up the reals you need to set up the integers and to set up the integers you need to set up the natural numbers and pianos postulates and all those things I mean it all goes back so far down the rabbit hole which is actually where you need to start and actually the things that they need to teach you in the beginning just make mathematics much more fun and understandable than this wrote sort of stuff that you try to do and that's just nonsense but anyway boils down to such a deep thing and abstract algebra is absolutely the basis of all of that and that's a fun thing but I'm talking all about proofs here so a little bit up up from the bottom depths of the rabbit hole is the fact that the real numbers are a field and a field has these properties and one of the properties are as we set up the real numbers is the fact that we have associativity and commutativity mean two plus three equals three plus two and two times three equals three times two and associativity is also there because we inherit those properties that makes it very easy to do these proofs because all you really have to say in a proof is number one that's the how we define addition element wise and because we inherit from the from the properties of the field of real numbers we can prove that these things are the way that they are this is the sort of inheritance that makes us these proofs quite a bit of fun and I think you have to spend some time sort of considering these things and that makes these proofs we sometimes as the same many others just chuck that you and then you have to try and memorize what's going on there because it makes no sense and actually they quite easy and actually they're beautiful and it's such an opportunity to be introduced to proofs in a non-threatening easy and fun way and of course because of constraint timers for the time they just chucked upon you and then you hate proofs and then it's just a disaster anyway where was I problem number six investment gate commutativity of two matrices now remember this is not a proof an example is never proof a counter example you know that's very important if someone you know states this postulate or you know things saying that something and something and you find a counter a count example and then that theorem you know then that thing if it was a theorem before because someone approved it before that theorem disappears because there's a count examples a count examples are very important in the disproving of a theory or making a postulate never become a theory but examples are never proofs but I'm going to show you example here because I just wanted to show you you know help you with this intuitive understanding so there we create another matrix there and all matrix one and two which we've already created and we say magic sub one plus magic sub two a magic sub two plus magic underscore one I should say and you see the results are exactly the same here and in solution six and then as far as the associativity is concerned we also grab the matrix three remember they all have the same number rows and columns otherwise it's not defined and you can see I've set those two up first add one and two and then three and then secondly add two and three and then add one to that and you can see if I use this double equals operator that's a logical operator asking is the left-hand side equal to the right-hand side and the result is this bit value two okay then and the next one I can also do the scalar multiplication over addition so I've got this addition of the two matrices I can add them first and then do the scalar multiplication or I can do the scalar matrix multiplication first to bother them and add them I end up with exactly the same thing and if you ask to prove this well you just inherit from the properties of the field of real numbers and Bob Johnkel anyway there's problem investigate the stupid the distributivity of this of a scalar with addition of the two matrices there we go so again three times first addition and then three times plus three times and you are both gonna end up you're gonna end up with the same thing and as I say the proof of that is very easy then at the end here we come to matrix matrix multiplication that's a lot more fun and it really boils down to the vector dot product because in the resultant vector if we are in the resultant matrix if we multiply two matrices we're gonna end up with the resultant matrix and each element in that is the result of a rona column dot product so that we have these two vectors that we dot product with each other and video one is all about that you know has that in it so you can go watch that again but just as a reminder I put it out for you here so if I have these two column vectors you and V I can do the dot product and that would be the same as the transpose of one all in video one but what it is is you dot V so I take this V and I make it turn it from a column vector into a row vector and then it just becomes you 1v1 plus you 2v2 plus you 3v3 and something hidden here is the number of elements remember because you want to do dot product both of those vectors have to have the same number of elements in them otherwise you can't and that brings us to this fundamental factor it's just written here easy PZ as if it's nothing but it's fundamental that the consequence is that matrix matrix multiplication is only defined for two matrices a mn and bnp so see the two ends they are the same so the column number of the first one has to equal the number of rows in the second one otherwise it's not defined so the number of columns in the first must equal the number of rows in the second is not defined and what you end up with the resultant one has the number of rows that the first one has and the number of columns that the second one has so you have this a b multiplied that its dimensions now going to be mp so the row number of the first one and the column number of the second one and it's only defined if if the columns in the row columns of the first rows of the second are the same so remember that little sentence and it comes down to the fact that this is the the dot product you know we for each element we are we doing a little dot product so in problem nine yeah we're going to create a three by four and a four by two matrix and in that order because we'll see commutativity doesn't hold when it comes to this bugger which is matrix multiplication so the column number therefore the row number there is four so in that order we can multiply it and the result will be a three times two matrix so there we create one a three times four just a thumbs up one and five as a four by two one so four rows and two columns and then we just simply use this multiplication symbol which in the computer languages is the star symbol shift eight on my keyboard and we just multiply them and lo and behold we get a three by two just as promised so how how did this happen behind the scenes I'm not going to do this whole thing here I'm going to do the I think I've described the first two here but again these are one of those things you have to sit down or stand on at the board or whatever you do and just do a bunch of them and just get familiar with how to do it but let me just construct the first two solutions for you see the 15 and then we also going to go for that nine there so let's do that how do we get to that 15 so read here in this solution above we note that the first element in the result matrix is 15 this is the dot product of the first row of matrix 4 and the first column of matrix 5 okay and they both if we look at the first row there we see the first row 1 2 3 4 the first row the first column 1 0 2 2 so if I do that I can do that dot product because it's both four elements long so one times one and two times zero and three times two and four times five and if I add those four multiplications I get to 15 and you see there I do the same for the element in position 2 2 this nine here it is a dot product between if so that resultant one is in where are we that nine in row two column two so it's going to be a row 2 in the first one column 2 in the second one gives me row 2 column 2 that solution in the last in the resultant matrix and it's really a simple as that it's a bunch of dot products and as remember this little simple sentence yes so when is it defined and how do we do it if we want to go for solution in the solution say row 1 column 2 we take row 1 of the first column 2 of the second one if we do that dot product for those two vectors the row vector in the column vector we do the dot product there we get that solution as simple as that so here I've got create 2 3 by 3 matrices and if they 3 by 3 both of them I can do a times B and B times a because we're going to get the 3 3 in the middle in that matter which order I do it I get the 3 3 in the middle in other words the column of the first one the row and value of the second one but you'll see if I create two ones I call it matrix underscore six matrix underscore seven I multiply them I don't get the same results and if I use the logical operator there I get a false so even if it is defined by the number of rows and columns the commutivity does not hold it's not commutative commutativity does not hold for matrix matrix multiplication so do a bunch on your own it's it's really not that difficult this is a bunch of arithmetic and you mustn't make any earth mathematical errors and it's check your work just create them in code and multiply them by each other and see the result and come back to this make notes on in Julia like I've done here it's been nice for me I like notes to be neat that's actually why I do this for myself and also other works that I do I don't write on paper do it like this because it looks neat neat in my handwriting anyway but then again I am a surgeon and you know doctors have horrible handwriting so there we go I have to make my notes like this I hope you enjoyed that very important that you have to leave a comment and equally important you have to if you haven't already done so subscribe so this is the whole series it uses Julia but you can use other languages as well if you want me to do more use another language or whatever the case might be discuss this and of course if I made little errors anyway tell me about it so we can correct it because these notebooks can't get up so you can download them subscribe leave a comment like or dislike twice gotta make that little printly I have to make that little youtuber as if I'm a real youtuber comment a little funny comment anyway I hope you enjoyed this one and part 4 is coming up