home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / special-matrix / vander.m < prev   
Encoding:
Text File  |  1999-11-21  |  2.1 KB  |  81 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} {} vander (@var{c})
  22. ## Return the Vandermonde matrix whose next to last column is @var{c}.
  23. ## 
  24. ## A Vandermonde matrix has the form
  25. ## @iftex
  26. ## @tex
  27. ## $$
  28. ## \left[\matrix{c_0^n  & \ldots & c_0^2  & c_0    & 1\cr
  29. ##               c_1^n  & \ldots & c_1^2  & c_1    & 1\cr
  30. ##               \vdots &        & \vdots & \vdots & \vdots\cr
  31. ##               c_n^n  & \ldots & c_n^2  & c_n    & 1}\right].
  32. ## $$
  33. ## @end tex
  34. ## @end iftex
  35. ## @ifinfo
  36. ## 
  37. ## @example
  38. ## @group
  39. ## c(0)^n ... c(0)^2  c(0)  1
  40. ## c(1)^n ... c(1)^2  c(1)  1
  41. ##  .           .      .    .
  42. ##  .           .      .    .
  43. ##  .           .      .    .
  44. ##                  
  45. ## c(n)^n ... c(n)^2  c(n)  1
  46. ## @end group
  47. ## @end example
  48. ## @end ifinfo
  49. ## @end deftypefn
  50.  
  51. ## See also: hankel, sylvester_matrix, hilb, invhilb, toeplitz
  52.  
  53. ## Author: jwe
  54.  
  55. function retval = vander (c)
  56.  
  57.   if (nargin != 1)
  58.     usage ("vander (c)");
  59.   endif
  60.  
  61.   nr = rows (c);
  62.   nc = columns (c);
  63.   if (nr == 1 && nc == 1)
  64.     retval = 1;
  65.   elseif (nr == 1 || nc == 1)
  66.     n = length (c);
  67.     if (n > 0)
  68.       retval = zeros (n, n);
  69.       for i = 1:n
  70.         tmp = c(i);
  71.         for j = 1:n
  72.           retval (i, j) = tmp ^ (n - j);
  73.         endfor
  74.       endfor
  75.     endif
  76.   else
  77.     error ("vander: argument must be a vector");
  78.   endif
  79.  
  80. endfunction
  81.