|
|
|
|
|
Inverse Matrix
How to Examples Exercise How to: First off, it should be noted that we can only find the inverse of a square matrix, and that not all square matrices will have an inverse. With that said, there are a few ways to go about finding an inverse in MATLAB. The first (the way we normally do it on paper) involves forming one large matrix with our square matrix and an identity matrix of the same size side-by-side. To do this: B = [A eye(# of rows in A)] Now, we put matrix B in Reduced Row-Echelon Form: B = rref(B) Assuming our matrix is invertible, B will now have an identity matrix in the first half of the columns, and matrix A's inverse in the second half of the columns. If B ends up being anything but this, it means it is non-invertible. Even though the above method is pretty simple, MATLAB has an even simpler way for us to find a matrix's inverse: B = inv(A) This will produce the same answer as above if A is invertible, or print out an error message if A is not. Examples: Let's find the inverse matrix of R = [1 3; 2 5] by both methods above. First, the slightly longer way. We need to form a matrix that combines both R and a 2x2 identity matrix: S = [R eye(2)] Next, we find the RREF of S: S = rref(S) This returns S = [1 0 -5 3; 0 1 2 -1] As you can see, the first two columns form our 2x2 identity matrix. The second two columns form the matrix T = [-5 3; 2 -1]. Thus, R is invertible, and T is its inverse. Now, the shorter way, again with R = [1 3; 2 5]: T = inv(R) This gives us the same answer as above, and in only one step. Exercise: |