]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/@kronprod/rdivide.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / @kronprod / rdivide.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} rdivide (@var{a}, @var{b})
18 ## XXX: Write help text.
19 ## @end deftypefn
20
21 function retval = rdivide (a, b)
22   ## Check input
23   if (nargin < 2)
24     print_usage ();
25   endif
26   
27   if (!ismatrix (a) || !ismatrix (a))
28     error ("rdivide: input arguments must be scalars or matrices");
29   endif
30   
31   if (!size_equal (a, b) || !isscalar (b))
32     error ("times: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
33            rows (a), columns (a), rows (b), columns (b));
34   endif
35
36   ## Take action depending on input
37   if (isscalar (a) && isa (b, "kronprod"))
38     retval = kronprod (a ./ b.A, 1 ./ b.B);
39   elseif (isa (a, "kronprod") && isscalar (b))
40     if (numel (a.A) < numel (a.B))
41       retval = kronprod (a.A ./ b, a.B);
42     else
43       retval = kronprod (a.A, a.B ./ b);
44     endif
45   elseif (isa (a, "kronprod") && isa (b, "kronprod"))
46     ## XXX: Can we do something smarter here?
47     retval = full (a) ./ full (b);
48   else
49     ## XXX: We should probably handle sparse cases and all sorts of other
50     ## situations better here
51     retval = full (a) ./ full (b);
52   endif
53 endfunction