2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
3372
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} kron (@var{a}, @var{b}) |
|
22 ## Form the kronecker product of two matrices, defined block by block as |
3426
|
23 ## |
3372
|
24 ## @example |
|
25 ## x = [a(i, j) b] |
|
26 ## @end example |
3426
|
27 ## |
3372
|
28 ## For example, |
3426
|
29 ## |
3372
|
30 ## @example |
|
31 ## @group |
|
32 ## kron (1:4, ones (3, 1)) |
|
33 ## @result{} 1 2 3 4 |
|
34 ## 1 2 3 4 |
|
35 ## 1 2 3 4 |
|
36 ## @end group |
|
37 ## @end example |
|
38 ## @end deftypefn |
75
|
39 |
2312
|
40 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
|
41 ## Created: August 1993 |
|
42 ## Adapted-By: jwe |
75
|
43 |
2312
|
44 function x = kron (a, b) |
75
|
45 |
|
46 if (nargin == 2) |
|
47 |
|
48 [m, n] = size (b); |
|
49 [ma, na] = size (a); |
|
50 |
3426
|
51 x = zeros (ma*m, na*n); |
3250
|
52 i_vec = 1:m; |
|
53 j_vec = 1:n; |
75
|
54 |
3250
|
55 for jj = 1:na |
|
56 for ii = 1:ma |
3426
|
57 x(i_vec+(ii-1)*m,j_vec) = a(ii,jj) * b; |
75
|
58 endfor |
3291
|
59 j_vec = j_vec + n; |
75
|
60 endfor |
3426
|
61 |
75
|
62 else |
904
|
63 usage ("kron (a, b)"); |
75
|
64 endif |
|
65 |
|
66 endfunction |