Description
Test the invert utility: 1. write a square matrix to a GDX file 2. call 'invert' (an external program) to do the inversion 3. read in the invert from a second GDX file 4. test that A * A-inv = I Contributor: Erwin Kalvelagen and Steve Dirkse, July 2008.
Small Model of Type : GAMS
Category : GAMS Test library
Main file : invert01.gms
$title 'Test invert utility' (INVERT01,SEQ=391)
$onText
Test the invert utility:
1. write a square matrix to a GDX file
2. call 'invert' (an external program) to do the inversion
3. read in the invert from a second GDX file
4. test that A * A-inv = I
Contributor: Erwin Kalvelagen and Steve Dirkse, July 2008.
$offText
* Introduce a set that leaves holes in the uel sequence of i and does not start at 1
set offset / x1*x5,i1,x6*x10,i2,x11*x15,i3,x16*x20/;
set i /i1*i3 /;
alias (i,j,k);
table a(i,j) 'original matrix'
i1 i2 i3
i1 1 2 3
i2 1 3 4
i3 1 4 3
;
parameter
inva(i,j) 'inverse of a'
chk(i,j) 'check the product a * inva'
;
execute_unload 'a.gdx',i,a;
executeTool.checkErrorLevel 'linalg.invert i a inva -gdxIn=a.gdx -gdxOut=b.gdx';
execute_load 'b.gdx',inva;
chk(i,j) = sum{k, a(i,k)*inva(k,j)};
chk(i,j) = round(chk(i,j),15);
display a,inva,chk;
chk(i,i) = chk(i,i) - 1;
abort$[card(chk)] 'a * ainv <> identity';
executeTool.checkErrorLevel 'linalg.invert i a inva';
chk(i,j) = sum{k, a(i,k)*inva(k,j)};
chk(i,j) = round(chk(i,j),15);
display a,inva,chk;
chk(i,i) = chk(i,i) - 1;
abort$[card(chk)] 'a * ainv <> identity';