$title Matrix inversion via R
$ontext
Example use of R to duplicate the functionality of the GAMS invert
utility. Obviously, you can extend this to do all sorts of things
that R supports, e.g. determinants, singular values, condition number,
etc. If getting started with data interchange between GAMS and R is a
roadblock for you, this example should help you push through.
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 the R script to do inversion
$call Rscript invert1.r %gams.sysdir%
$if NOT exist c.gdx $abort R 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