Lindo Systems

! Compute eigenvalues and eigenvectors; !(EigenExample.lng);
! Keywords: Eigenvalue, Eigenvector, Matt Damon, PCA, Population growth, 
            Principal Component Analysis, Good Will Hunting;
sets:
  item: evalr, evali;
  ixi( item, item): a, evecr, eveci;
endsets

data:
! Case:  Finding the eigenvalues of these two matrices was
  listed as an exercise on the board to be solved by 
  Matt Damon in the  movie "Good Will Hunting";
! item = 1..3;
!  A =
      1  1  0
      1  1 -2
      2  1  0;
!  A = 
      2 -1 -1
     -1  2 -1
     -1 -1  2;
   ! A Covariance matrix;
! item =  ATT       GMC       USX;
!  A = 
    .01080754 .01240721 .01307513
    .01240721 .05839170 .05542639
    .01307513 .05542639 .09422681;

   ! A population change matrix;
 item = Bunnies Clover  Foxes;
  A = 
        0.612   2.291  -1.200
       -0.295   2.321  -0.560
        0.500  -0.050   0.110 ;
enddata

calc:
 ! Get the eigenvalues(real part),
   eigenvectors(real part), eigenvalues(imaginary part),
   and eigenvectors(imaginary part);
  evalr, evecr, evali, eveci = @eigen(a);
endcalc

data:
   @text() = '';
   @text() = 'eigenvalues, real part:';
   @text() = @table( evalr);
   @text() = '';
   @text() = 'eigenvectors(columns), real part:';
   @text() = @table( evecr);
   @text() = '';
   @text() = 'eigenvalues, imaginary part:';
   @text() = @table( evali);
   @text() = '';
   @text() = 'eigenvectors(columns), imaginary part:';
   @text() = @table( eveci);
enddata