1. Home
  2. GINVERSE procedure

GINVERSE procedure

Calculates the generalized inverse of a matrix (S.K. Haywood).


PRINT = string token Printed output from the procedure (inverse); default *, i.e. no printing
METHOD = string token Method to be used to invert symmetric matrices (svd, lrv); default lrv
TOLERANCE = scalar How close a number must be be to zero before it is recognised as zero; default 1.0-6


INMATRIX = matrices The matrix whose inverse is to be calculated
INVERSE = matrices Matrix to save the generalized inverse


GINVERSE calculates generalized inverses. The method of inversion depends on the type of the matrix to be inverted. Ordinary (square or rectangular) matrices are inverted using the singular value decomposition. This method can also be used for symmetric matrices, by setting option METHOD=svd; however, by default, these are inverted using an eigenvalue (lrv) decomposition. For a diagonal matrix, the inverse is calculated by taking the reciprocal of each individual value on the diagonal. The tolerance for zero, to be used in the calculations, can be set using the TOLERANCE option.

The inverse can be saved using the INVERSE parameter; its type and dimensions will be defined automatically if it has not been declared in advance. The inverse can also be printed, by setting option PRINT=inverse.



GINVERSE inverts a matrix structure by performing an singular value decomposition to represent the input matrix as

left-matrix *+ diagonal-matrix *+ right-matrix.

In the case of a square matrix both left- and right-matrices are orthogonal while, for a non-square matrix, one of the left- or the right-matrices is orthogonal (which one depending on the dimensions of the input matrix), and the other one is orthonormal. The three matrices are inverted: the diagonal matrix by taking each non-zero element and calculating the inverse of that value, the left- and right-matrices by transposition. The order of the three matrices is then reversed, and they are multiplied together to form the generalized inverse of the original matrix.

A symmetric matrix is inverted in a similar way except that, by default, the matrix is decomposed using an eigenvalue decomposition.

A diagonal matrix is inverted by taking the reciprocal of each non-zero element down the diagonal.

For further details, see Graybill (1969) pages 96-103.


Graybill, A.F. (1969). Introduction to Matrices with Applications in Statistics. Colorado State University, Fort Collins, Colorado.

See also

Directive: CALCULATE.

Function: GINVERSE .


         !t('Calculate and print the inverse of a 3x4 matrix,',\
         'save the inverse in the 4x3 matrix InvMat1;'); STYLE=meta,plain
MATRIX   [ROWS=3; COLUMNS=4; VALUES= 1, 3, 9, 5,\
                                     7, 8, 4, 1,\
                                     0,10, 5, 3] Mat1
GINVERSE [PRINT=inverse] Mat1; INVERSE=InvMat1
CAPTION  !t('calculate the inverse of a 3x3 symmetric matrix',\
         'using the TOLERANCE option to set the sensitivity to zero',\
         'and saving the inverse in the symmetric matrix InvSym1.')
SYMMETRICMATRIX [ROWS=3; VALUES=1,20,3,15,17,2] Sym1
PRINT    InvSym1
Updated on March 7, 2019

Was this article helpful?