invert2.gms : Matrix inversion via Matlab

Description

Example use of Matlab to duplicate the functionality of the GAMS
invert utility.  Obviously, you can extend this to do all sorts of
things that Matlab supports, e.g. determinants, singular values,
condition number, etc.  If getting started with data interchange
between GAMS and Matlab is a roadblock for you, this example should
help you push through.

Intended use: call Matlab in batch-mode

Contributor: Steve


Category : GAMS Data Utilities library


Main file : invert2.gms   includes :  invert2.gms  invert2.m

$title Matrix inversion via Matlab

$ontext
Example use of Matlab to duplicate the functionality of the GAMS
invert utility.  Obviously, you can extend this to do all sorts of
things that Matlab supports, e.g. determinants, singular values,
condition number, etc.  If getting started with data interchange
between GAMS and Matlab is a roadblock for you, this example should
help you push through.

Intended use: call Matlab in batch-mode

Contributor: Steve
$offtext
$ondollar

$if NOT exist invert01.gms $call testlib invert01
$if NOT exist invert01.gms $abort Test model invert01.gms does not exist: why not??

$call rm -f a.gdx b.gdx c.gdx

$call gams invert01
$if errorlevel 1     $abort Invert01 test failed
$if NOT exist a.gdx  $abort Invert01 test did not produce a.gdx
$if NOT exist b.gdx  $abort Invert01 test did not produce b.gdx


* OK so far.  Now, starting with matrix A in a.gdx, produce A-inverse
* and compare to the inverse matrix inva in b.gdx

* this calls Matlab to do inversion
$set WAIT
$if not %system.filesys% == UNIX $set WAIT /wait
$call =matlab -r invert2 -logfile invert2.mlog -nosplash -nodisplay -nojvm %WAIT%

$if NOT exist c.gdx  $abort Matlab script did not produce c.gdx

$call gdxdiff b.gdx c.gdx releps=1e-12
$if errorlevel 1     $abort The two inverses are not equal within tolerance

$log All done.  The two methods produce the same inverse of A