1 ## Copyright (C) 2010 Soren Hauberg
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3, or (at your option)
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this file. If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{lambda} =} eig (@var{KP})
18 ## @deftypefnx{Function File} {[var{V}, @var{lambda}] =} eig (@var{KP})
19 ## XXX: Write help text
20 ## @seealso{eig, @kronprod/svd}
23 function [V, lambda] = eig (KP, A)
24 ## XXX: This implementation provides a different permutation of eigenvalues and
25 ## eigenvectors compared to 'eig (full (KP))'
28 if (nargin == 0 || nargin > 2)
32 if (!isa (KP, "kronprod"))
33 error ("eig: first input argument must be of class 'kronprod'");
37 error ("eig: first input must be a square matrix");
43 ## Only eigenvalues were requested
44 if (issquare (KP.A) && issquare (KP.B))
45 lambda_A = eig (KP.A);
46 lambda_B = eig (KP.B);
47 V = kronprod (lambda_A, lambda_B);
49 ## We should be able to do this using SVD
50 error ("eig not implemented (yet) for Kronecker products of non-square matrices");
54 ## Both eigenvectors and eigenvalues were requested
55 if (issquare (KP.A) && issquare (KP.B))
56 [V_A, lambda_A] = eig (KP.A);
57 [V_B, lambda_B] = eig (KP.B);
58 V = kronprod (V_A, V_B);
59 lambda = kronprod (lambda_A, lambda_B);
61 ## We should be able to do this using SVD
62 error ("eig not implemented (yet) for Kronecker products of non-square matrices");
67 ## Solve generalised eigenvalue problem
68 ## XXX: Is there a fancy way of doing this?
69 [V, lambda] = eig (full (KP), full (A));