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} det (@var{KP})
18 ## Compute the determinant of a Kronecker product.
20 ## If @var{KP} is the Kronecker product of the @var{n}-by-@var{n} matrix @var{A}
21 ## and the @var{q}-by-@var{q} matrix @var{B}, then the determinant is computed
25 ## det (@var{A})^q * det (@var{B})^n
28 ## If @var{KP} is not a Kronecker product of square matrices the determinant is
29 ## computed by forming the full matrix and then computing the determinant.
30 ## @seealso{det, @@kronprod/trace, @@kronprod/rank, @@kronprod/full}
33 function retval = det (KP)
39 if (!isa (KP, "kronprod"))
40 error ("det: input argument must be of class 'kronprod'");
44 error ("det: argument must be a square matrix");
50 if (n == m && q == r) # A and B are both square
51 retval = (det (KP.A)^q) * (det (KP.B)^n);
52 elseif (n*q == m*r) # kron (A, B) is square
53 ## XXX: Can we do something smarter here? We should be able to use the SVD...
54 retval = det (full (KP));