Calculate the inverse of a square matrix used in linear algebra operations.
The inverse of a 2×2 matrix [[a,b],[c,d]] is (1/det) × [[d,−b],[−c,a]] where det = ad − bc. A matrix is invertible only if its determinant is non-zero. Matrix inversion is used in solving linear systems, computing covariance matrices, and certain optimization algorithms in ML.
2×2 Inverse
A^(-1) = (1/(ad-bc)) * [[d, -b], [-c, a]]
Direct inversion is numerically unstable and O(n³). In ML, solving Ax=b via LU or Cholesky decomposition is preferred, and most optimization algorithms use iterative methods instead of computing inverses.
A singular (non-invertible) matrix has linearly dependent rows/columns, indicating redundant features. This can cause issues in algorithms like linear regression if the feature matrix is rank-deficient.