|
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
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
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;
|