Matrix inverse
It is seldom necessary to form the explicit inverse
of a matrix. A frequent misuse of inv
arises when
solving the system of linear equations Ax = b.
One way to solve the equation is with x = inv(A)*b
.
A better way, from the standpoint of both execution time and numerical
accuracy, is to use the matrix backslash operator x = A\b
.
This produces the solution using Gaussian elimination, without explicitly
forming the inverse. See mldivide
for
further information.
inv
performs an LU decomposition of the
input matrix (or an LDL decomposition if the input matrix is Hermitian).
It then uses the results to form a linear system whose solution is
the matrix inverse inv(X)
. For sparse inputs, inv(X)
creates
a sparse identity matrix and uses backslash, X\speye(size(X))
.