]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/@kronprod/not_done/eig.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / @kronprod / not_done / eig.m
1 ## Copyright (C) 2010  Soren Hauberg
2 ## 
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)
6 ## any later version.
7 ## 
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. 
12 ## 
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/>.
15
16 ## -*- texinfo -*-
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}
21 ## @end deftypefn
22
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))'
26
27   ## Check input
28   if (nargin == 0 || nargin > 2)
29     print_usage ();
30   endif
31   
32   if (!isa (KP, "kronprod"))
33     error ("eig: first input argument must be of class 'kronprod'");
34   endif
35   
36   if (!issquare (KP))
37     error ("eig: first input must be a square matrix");
38   endif
39   
40   ## Take action
41   if (nargin == 1)
42     if (nargout <= 1)
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);
48       else
49         ## We should be able to do this using SVD
50         error ("eig not implemented (yet) for Kronecker products of non-square matrices");
51       endif
52
53     elseif (nargout == 2)
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);
60       else
61         ## We should be able to do this using SVD
62         error ("eig not implemented (yet) for Kronecker products of non-square matrices");
63       endif
64     endif
65     
66   elseif (nargin == 2)
67     ## Solve generalised eigenvalue problem
68     ## XXX: Is there a fancy way of doing this?
69     [V, lambda] = eig (full (KP), full (A));
70   endif
71 endfunction