# Intro to matrix inverses

## Video transcript

We've learned about matrix addition, matrix subtraction, matrix multiplication. So you might be wondering, is there the equivalent of matrix division? And before we get into that, let me introduce some concepts to you. And then we'll see that there is something that maybe isn't exactly division, but it's analogous to it. So before we introduce that, I'm going to introduce you to the concept of an identity matrix. So an identity matrix is a matrix. And I'll denote that by capital I. When I multiply it times another matrix-- actually I don't know if I should write that dot there-- but anyway, when I multiply times another matrix, I get that other matrix. Or when I multiply that matrix times the identity matrix, I get the matrix again. And it's important to realize when we're doing matrix multiplication, that direction matters. I've actually given you some information here that-- we can't just assume when we were doing regular multiplication that, a times b is always equal to b times a. It's important when we're doing matrix multiplication, to confirm that it matters what direction you do the multiplication in. But anyway, and this works both ways only if we're dealing with square matrices. It can work in one direction or another if this matrix is non-square, but it won't work in both. And you can think about that just in terms of how we learned matrix multiplication, why that happens. But anyway, I've defined this matrix. Now what does this matrix actually look like? It's actually pretty simple. If we have a 2x2 matrix, the identity matrix is 1, 0, 0, 1. If you want 3x3, it's 1, 0, 0, 0, 1, 0, 0, 0, 1. I think you see the pattern. If you want a 4x4, the identity matrix is 1, 0, 0, 0 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1. So you can see all that any matrix is, for a given dimension-- I mean we could extend this to an n by n matrix-- is you just have 1's along this top left to bottom right diagonals. And everything else is a 0. So I've told you that. Let's prove that it actually works. Let's take this matrix and multiply it times another matrix. And confirm that that matrix doesn't change. So if we take 1, 0, 0, 1. Let's multiply it times-- let's do a general matrix. Just so you see that this works for all numbers. a, b, c, d. So what does that equal? We're going to multiply this row times this column. 1 times a plus 0 times c is a. And that row times this column. 1 times b plus 0 times d. That's b. Then this row times this column. 0 times a plus 1 times c is c. Then finally, this row times this column. 0 times b plus 1 times d. Well, that's just d. There you have it. And it might be a fun exercise to try it the other way around as well. And actually it's an even better exercise to try this with a 3x3. And you'll see it all works out. And a good exercise for you is to think about why it works. And if you think about it, it's because you're getting your row information from here and your column information from here. And essentially, anytime you're multiplying, let's say this vector times this vector, you're multiplying the corresponding terms and then adding them, right? So if you have a 1 and a 0, the 0 is going to cancel out anything but the first term in this column vector. So that's why you're just left with a. And that's why it's going to cancel out everything but the first term in this column vector. And that's why you're left with just b. And similarly, this will cancel out everything but the second term. That's why you're left with just c there. This times this. You're just left with c. This times this. You're just left with d. And that same thing applies when you go to 3x3 or n by n vectors. So that's interesting. You have the identity vector. Now if we wanted to complete our analogy-- so let's think about it. We know in regular mathematics, if I have 1 times a, I get a. And we also know that 1 over a times a-- this is just regular math, this has nothing to do with matrices-- is equal to 1. And you know, we call this the inverse of a. And that's also the same thing as dividing by the number a. So is there a matrix analogy? Let me switch colors, because I've used this green a little bit too much. Is there a matrix, where if I were to have the matrix a, and I multiply it by this matrix-- and I'll call that the inverse of a-- is there a matrix where I'm left with, not the number 1, but I'm left with the 1 equivalent in the matrix world? Where I'm left with the identity matrix? And it would be extra nice if I could actually switch this multiplication around. So A times A inverse should also be equal to the identity matrix. And if you think about it, if both of these things are true, then actually not only is A inverse the inverse of A, but A is also the inverse of A inverse. So they're each other's inverses. That's all I meant to say. And it turns out there is such a matrix. It's called the inverse of A, as I've said three times already. And I will now show you how to calculate it. So let's do that. And we'll see calculating it for a 2x2 is fairly straightforward. Although you might think it's a little mysterious as to how people came up with the mechanics of it, or the algorithm for it. 3x3 becomes a little hairy. 4x4 will take you all day. 5x5, you're almost definitely going to do a careless mistake if you did the inverse of a 5x5 matrix. And that's better left to a computer. But anyway, how do we calculate the matrix? So let's do that, and then we'll confirm that it really is the inverse. So if I have a matrix A, and that is a, b, c, d. And I want to calculate its inverse. Its inverse is actually-- and this is going to seem like voodoo. In future videos, I will give you a little bit more intuition for why this works, or I'll actually show you how this came about. But for now it's almost better just to memorize the steps, just so you have the confidence that you know that you can calculate an inverse. It's equal to 1 over this number times this. a times d minus b times c. ad minus bc. And this quantity down here, ad minus bc, that's called the determinant of the matrix A. And we're going to multiply that. This is just a number. This is just a scalar quantity. And we're going to multiply that by-- you switch the a and the d. You switch the top left and the bottom right. So you're left with d and a. And you make these two, you make the bottom left and the top right, you make them negative. So minus c minus b. And the determinant-- once again, this is something that you're just going to take a little bit on faith right now. In future videos, I promise to give you more tuition. But it's actually kind of sophisticated to learn what the determinant is. And if you're doing this in your high school class, you kind of just have to know how to calculate it. Although I don't like telling you that. So what is this? This is also call the determinant of A. So you might see on an exam, figure out the determinant of A. So let me just tell you that. And that's denoted by A in absolute value signs. And that's equal to ad minus bc. So another way of saying this, this could be 1 over the determinant. So you could write A inverse is equal to 1 over the determinant of A times d minus b minus c, a. Anyway you look at it. But let's apply this to a real problem, and you'll see that it's actually not so bad. So let's change letters, just so you know it doesn't always have to be an A. Let's say I have a matrix B. And the matrix B is 3-- I'm just going to pick random numbers-- minus 4, 2 minus 5. Let's calculate B inverse. So B inverse is going to be equal to 1 over the determinant of B. What's the determinant? It's 3 times minus 5 minus 2 times minus 4. So 3 times minus 5 is minus 15, minus 2 times minus 4. 2 times minus 4 is minus 8. We're going to subtract that. So it's plus 8. And we're going to multiply that times what? Well, we switched these two terms. So it's minus 5 and 3. And we just make these two terms negative. Minus 2 and 4. 4 was minus 4, so now it becomes 4. And let's see if we can simplify this a little bit. So B inverse is equal to minus 15 plus 8. That's minus 7. So this is minus 1/7. So the determinant of B-- we could write B's determinant-- is equal to minus 7. So that's minus 1/7 times minus 5, 4, minus 2, 3. Which is equal to-- this is just a scalar, this is just a number, so we multiply it times each of the elements-- so that is equal to minus, minus, plus. That's 5/7. 5/7 minus 4/7. Let's see. Positive 2/7. And then minus 3/7. It's a little hairy. We ended up with fractions here and things. But let's confirm that this really is the inverse of the matrix B. Let's multiply them out. So before I do that I have to create some space. I don't even need this anymore. There you go. OK. So let's confirm that that times this, or this times that, is really equal to the identity matrix. So let's do that. So let me switch colors. So B inverse is 5/7, if I haven't made any careless mistakes. Minus 4/7. 2/7. And minus 3/7. That's B inverse. And let me multiply that by B. 3 minus 4. 2 minus 5. And this is going to be the product matrix. I need some space to do my calculations. Let me switch colors. I'm going to take this row times this column. So 5/7 times 3 is what? 15/7. Plus minus 4/7 times 2. So minus 4/7 times 2 is minus-- let me make sure that's right-- 5 times 3 is 15/7. Minus 4-- oh right, right-- 4 times 2, so minus 8/7. Now we're going to multiply this row times this column. So 5 times minus 4 is minus 20/7. Plus minus 4/7 times minus 5. That is plus 20/7. My brain is starting to slow down, having to do matrix multiplications with fractions with negative numbers. But this is a good exercise for multiple parts of the brain. But anyway. So let's go down and do this term. So now we're going to multiply this row times this column. So 2/7 times 3 is 6/7. Plus minus 3/7 times 2. So that's minus 6/7. One term left. Home stretch. 2/7 times minus 4 is minus 8/7. Plus minus 3/7 times minus 5. So those negatives cancel out, and we're left with plus 15/7. And if we simplify, what do we get? 15/7 minus 8/8 is 7/7. Well that's just 1. This is 0, clearly. This is 0. 6/7 minus 6/7 is 0. And then minus 8/7 plus 15/7, that's 7/7. That's 1 again. And there you have it. We've actually managed to inverse this matrix. And it was actually harder to prove that it was the inverse by multiplying, just because we had to do all this fraction and negative number math. But hopefully that satisfies you. And you could try it the other way around to confirm that if you multiply it the other way, you'd also get the identity matrix. But anyway, that is how you calculate the inverse of a 2x2. And as we'll see in the next video, calculating by the inverse of a 3x3 matrix is even more fun. See you soon.