]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/@kronprod/det.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / @kronprod / det.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} det (@var{KP})
18 ## Compute the determinant of a Kronecker product.
19 ##
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
22 ## as
23 ##
24 ## @example
25 ## det (@var{A})^q * det (@var{B})^n
26 ## @end example
27 ##
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}
31 ## @end deftypefn
32
33 function retval = det (KP)
34   ## Check input
35   if (nargin != 1)
36     print_usage ();
37   endif
38   
39   if (!isa (KP, "kronprod"))
40     error ("det: input argument must be of class 'kronprod'");
41   endif
42
43   if (!issquare (KP))
44     error ("det: argument must be a square matrix");
45   endif
46
47   ## Take action
48   [n, m] = size (KP.A);
49   [q, r] = size (KP.B);
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));
55   endif
56 endfunction