Matrix Inverse
The inverse of a matrix A is denoted as A^-1. It is a unique matrix such that when it is multiplied by the original matrix A, the result is the identity matrix I. Mathematically, this is expressed as:
$$ AA^{-1} = A^{-1}A = I $$
Not all matrices have an inverse. Only square matrices (those with the same number of rows and columns) are eligible to have an inverse, and even then, some do not. A matrix has an inverse if and only if it is non-singular, i.e., its determinant is not zero.
Mathematical Formulation
Given a square matrix A of order n, the inverse A^-1 is calculated as:
$$ A^{-1} = \frac{1}{det(A)} adj(A) $$
where det(A) is the determinant of A and adj(A) is the adjugate of A.
The adjugate of A is the transpose of the cofactor matrix C of A. Each element c_ij of C is calculated as (-1)^(i+j) det(M_ij), where M_ij is the (i, j)th minor of A.
Using inverse matrix to solve matrix equations
We can solve a following matrix equation, using a matrix invers:
$$A\boldsymbol{x} = \boldsymbol{b}$$
Let's mutiply both sides by the inverse of the matrix $A$:
$$\implies A^{-1}A\boldsymbol{x} = A^{-1}\boldsymbol{b}$$
$$\implies I\boldsymbol{x} = A^{-1}\boldsymbol{b}$$
$$\implies \boldsymbol{x} = A^{-1}\boldsymbol{b}$$
Algorithm Steps
Implementation note: the formula above (cofactors and adjugate) is shown for theory and for small hand calculations. It is far too expensive and numerically poor for general use, so the code in this repository computes the inverse by Gauss-Jordan elimination with partial pivoting: it row-reduces the augmented matrix $[A \mid I]$ to $[I \mid A^{-1}]$ and raises an error if a pivot is (numerically) zero, i.e. $A$ is singular. The steps below describe the adjugate method.
Finding the inverse of a matrix with the adjugate formula is a multi-step process:
- Check if the matrix is invertible. A matrix is invertible if it is square (has the same number of rows and columns) and its determinant is not zero. If the matrix is not invertible, stop here, the matrix does not have an inverse.
- Calculate the matrix of minors. The minor of each element in the matrix is the determinant of the matrix formed by removing the row and column of that element from the original matrix.
- Form the matrix of cofactors. Multiply each minor by (-1)^(i+j), where i and j are the row and column numbers of each element.
- Calculate the adjugate of the matrix. The adjugate is simply the transpose of the cofactor matrix.
- Finally, the inverse of the original matrix is the adjugate divided by the determinant of the original matrix.
Example
Let's take a 2x2 matrix A as an example:
$$ A = \begin{bmatrix} 4 & 7 \\ 2 & 6\\ \end{bmatrix} $$
- First, check if the matrix is invertible. The determinant of A is (46 - 72) = 10, which is not zero, so the matrix is invertible.
- The minor of 4 is the determinant of the matrix that results from removing the row and column of 4 from A, which is just 6. Similarly, the minor of 7 is 2, the minor of 2 is 7, and the minor of 6 is 4.
- The cofactor matrix is obtained by multiplying each minor by (-1)^(i+j). The off-diagonal entries get a minus sign, so the cofactor matrix is $\begin{bmatrix} 6 & -2 \\ -7 & 4 \end{bmatrix}$.
- The adjugate of A is the transpose of the cofactor matrix, which is $\begin{bmatrix} 6 & -7 \\ -2 & 4 \end{bmatrix}$.
- The inverse of A is the adjugate divided by the determinant, resulting in:
$$ A^{-1} = \frac{1}{10} \begin{bmatrix} 6 & -7 \\ -2 & 4\\ \end{bmatrix} = \begin{bmatrix} 0.6 & -0.7 \\ -0.2 & 0.4\\ \end{bmatrix} $$
Advantages
- The inverse of a matrix provides an analytical solution for systems of linear equations of the form $A \mathbf{x} = \mathbf{b}$, where $\mathbf{x} = A^{-1} \mathbf{b}$, offering a direct approach when the inverse is available.
- Matrix inversion is a fundamental concept in linear algebra, with applications ranging from solving systems of equations to transformations in geometry, optimization problems, and control systems.
- It enables the characterization of matrix properties, such as determining whether a matrix is singular (non-invertible) and finding relationships in systems represented by matrices.
- Inverse matrices are used in statistical computations, such as calculating the covariance matrix in multivariate analysis and solving normal equations in least squares problems.
- The computation of $A^{-1}$ can be performed once and reused for multiple right-hand sides $\mathbf{b}$, making it useful in scenarios where multiple systems need solving with the same matrix $A$.
Limitations
- Not all matrices are invertible. A matrix must be square (having the same number of rows and columns) and non-singular (having a non-zero determinant) to possess an inverse.
- Computational cost is high for calculating matrix inverses directly. The process involves determinant calculations and can be computationally prohibitive for large matrices, with complexity on the order of $O(n^3)$ for typical methods like Gaussian elimination.
- Using the inverse to solve $A \mathbf{x} = \mathbf{b}$ is often less efficient and less numerically stable than solving the system directly with techniques like LU decomposition or iterative methods, especially for large or sparse systems.
- Small numerical errors in the computation of the inverse can magnify errors in the solution, particularly for ill-conditioned matrices, making direct inversion less desirable in sensitive applications.
- The process of inversion does not apply to non-square or singular matrices, and alternative approaches like pseudo-inverse computation or regularization methods must be employed for such cases.