Eigenvector

Table of Contents

Note
This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools.

This calculates the Eigenvalues and Eigenvectors of a symmetric positive definite matrix. The matrices A and AVec are indexed over (i,i). AVal(i) is indexed over i.

Usage

Command line:

gamstool [linalg.]Eigenvector i A AVal AVec gdxIn=fileIn.gdx gdxOut=fileOut.gdx

Compile time:

$callTool [linalg.]Eigenvector i A AVal AVec [gdxIn=fileIn.gdx] [gdxOut=fileOut.gdx]

Execution time:

executeTool '[linalg.]Eigenvector i A AVal AVec [gdxIn=fileIn.gdx] [gdxOut=fileOut.gdx]';

Where:

Argument Description
i Name of set used in matrix i(*).
A Name of two-dimensional matrix parameter A(i,i).
AVal Name of one-dimensional parameter to store the Eigenvalues AVal(i).
AVec Name of two-dimensional matrix to store the Eigenvectors AVec(i,i).

The following parameters are available:

Parameter Description
gdxIn=fileIn.gdx Name of GDX file that contains symbols i and A. Mandatory if called from the command line, otherwise optional.
gdxOut=fileOut.gdx Name of GDX file that contains symbols AVal and AVec after execution. Mandatory if called from the command line, otherwise optional.


Example

Set i / i1*i5 /;

Alias (i,j);

Table a(i,j)
        i1   i2   i3   i4   i5
   i1    1    2    4    7   11
   i2    2    3    5    8   12
   i3    4    5    6    9   13
   i4    7    8    9   10   14
   i5   11   12   13   14   15
;

Table expected(i,*)
              val          i1          i2          i3          i4          i5
   i1   -8.464425   0.5550905  -0.2642556   0.2892854   0.6748602   0.2879604
   i2   -1.116317   0.4820641  -0.2581518   0.2196341  -0.7349311   0.3355726
   i3   -0.512109   0.2865066   0.2159261  -0.8437897   0.0411896   0.3970041
   i4   -0.027481  -0.0992784   0.7711236   0.3943678   0.0055409   0.4898525
   i5   45.120332  -0.6062562  -0.4714561  -0.0238286   0.0520829   0.6378888
;

Parameter
   eval(i)   'Eigenvalues'
   evec(i,j) 'Eigenvectors';

execute_unload 'a.gdx', i, a;
executeTool.checkErrorLevel 'linalg.eigenvector i a eval evec gdxin=a.gdx gdxout=b.gdx';
execute_load 'b.gdx', eval, evec;
evec(i,j)$(evec('i1','i1')<0) = -evec(i,j);
abort$(sum(i$(abs(eval(i)-expected(i,'val'))>1e-4),1)) 'Wrong Eigenvalue', eval, expected;
abort$(sum((i,j)$(abs(evec(i,j)-expected(i,j))>1e-4),1)) 'Wrong Eigenvector', evec, expected;

option clear=eval, clear=evec;
executeTool.checkErrorLevel 'linalg.eigenvector i a eval evec';
evec(i,j)$(evec('i1','i1')<0) = -evec(i,j);
abort$(sum(i$(abs(eval(i)-expected(i,'val'))>1e-4),1)) 'Wrong Eigenvalue', eval, expected;
abort$(sum((i,j)$(abs(evec(i,j)-expected(i,j))>1e-4),1)) 'Wrong Eigenvector', evec, expected;