Invert

Top  Previous  Next

INVERT is a utility that calculates the inverse of a matrix

It is used by using $Call or Execute on the command

 invert inputgdxfile indexofmatrix matrixtoinvert outputgdxfile resultantinverse

Where the parameters in this line are

 

inputgdxfile

Name of gdxfile sent to invert that has the matrix to be inverted

indexofmatrix

Name of set that defines row and column names of the matrix

matrixtoinvert

Name of the matrix to invert that must be in inputgdxfile

outputgdxfile

Name of gdxfile  that has the resultant inverse matrix

resultantinverse

Name to call the inverse in the gdx file outputgdxfile

 

Example inverseexample.gms

Set index /i1*i2/;

Table a(index,index) matrix to invert

             i1   i2

    i1       2     1

    i2       1     3;

parameter ainverse(index,index) matrix that was inverted;

execute_unload 'gdxforinverse.gdx' index,a;

execute 'invert gdxforinverse.gdx index a gdxfrominverse.gdx ainverse';

execute_load 'gdxfrominverse.gdx' , ainverse;

display a, ainverse;

 

Users are likely to be constrained by the assumption that the matrix has the same column and row indices.  Also having to define the GDX files every time may be inconvenient.  Consequently a routine (arealinverter.gms) was written that provides a wrapper around the inverse it is called using the sequence

$batinclude arealinverter  matrixtoinvert rowindex colindex resultantinverse

Where the parameters in this line are

 

matrixtoinvert

Name of the matrix to invert that is of dimension (rowindex,colindex)

rowindex

Name of set that is the row index for the matrix to invert

colindex

Name of set that is the column index for the matrix to invert

resultantinverse

Array to receive the inverse that must be predefined and of dimension (colindex,rowindex)

 

Internally this procedure generates a matrix of the form required by INVERT and handles the GDX files.

Note the inverse is of opposite dimension order as compared with original matrix.

Example inverseexample.gms and

Set j /j1*j2/;

Table a2(index,j) second matrix to invert

             j1   j2

    i1       4     2

    i2       1     7;

Parameter a2inverse(j,index) inverse of second matrix

$batinclude arealinverter a2 index j a2inverse

display a2,a2inverse;