Mercurial > hg > octave-nkf
annotate scripts/special-matrix/vander.m @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 81d6ab3ac93c |
children | 853f96e8008f |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, |
8920 | 2 ## 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
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 | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
245 | 19 |
3369 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} vander (@var{c}) | |
22 ## Return the Vandermonde matrix whose next to last column is @var{c}. | |
3426 | 23 ## |
5016 | 24 ## A Vandermonde matrix has the form: |
3369 | 25 ## @iftex |
26 ## @tex | |
27 ## $$ | |
5016 | 28 ## \left[\matrix{c_1^{n-1} & \cdots & c_1^2 & c_1 & 1 \cr |
29 ## c_2^{n-1} & \cdots & c_2^2 & c_2 & 1 \cr | |
30 ## \vdots & \ddots & \vdots & \vdots & \vdots \cr | |
31 ## c_n^{n-1} & \cdots & c_n^2 & c_n & 1 }\right] | |
3369 | 32 ## $$ |
33 ## @end tex | |
34 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
35 ## @ifnottex |
3426 | 36 ## |
3369 | 37 ## @example |
38 ## @group | |
5016 | 39 ## c(1)^(n-1) ... c(1)^2 c(1) 1 |
40 ## c(2)^(n-1) ... c(2)^2 c(2) 1 | |
41 ## . . . . . | |
42 ## . . . . . | |
43 ## . . . . . | |
44 ## c(n)^(n-1) ... c(n)^2 c(n) 1 | |
3369 | 45 ## @end group |
46 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
47 ## @end ifnottex |
5642 | 48 ## @seealso{hankel, sylvester_matrix, hilb, invhilb, toeplitz} |
3369 | 49 ## @end deftypefn |
4 | 50 |
2314 | 51 ## Author: jwe |
52 | |
2311 | 53 function retval = vander (c) |
4 | 54 |
55 if (nargin != 1) | |
6046 | 56 print_usage (); |
4 | 57 endif |
58 | |
4030 | 59 if (isvector (c)) |
4 | 60 n = length (c); |
7387 | 61 retval = (c(:) * ones (1, n)) .^ (ones (n, 1) * (n-1:-1:0)); |
4 | 62 else |
63 error ("vander: argument must be a vector"); | |
64 endif | |
65 | |
66 endfunction | |
7387 | 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); | |
7411 | 73 |
74 %!assert((vander (1) == 1 && vander ([1, 2, 3]) == vander ([1; 2; 3]) | |
75 %! && vander ([1, 2, 3]) == [1, 1, 1; 4, 2, 1; 9, 3, 1] | |
76 %! && vander ([1, 2, 3]*i) == [-1, i, 1; -4, 2i, 1; -9, 3i, 1])); | |
77 | |
78 %!error vander ([1, 2; 3, 4]); | |
79 | |
80 %!error vander (); | |
81 | |
82 %!error vander (1, 2); | |
83 |