Matrix inverse

Syntax: x = INVERSE(m)

The function INVERSE(m) returns the inverse of the matrix m, which must be a square matrix. The output is a matrix with the same shape as the argument. The answer can be checked by using the inner product operator, for example:

 invm=INVERSE(m) ! find the inverse of m
 =m<>invm        ! this should be close to the identity matrix
 

Method

Suppose that the matrix A has n rows and n columns. Let X represent the inverse of A, and let I be the identity matrix:

The LU decomposition method is used for finding the inverse matrix X. Write A as the product of two matrices: A = L<>U where L is lower triangular and U is upper triangular. A lower triangular matrix has elements only on the diagonal and below, while an upper triangular matrix has elements only on the diagonal and above. This decomposition is used to solve n sets of n linear equations. The matrix subscript *,j represents the entire jth column of that matrix.

Solve for the y vectors, there will be n of them, such that L<>y = I*,j and then solve for the jth column of X:

U<>X*,j = y  for each  j=1,2,...,n

Since L and U are triangular

and