Language Reference

INV Function

computes the matrix inverse

INV( matrix)

where matrix is a square nonsingular matrix.

The INV function produces a matrix that is the inverse of matrix, which must be square and nonsingular.

For g = {inv}(a) the inverse has the properties
{ga}= {ag} = {identity}
To solve a system of linear equations {ax}=b for x, you can use the following statement:
  
    x=inv(a)*b;
 
Note that the SOLVE function is more accurate and efficient for this task.

An example of valid usage is as follows:
  
    A = {0 0 1 0 1, 
         1 0 0 1 0, 
         0 1 1 0 1, 
         1 0 0 0 1, 
         0 1 0 1 0}; 
  
     b = {9,4,10,8,2}; 
  
     /* find inverse and solve linear system */ 
     Ainv = inv(A); 
     x1 = Ainv*b; 
  
     /* solve by using a more efficient algorithm */ 
     x2 = solve(A,b);
 
These statements produce the following output:
  
                      X1        X2 
  
                       3         3 
                       1         1 
                       4         4 
                       1         1 
                       5         5
 


The INV function uses an LU decomposition followed by back substitution to solve for the inverse, as described in Forsythe, Malcolm, and Moler (1967).

The INV function (as well as the DET and SOLVE functions) uses the following criterion to decide whether the input matrix, {a}= [a_{ij}]_{i,j=1, ... ,n}, is singular:
{sing} = 100 x {macheps} x    \max_{1 \leq i,j \leq n} | a_{ij}|
where MACHEPS is the relative machine precision.

All matrix elements less than or equal to sing are now considered rounding errors of the largest matrix elements, so they are taken to be zero. For example, if a diagonal or triangular coefficient matrix has a diagonal value less than or equal to sing, the matrix is considered singular by the DET, INV, and SOLVE functions.

Previously, a much smaller singularity criterion was used, which caused algebraic operations to be performed on values that were essentially floating-point error. This occasionally yielded numerically unstable results. The new criterion is much more conservative, and it generates far fewer erroneous results. In some cases, you might need to scale the data to avoid singular matrices. If you think the new criterion is too strong, do the following:

If a is an n x n matrix, the INV function allocates an n x n matrix in order to return the inverse. It also temporarily allocates an n^2 array in order to compute the inverse.

Previous Page | Next Page | Top of Page