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} svd (@var{KP})
18 ## XXX: Write documentation
21 function [U, S, V] = svd (KP)
26 if (!isa (KP, "kronprod"))
27 error ("svd: input must be of class 'kronprod'");
30 ## XXX: I don't think this works properly for non-square A and B
33 ## Only singular values were requested
36 U = sort (kron (S_A, S_B), "descend");
38 ## The full SVD was requested
39 [U_A, S_A, V_A] = svd (KP.A);
40 [U_B, S_B, V_B] = svd (KP.B);
42 ## Compute and sort singular values
43 [sv, idx] = sort (kron (diag (S_A), diag (S_B)), "descend");
46 S = resize (diag (sv), [rows(KP), columns(KP)]);
47 #Pu = eye (rows (KP)) (idx, :);
48 U = kronprod (U_A, U_B, idx);
49 #Pv = eye (columns (KP)) (idx, :);
50 V = kronprod (V_A, V_B, idx);