inv

Inverse of a square matrix.

Category: Mathematics > Linear Algebra

Syntax

Y = inv(X)

Returns the matrix Y with X*Y = Y*X = I.

Description

A matrix has an inverse only when its determinant is nonzero. inv computes it from an LU factorization. For a nearly singular matrix the result can be inaccurate, and a warning reports a bad condition.

To solve A*x = b, write A\b instead of inv(A)*b: it is faster and more accurate, because it never forms the inverse.

Input arguments

X
Square matrix.

Output arguments

Y
Inverse of X. For a singular matrix a warning is printed and the result holds Inf.

Example

Regular and singular matrices

inv([1 2; 3 4])
inv([2 0; 0 4])
inv([1 2; 2 4])
Output
ans = 2×2

   -2.0000    1.0000
    1.5000   -0.5000
ans = 2×2

    0.5000         0
         0    0.2500
ans = 2×2

   Inf   Inf
   Inf   Inf
Warning: Matrix is singular to working precision.

See also

det mldivide pinv lu cond