%mathpiper,def="EigenVectors"

EigenVectors(_matrix,_eigenvalues) <--
[
  Local(result,n);
/*  eigenvalues:=N(Eval(eigenvalues));  */
  n:=Length(eigenvalues);
  result:={};
  ForEach(e,eigenvalues)
  [
    Local(possible);
/* Echo({"1...",result}); */
    possible:=OldSolve(matrix*MakeVector(k,n)==e*MakeVector(k,n),MakeVector(k,n))[1];
/* Echo({"2..."}); */
/* Echo({"2..."}); */

    If(Not(IsZeroVector(possible)),
      DestructiveAppend(result,possible)
      );
/* Echo({"3..."}); */
  ];
  result;
];

%/mathpiper



%mathpiper_docs,name="EigenVectors",categories="User Functions;Linear Algebra"
*CMD EigenVectors --- get eigenvectors of a matrix
*STD
*CALL
	EigenVectors(A,eigenvalues)

*PARMS

{matrix} -- a square matrix

{eigenvalues} -- list of eigenvalues as returned by {EigenValues}

*DESC

{EigenVectors} returns a list of the eigenvectors of a matrix.
It uses the eigenvalues and the matrix to set up n equations with
n unknowns for each eigenvalue, and then calls {Solve} to determine
the values of each vector.

*E.G.

In> M:={{1,2},{2,1}}
Result: {{1,2},{2,1}};
In> e:=EigenValues(M)
Result: {3,-1};
In> EigenVectors(M,e)
Result: {{-ki2/ -1,ki2},{-ki2,ki2}};

*SEE EigenValues, CharacteristicEquation
%/mathpiper_docs