home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / specmat / hankel.m next >
Text File  |  1999-04-29  |  2KB  |  85 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: hankel (c, r)
  21. ##
  22. ## Return the Hankel matrix constructed given the first column
  23. ## c, and (optionally) the last row r.
  24. ##
  25. ## If the second argument is omitted, zeros are inserted below the main
  26. ## anti-diagonal.  If the last element of c is not the same as the first
  27. ## element of r, the last element of c is used.
  28. ##
  29. ## See also: vander, sylv_mat, hilb, invhilb, toeplitz
  30.  
  31. ## Author: jwe
  32.  
  33. function retval = hankel (c, r)
  34.  
  35.   if (nargin == 1)
  36.     r = zeros (size (c));
  37.   elseif (nargin != 2)
  38.     usage ("hankel (c, r)");
  39.   endif
  40.  
  41.   [c_nr, c_nc] = size (c);
  42.   [r_nr, r_nc] = size (r);
  43.  
  44.   if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1))
  45.     error ("hankel: expecting vector arguments");
  46.   endif
  47.  
  48.   if (nargin == 1)
  49.     r (1) = c (length (c));
  50.   endif
  51.  
  52.   if (c_nc != 1)
  53.     c = c.';
  54.   endif
  55.  
  56.   if (r_nr != 1)
  57.     r = r.';
  58.   endif
  59.  
  60.   nc = length (r);
  61.   nr = length (c);
  62.  
  63.   if (r (1) != c (nr))
  64.     warning ("hankel: column wins anti-diagonal conflict");
  65.   endif
  66.  
  67.   ## This should probably be done with the colon operator...
  68.  
  69.   retval = zeros (nr, nc);
  70.  
  71.   for i = 1:min (nr, nc)
  72.     retval (1:nr-i+1, i) = c (i:nr);
  73.   endfor
  74.  
  75.   tmp = 1;
  76.   if (nc <= nr)
  77.     tmp = nr - nc + 2;
  78.   endif
  79.  
  80.   for i = nr:-1:tmp
  81.     retval (i, 2+nr-i:nc) = r (2:nc-nr+i);
  82.   endfor
  83.  
  84. endfunction
  85.