comparison scripts/special-matrix/vander.m @ 7387:b429b21abdd4

[project @ 2008-01-15 21:43:11 by jwe]
author jwe
date Tue, 15 Jan 2008 21:43:11 +0000
parents a1dbe9d80eee
children 83a8781b529d
comparison
equal deleted inserted replaced
7386:22815fa9c368 7387:b429b21abdd4
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002,
2 ## 2004, 2005, 2006, 2007 John W. Eaton 2 ## 2004, 2005, 2006, 2007, 2008 John W. Eaton
3 ## 3 ##
4 ## This file is part of Octave. 4 ## This file is part of Octave.
5 ## 5 ##
6 ## Octave is free software; you can redistribute it and/or modify it 6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by 7 ## under the terms of the GNU General Public License as published by
56 print_usage (); 56 print_usage ();
57 endif 57 endif
58 58
59 if (isvector (c)) 59 if (isvector (c))
60 n = length (c); 60 n = length (c);
61 retval = zeros (n, n); 61 retval = (c(:) * ones (1, n)) .^ (ones (n, 1) * (n-1:-1:0));
62 j = 1:n;
63 for i = 1:n
64 retval(i,:) = c(i) .^ (n - j);
65 endfor
66 else 62 else
67 error ("vander: argument must be a vector"); 63 error ("vander: argument must be a vector");
68 endif 64 endif
69 65
70 endfunction 66 endfunction
67
68 %!test
69 %! c = [0,1,2,3];
70 %! expect = [0,0,0,1; 1,1,1,1; 8,4,2,1; 27,9,3,1];
71 %! result = vander(c);
72 %! assert(expect, result);