home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / special-matrix / hankel.m next >
Encoding:
Text File  |  1999-11-21  |  2.5 KB  |  104 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} {} hankel (@var{c}, @var{r})
  22. ## Return the Hankel matrix constructed given the first column @var{c}, and
  23. ## (optionally) the last row @var{r}.  If the last element of @var{c} is
  24. ## not the same as the first element of @var{r}, the last element of
  25. ## @var{c} is used.  If the second argument is omitted, the last row is
  26. ## taken to be the same as the first column.
  27. ## 
  28. ## A Hankel matrix formed from an m-vector @var{c}, and an n-vector
  29. ## @var{r}, has the elements
  30. ## @iftex
  31. ## @tex
  32. ## $$
  33. ## H (i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr}
  34. ## $$
  35. ## @end tex
  36. ## @end iftex
  37. ## @ifinfo
  38. ## 
  39. ## @example
  40. ## @group
  41. ## H (i, j) = c (i+j-1),  i+j-1 <= m;
  42. ## H (i, j) = r (i+j-m),  otherwise
  43. ## @end group
  44. ## @end example
  45. ## @end ifinfo
  46. ## @end deftypefn
  47.  
  48. ## See also: vander, sylvester_matrix, hilb, invhilb, toeplitz
  49.  
  50. ## Author: jwe
  51.  
  52. function retval = hankel (c, r)
  53.  
  54.   if (nargin == 1)
  55.     r = zeros (size (c));
  56.   elseif (nargin != 2)
  57.     usage ("hankel (c, r)");
  58.   endif
  59.  
  60.   [c_nr, c_nc] = size (c);
  61.   [r_nr, r_nc] = size (r);
  62.  
  63.   if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1))
  64.     error ("hankel: expecting vector arguments");
  65.   endif
  66.  
  67.   if (nargin == 1)
  68.     r (1) = c (length (c));
  69.   endif
  70.  
  71.   if (c_nc != 1)
  72.     c = c.';
  73.   endif
  74.  
  75.   if (r_nr != 1)
  76.     r = r.';
  77.   endif
  78.  
  79.   nc = length (r);
  80.   nr = length (c);
  81.  
  82.   if (r (1) != c (nr))
  83.     warning ("hankel: column wins anti-diagonal conflict");
  84.   endif
  85.  
  86.   ## This should probably be done with the colon operator...
  87.  
  88.   retval = zeros (nr, nc);
  89.  
  90.   for i = 1:min (nr, nc)
  91.     retval (1:nr-i+1, i) = c (i:nr);
  92.   endfor
  93.  
  94.   tmp = 1;
  95.   if (nc <= nr)
  96.     tmp = nr - nc + 2;
  97.   endif
  98.  
  99.   for i = nr:-1:tmp
  100.     retval (i, 2+nr-i:nc) = r (2:nc-nr+i);
  101.   endfor
  102.  
  103. endfunction
  104.