home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / specmat / toeplitz.m < prev    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: toeplitz (c, r)
  21. ##
  22. ## Return the Toeplitz matrix constructed given the first column
  23. ## c, and (optionally) the first row r.
  24. ##
  25. ## If the second argument is omitted, the first row is taken to be the
  26. ## same as the first column.  If the first element of c is not the same
  27. ## as the first element of r, the first element of c is used.
  28. ##
  29. ## See also: hankel, vander, sylv_mat, hilb, invhib
  30.  
  31. ## Author: jwe
  32.  
  33. function retval = toeplitz (c, r)
  34.  
  35.   if (nargin == 1)
  36.     r = c;
  37.   elseif (nargin != 2)
  38.     usage ("toeplitz (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 ("toeplitz: expecting vector arguments");
  46.   endif
  47.  
  48.   if (c_nc != 1)
  49.     c = c.';
  50.   endif
  51.  
  52.   if (r_nr != 1)
  53.     r = r.';
  54.   endif
  55.  
  56.   if (r (1) != c (1))
  57.     warning ("toeplitz: column wins diagonal conflict");
  58.   endif
  59.  
  60.   ## If we have a single complex argument, we want to return a
  61.   ## Hermitian-symmetric matrix (actually, this will really only be
  62.   ## Hermitian-symmetric if the first element of the vector is real).
  63.  
  64.   if (nargin == 1)
  65.     c = conj (c);
  66.     c(1) = conj (c(1));
  67.   endif
  68.  
  69.   ## This should probably be done with the colon operator...
  70.  
  71.   nc = length (r);
  72.   nr = length (c);
  73.  
  74.   retval = zeros (nr, nc);
  75.  
  76.   for i = 1:min (nc, nr)
  77.     retval (i:nr, i) = c (1:nr-i+1);
  78.   endfor
  79.  
  80.   for i = 1:min (nr, nc-1)
  81.     retval (i, i+1:nc) = r (2:nc-i+1);
  82.   endfor
  83.  
  84. endfunction
  85.