Hello everyone. Welcome to our lecture, finding inverses of a higher dimension matrices. From the previous video, we learned how to find the inverse of a matrix in two-dimension and three-dimension. In this video, I'm going to show you how to find the inverse of higher dimension matrix using both NumPy and SymPy. Let me import those library, I import the NumPy and SymPy so that I'll be able to build matrix of them. To find the inverse of the matrix, we first need to have a matrix. Let's say I will define matrix M is the NumPy matrix, so I'll call np, that stand for NumPy. That array, so I'm going to use numpy array to build this matrix. The matrix, the rows come as a member of lists, meaning they have to be in-between square bracket. You see the square bracket in green here at the beginning and at the end. Necessarily, if I don't put that, I will have an error message. Now I will tell what number I want to be in the entry. The first row has entry 1, 2, 3, for example. Second row have entry 4, 5, and 6. Seven entry is 7, 8, and 11, something like that. If I want to see the output, then I will print out the M matrix again, so this is our matrix M. To find the inverse of this matrix using NumPy, we'll learn that all you need to do, let's say, I'll call the inverse call N, N equal, we'll use the linalg function, so np.linalg.inv, inv stands for inverse, inv and I will put the matrix M in there. It will take matrix M as parameter. Now if you print N, you will see that it is the inverse of M. If you want to check that these two are inverses of each other, one way to do that is to find the multiplication of M and N. One thing you can do is matrix multiplication so, np.matmul, so this will multiply the two matrix. You can just enter M and N and we can store the result to a variable called I3 because it's a three-by-three matrix. If you want to see I3, we can print it here and there you go. This is a identity matrix. Because you look at this, this is a negative 2 to the power 10 to the negative 16. This is zero basically, this number zero, you got one here. This number is also zero. We got 10 to the negative 17, 10 to the negative 16, so that's pretty much zero. Yes, N is the inverse of M, so that's in three-dimensions, so we can go higher. You use the same method if you go to higher dimensions. Instead of manually building my matrix, I will use random numbers to build a matrix. Let's say I'll call a matrix R. R equal to, I will use a random number, so np.random.randint and then I'm building this matrix of random numbers. I can pick a random number between, for example, negative 8 and positive 8 and I want to use the size. I can use the size equal, let's say 10 by 10, so I want to have 10 rows, 10 columns. This is our matrix R. If you want to see R, you can just plug it out here. This is a random matrix. If you look at the first row, I'm going to run it again. You see that this will change. That's why is a random matrix, you see it changes. This is four negative 8. Let me change. I'll run it again. You see it becomes seven, zero. It's a random matrix built of random numbers. Now we can find this inverse using the same exact method. I will call the inverse of R to be S. S equal numpy.linalg.inv and then I'll put the matrix R in there and then if you want to see the S is here. Again, you can check the multiplication of R and S, so R.S for example. That's another way to multiply these matrices. See is a random matrix. Let me make it look nicer. One thing you can do is to put it here if you want to make it look nicer. You can use SymPy to do that. Sympy you apply to that, I think that will make it look a little bit nicer. Let me see. Yeah, it look like that. It's a big matrix. You see any non-zero number have the power negative number, here is negative number. That means all of these numbers are zero , except this one. Here, all of them are zero except this 0.999, which is one. Identity matrix, let me write what identity matrix look like. A 10 by 10 identity matrix will look like this. Let me call it I10 is equal to sy.eye, so I'll put just 10 here. Let me look at I10 here. If I plug in, this is what it look like. The diagonal entry are non-zero, everything else is zero. If you look at the diagonal, this is non-zero. Everything else is zero because they are 10 to the negative something, 10 to the negative 16 that's zero,10 to the negative 17 that's 0. These two matrices are inverse of each other because their product give you identity matrix. Now, speaking about SymPy, we can do the same thing. We can find inverses of matrix using SymPy. Let's build a matrix Q, we'll say Q equal sy.matrix. We're going to build a matrix of SymPy library. Here we can use random numbers or we can manually enter it. Let's pick a five-by-five. I'm going to manually enter this numpy.random.randint. I want to build a five-by-five. I'll put here from negative 4-5 and then the size equal five-by-five. That's Q, look like this. This is Q, and then to get the inverse of Q, let's call it P. To get the inverse using SymPy, all you need to do is to use a method inv to do that and then let's print P. That's the inverse of Q. Again, we can check out the multiplication numpy.matmul, so matrix multiplication of P, Q. Let's see that, you see is an identity matrix. It's a five-by-five matrix, is an identity matrix. The same thing is true with for 100 dimension, 1,000 dimension. You use the same thing. In this video, we'll learn how to find the inverse of a higher-dimension matrix using SymPy and NumPy first and then we populate a matrix using random numbers and then find the inverse using NumPy again and then lastly, we find the inverse of higher dimension matrices using SymPy. Thanks everybody. See you next time.