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} mldivide (@var{M1}, @var{M2})
18 ## XXX: Write documentation
21 function retval = mldivide (M1, M2)
27 if (!ismatrix (M1) || !ismatrix (M2))
28 error ("mldivide: both input arguments must be matrices");
31 if (rows (M1) != rows (M2))
32 error ("mldivide: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
33 rows (M1), columns (M1), rows (M2), columns (M2));
36 ## Take action depending on types
37 M1_is_KP = isa (M1, "kronprod");
38 M2_is_KP = isa (M2, "kronprod");
40 if (M1_is_KP && M2_is_KP) # Left division of Kronecker Products
41 error ("mldividide: this part not yet implemented as I'm lazy...");
43 elseif (M1_is_KP) # Left division of Kronecker Product and Matrix
44 ## XXX: Does this give the same minimum-norm solution as when using
45 ## XXX: full (M1) \ M2
46 ## XXX: ? It is the same when M1 is invertible.
47 retval = zeros (columns (M1), columns (M2));
48 for n = 1:columns (M2)
49 M = reshape (M2 (:, n), [rows(M1.B), rows(M1.A)]);
50 retval (:, n) = vec ((M1.A \ (M1.B \ M)')');
53 elseif (M2_is_KP) # Left division of Matrix and Kronecker Product
54 error ("mldividide: this part not yet implemented as I'm lazy...");
57 error ("mldivide: internal error for 'kronprod'");