home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / la / kron.m < prev    next >
Text File  |  1999-12-24  |  2KB  |  67 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. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} kron (@var{a}, @var{b})
  22. ## Form the kronecker product of two matrices, defined block by block as
  23. ## 
  24. ## @example
  25. ## x = [a(i, j) b]
  26. ## @end example
  27. ## 
  28. ## For example,
  29. ## 
  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
  39.  
  40. ## Author: A. S. Hodel <scotte@eng.auburn.edu>
  41. ## Created: August 1993
  42. ## Adapted-By: jwe
  43.  
  44. function x = kron (a, b)
  45.  
  46.   if (nargin == 2)
  47.  
  48.     [m, n] = size (b);
  49.     [ma, na] = size (a);
  50.  
  51.     x = zeros (ma*m, na*n);    
  52.     i_vec = 1:m;
  53.     j_vec = 1:n;
  54.  
  55.     for jj = 1:na
  56.       for ii = 1:ma
  57.     x(i_vec+(ii-1)*m,j_vec) = a(ii,jj) * b;
  58.       endfor
  59.       j_vec = j_vec + n;
  60.     endfor
  61.     
  62.   else
  63.     usage ("kron (a, b)");
  64.   endif
  65.  
  66. endfunction
  67.