]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/@kronprod/plus.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / @kronprod / plus.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} plus (@var{a}, @var{a})
18 ## Return the sum of a Kronecker product and another matrix. This is performed
19 ## by forming the full matrix of both inputs and is as such a potential expensive
20 ## operation.
21 ## @seealso{plus, @@kronprod/minus}
22 ## @end deftypefn
23
24 function retval = plus (M1, M2)
25   if (nargin == 0 || nargin > 2)
26     print_usage ();
27   elseif (nargin == 1)
28     ## This seems to be the behaviour for the built-in types so we copy that
29     retval = M1;
30     return;
31   endif
32   
33   if (!ismatrix (M1) || !ismatrix (M2))
34     error ("plus: input arguments must be matrics");
35   endif
36   
37   if (!size_equal (M1, M2))
38     error ("plus: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
39            rows (M1), columns (M1), rows (M2), columns (M2));
40   endif
41   
42   ## XXX: Can we do something smarter here?
43   if (issparse (M1))
44     M1 = sparse (M1);
45   else
46     M1 = full (M1);
47   endif
48   
49   if (issparse (M2))
50     M2 = sparse (M2);
51   else
52     M2 = full (M2);
53   endif
54   
55   retval = M1 + M2;
56 endfunction