Mercurial > hg > octave-lyh
annotate scripts/special-matrix/vander.m @ 10791:3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
interpreter/doccheck: New directory for spelling/grammar scripts.
interpreter/doccheck/README: Instructions for using scripts.
interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file.
interpreter/doccheck/aspell.conf: GNU Aspell configuration file for
Octave documentation.
interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary.
interpreter/doccheck/add_to_aspell_dict: Script to add new
Octave-specific words to
private Aspell dictionary.
interpreter/octave.texi: New @nospell macro which forces Aspell
to ignore the word marked by the macro.
interpreter/mk_doc_cache.m: Skip new @nospell macro when building
doc_cache.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 17 Jul 2010 19:53:01 -0700 |
parents | f0c3d3fc4903 |
children | 693e22af08ae |
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 |
9104 | 3 ## Copyright (C) 2009 VZLU Prague |
2313 | 4 ## |
5 ## This file is part of Octave. | |
6 ## | |
7 ## Octave is free software; you can redistribute it and/or modify it | |
8 ## under the terms of the GNU General Public License as published by | |
7016 | 9 ## the Free Software Foundation; either version 3 of the License, or (at |
10 ## your option) any later version. | |
2313 | 11 ## |
12 ## Octave is distributed in the hope that it will be useful, but | |
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 ## General Public License for more details. | |
16 ## | |
17 ## You should have received a copy of the GNU General Public License | |
7016 | 18 ## along with Octave; see the file COPYING. If not, see |
19 ## <http://www.gnu.org/licenses/>. | |
245 | 20 |
3369 | 21 ## -*- texinfo -*- |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
22 ## @deftypefn {Function File} {} vander (@var{c}) |
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
23 ## @deftypefnx {Function File} {} vander (@var{c}, @var{n}) |
3369 | 24 ## Return the Vandermonde matrix whose next to last column is @var{c}. |
9137
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
25 ## If @var{n} is specified, it determines the number of columns; |
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
26 ## otherwise, @var{n} is taken to be equal to the length of @var{c}. |
3426 | 27 ## |
5016 | 28 ## A Vandermonde matrix has the form: |
3369 | 29 ## @tex |
30 ## $$ | |
5016 | 31 ## \left[\matrix{c_1^{n-1} & \cdots & c_1^2 & c_1 & 1 \cr |
32 ## c_2^{n-1} & \cdots & c_2^2 & c_2 & 1 \cr | |
33 ## \vdots & \ddots & \vdots & \vdots & \vdots \cr | |
34 ## c_n^{n-1} & \cdots & c_n^2 & c_n & 1 }\right] | |
3369 | 35 ## $$ |
36 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
37 ## @ifnottex |
3426 | 38 ## |
3369 | 39 ## @example |
40 ## @group | |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
41 ## c(1)^(n-1) @dots{} c(1)^2 c(1) 1 |
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 ## c(2)^(n-1) @dots{} c(2)^2 c(2) 1 |
5016 | 43 ## . . . . . |
44 ## . . . . . | |
45 ## . . . . . | |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 ## c(n)^(n-1) @dots{} c(n)^2 c(n) 1 |
3369 | 47 ## @end group |
48 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
49 ## @end ifnottex |
5642 | 50 ## @seealso{hankel, sylvester_matrix, hilb, invhilb, toeplitz} |
3369 | 51 ## @end deftypefn |
4 | 52 |
2314 | 53 ## Author: jwe |
54 | |
9137
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
55 function retval = vander (c, n) |
4 | 56 |
9137
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
57 if (nargin == 1) |
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
58 n = length (c); |
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
59 elseif (nargin != 2) |
6046 | 60 print_usage (); |
4 | 61 endif |
62 | |
4030 | 63 if (isvector (c)) |
9137
eebc7f8e7398
extend vander to allow specified number of columns
Jaroslav Hajek <highegg@gmail.com>
parents:
9104
diff
changeset
|
64 retval = zeros (length (c), n, class (c)); |
9104 | 65 ## avoiding many ^s appears to be faster for n >= 100. |
66 d = 1; | |
67 c = c(:); | |
68 for i = n:-1:1 | |
69 retval(:,i) = d; | |
70 d = c .* d; | |
71 endfor | |
4 | 72 else |
73 error ("vander: argument must be a vector"); | |
74 endif | |
75 | |
76 endfunction | |
7387 | 77 |
78 %!test | |
79 %! c = [0,1,2,3]; | |
80 %! expect = [0,0,0,1; 1,1,1,1; 8,4,2,1; 27,9,3,1]; | |
81 %! result = vander(c); | |
82 %! assert(expect, result); | |
7411 | 83 |
84 %!assert((vander (1) == 1 && vander ([1, 2, 3]) == vander ([1; 2; 3]) | |
85 %! && vander ([1, 2, 3]) == [1, 1, 1; 4, 2, 1; 9, 3, 1] | |
86 %! && vander ([1, 2, 3]*i) == [-1, i, 1; -4, 2i, 1; -9, 3i, 1])); | |
87 | |
9140 | 88 %!assert(vander (2, 3), [4, 2, 1]) |
89 %!assert(vander ([2, 3], 3), [4, 2, 1; 9, 3, 1]) | |
90 | |
7411 | 91 %!error vander ([1, 2; 3, 4]); |
92 | |
93 %!error vander (); | |
94 | |
9140 | 95 %!error vander (1, 2, 3); |
7411 | 96 |