Section 9.1 Inverse Matrix
Let \(A\) be a square matrix. A matrix \(B\) is called an inverse of \(A\) if \(AB = I\) and \(BA = I\text{,}\) where \(I\) is the identity matrix.
If such a matrix exists, we say that \(A\) is invertible and we denote the inverse by \(A^{-1}\text{.}\)
We can ask Sage whether a matrix is invertible using the
is_invertible() method:
In Sage, if a matrix is invertible, the inverse of a matrix can be computed using the
inverse() method:
We can check that the products of these matrices are actually the identity:
Exponent notation also produces the same result.
Observe that a matrix is invertible over its base ring. Even though the next matrix is invertible, we would obtain a false result if we do not specify the ring:
By calculating the inverse, we can see that the inverse exists and therefore \(A\) is invertible, though the coefficients are not integers:
If we specify the ring to be the rationals, we obtain the correct result:
Next, we will show how to use Sage to implement the different ways in which we can calculate the inverse matrix.
Subsection 9.1.1 Echelon Method
A matrix is invertible if and only if the reduced row echelon form is the identity matrix. We can find the inverse matrix of \(A\) by augmenting \(A\) by the identity matrix \(I\) and then finding the reduced row echelon form. If the matrix is invertible, the first half of the matrix would be the identity and the second half the inverse matrix.
Letβs start by augmenting the matrix.
By invoking
rref(), we obtain the reduced form of the augmented matrix, which allows us to determine whether the original matrix is invertible.
Since the left sub-matrix is the identity matrix, the original matrix is invertible and the right sub-matrix is the inverse. We can obtain the inverse using the
submatrix() method:
This algorithm coincides with Sageβs built-in
inverse() method:
Subsection 9.1.2 Adjugate Method
The adjugate matrix can be used to compute the inverse of an invertible matrix using the formula: \(A^{-1} = \frac{1}{\det(A)} \cdot \text{adj}(A)\text{.}\)
This algorithm also coincides with Sageβs built-in
inverse() method:
Subsection 9.1.3 Comparing Methods
The three methods coincide when the matrix is invertible.
Letβs see how they differ in the way they handled non-invertible matrices.
In the case of a matrix that is not invertible, the
inverse() method will raise an exception.
Using the adjugate method will also raise an exception.
While the echelon method will return a matrix whose first half is not the identity.
We can programmatically check for this with the following code:
To generalize the previous code to any \(n \times n\) matrix, keep the first three arguments the same but replace 3 with \(n\text{.}\)
