home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / linear-algebra / kron.m < prev    next >
Text File  |  1998-11-10  |  1KB  |  62 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  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.
  19.  
  20. ## Usage: x = kron (a, b)
  21. ##
  22. ## Form the Kronecker product of two matrices, defined block by block
  23. ## as
  24. ##
  25. ##   x = [a(i,j) b]
  26.  
  27. ## Author: A. S. Hodel <scotte@eng.auburn.edu>
  28. ## Created: August 1993
  29. ## Adapted-By: jwe
  30.  
  31. function x = kron (a, b)
  32.  
  33.   if (nargin == 2)
  34.  
  35.     [m, n] = size (b);
  36.     [ma, na] = size (a);
  37.  
  38.     ## Do 1st column.
  39.  
  40.     x = a (1, 1) * b;
  41.     for ii = 2:ma
  42.       tmp = a (ii, 1) * b;
  43.       x = [x; tmp];
  44.     endfor
  45.  
  46.     ## Do remaining columns.
  47.  
  48.     for jj = 2:na
  49.       tmp = a (1, jj) * b;
  50.       for ii = 2:ma
  51.         pmt = a (ii, jj) * b;
  52.     tmp = [tmp; pmt];
  53.       endfor
  54.       x = [x, tmp];
  55.     endfor
  56.  
  57.   else
  58.     usage ("kron (a, b)");
  59.   endif
  60.  
  61. endfunction
  62.