Mercurial > octave-nkf
comparison scripts/linear-algebra/kron.m @ 75:505c8b681f66
[project @ 1993-08-30 15:11:21 by jwe]
Initial revision
author | jwe |
---|---|
date | Mon, 30 Aug 1993 15:11:21 +0000 |
parents | |
children | 16a24e76d6e0 |
comparison
equal
deleted
inserted
replaced
74:1b1a6414f9ed | 75:505c8b681f66 |
---|---|
1 function x = kron (a, b) | |
2 | |
3 # Usage: x = kron (a, b) | |
4 # | |
5 # Form the Kronecker product of two matrices, defined block by block | |
6 # as | |
7 # | |
8 # x = [a(i,j) b] | |
9 | |
10 # Written by A. S. Hodel (scotte@eng.auburn.edu) August 1993. | |
11 | |
12 if (nargin == 2) | |
13 | |
14 [m, n] = size (b); | |
15 [ma, na] = size (a); | |
16 | |
17 # Do 1st column. | |
18 | |
19 x = a (1, 1) * b; | |
20 for ii = 2:ma | |
21 x = [x; a (ii, 1)*b]; | |
22 endfor | |
23 | |
24 # Do remaining columns. | |
25 | |
26 for jj = 2:na | |
27 tmp = a (1, jj)*b; | |
28 for ii = 2:ma | |
29 tmp = [tmp; a (ii, jj)*b]; | |
30 endfor | |
31 x = [x, tmp]; | |
32 endfor | |
33 | |
34 else | |
35 error ("usage: kron (a, b)"); | |
36 endif | |
37 | |
38 endfunction |