eigvec02.gms : Test eigenvector/eigenvalue utilities

Description

Eigenvalue/vector test.
Construct A to have known eigenvalues/vectors: A X = X lam

A = 2 1   X = 1  1   lam =  1
    1 2      -1  1            3

Contributor: Steve Dirkse, October 2008


Small Model of Type : GAMS


Category : GAMS Test library


Main file : eigvec02.gms

$title Test eigenvector/eigenvalue utilities (EIGVEC02,SEQ=413)

$onText
Eigenvalue/vector test.
Construct A to have known eigenvalues/vectors: A X = X lam

A = 2 1   X = 1  1   lam =  1
    1 2      -1  1            3

Contributor: Steve Dirkse, October 2008
$offText

set I / i1 * i2 /;
alias (I,J,K);

parameters
  A(I,J)     'constructed to have known eigenvectors/values'
  X0(I,J)    'known eigenvectors'
  X(I,J)
  lam0(I)    'known eigenvalues' /
    i1       1
    i2       3
  /,
  lam(I)
  s(J)       'scales for the eigenvector comparison'
  ;

table A(I,J)
      i1        i2
i1    2         1
i2    1         2   ;

table X0(I,J)
      i1        i2
i1     1         1
i2    -1         1 ;


executeTool.checkErrorLevel 'linalg.eigenvalue I A lam';
* Symbol lam has been loaded implicitly by executeTool. The compiler instruction
* in the next line supresses errors about presumably unassigned symbols
$onImplicitAssign

abort$[smax{I, abs(lam(I)-lam0(I))} > 1e-8] 'Bad eigenvalues in lam (1)';

executeTool.checkErrorLevel 'linalg.eigenvector I A lam X';
abort$[smax{I, abs(lam(I)-lam0(I))} > 1e-8] 'Bad eigenvalues in lam (2)';
s(J) = X0('i1',J) / X('i1',J);
X(I,J) = X(I,J) * s(J);
abort$[smax{(I,J), abs(X(I,J)-X0(I,J))} > 1e-8] 'Bad eigenvectors in X';