Mercurial > hg > octave-nkf
annotate scripts/special-matrix/toeplitz.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 | 95c3e38098bf |
children | 693e22af08ae |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004, |
8920 | 2 ## 2005, 2006, 2007, 2008, 2009 John W. Eaton |
9092 | 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:
10549
diff
changeset
|
22 ## @deftypefn {Function File} {} toeplitz (@var{c}) |
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
23 ## @deftypefnx {Function File} {} toeplitz (@var{c}, @var{r}) |
3369 | 24 ## Return the Toeplitz matrix constructed given the first column @var{c}, |
25 ## and (optionally) the first row @var{r}. If the first element of @var{c} | |
26 ## is not the same as the first element of @var{r}, the first element of | |
27 ## @var{c} is used. If the second argument is omitted, the first row is | |
28 ## taken to be the same as the first column. | |
3426 | 29 ## |
5016 | 30 ## A square Toeplitz matrix has the form: |
3369 | 31 ## @tex |
32 ## $$ | |
5016 | 33 ## \left[\matrix{c_0 & r_1 & r_2 & \cdots & r_n\cr |
34 ## c_1 & c_0 & r_1 & \cdots & r_{n-1}\cr | |
35 ## c_2 & c_1 & c_0 & \cdots & r_{n-2}\cr | |
36 ## \vdots & \vdots & \vdots & \ddots & \vdots\cr | |
37 ## c_n & c_{n-1} & c_{n-2} & \ldots & c_0}\right] | |
3369 | 38 ## $$ |
39 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
40 ## @ifnottex |
3426 | 41 ## |
3369 | 42 ## @example |
43 ## @group | |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
44 ## c(0) r(1) r(2) @dots{} r(n) |
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
45 ## c(1) c(0) r(1) @dots{} r(n-1) |
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 ## c(2) c(1) c(0) @dots{} r(n-2) |
5016 | 47 ## . , , . . |
48 ## . , , . . | |
49 ## . , , . . | |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
50 ## c(n) c(n-1) c(n-2) @dots{} c(0) |
3369 | 51 ## @end group |
52 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
53 ## @end ifnottex |
5781 | 54 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb} |
3369 | 55 ## @end deftypefn |
4 | 56 |
9092 | 57 ## Author: jwe && jh |
2314 | 58 |
2311 | 59 function retval = toeplitz (c, r) |
4 | 60 |
61 if (nargin == 1) | |
62 r = c; | |
63 elseif (nargin != 2) | |
6046 | 64 print_usage (); |
4 | 65 endif |
66 | |
9092 | 67 if (! (isvector (c) && isvector (r))) |
1518 | 68 error ("toeplitz: expecting vector arguments"); |
4 | 69 endif |
70 | |
9092 | 71 nc = length (r); |
72 nr = length (c); | |
4 | 73 |
9092 | 74 if (nr == 0 || nc == 0) |
75 ## Empty matrix. | |
76 retval = zeros (nr, nc, class (c)); | |
77 return; | |
4 | 78 endif |
79 | |
80 if (r (1) != c (1)) | |
904 | 81 warning ("toeplitz: column wins diagonal conflict"); |
4 | 82 endif |
83 | |
2303 | 84 ## If we have a single complex argument, we want to return a |
85 ## Hermitian-symmetric matrix (actually, this will really only be | |
86 ## Hermitian-symmetric if the first element of the vector is real). | |
1016 | 87 |
9092 | 88 if (nargin == 1 && iscomplex (c)) |
1016 | 89 c = conj (c); |
90 c(1) = conj (c(1)); | |
91 endif | |
92 | |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
93 if (issparse(c) && issparse(r)) |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
94 c = c(:).'; |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
95 r = r(:).'; |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
96 cidx = find(c); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
97 ridx = find(r); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
98 |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
99 ## Ignore the first element in r. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
100 ridx = ridx(ridx > 1); |
4 | 101 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
102 ## Form matrix. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
103 retval = spdiags(repmat(c(cidx),nr,1),1-cidx,nr,nc)+... |
10549 | 104 spdiags(repmat(r(ridx),nr,1),ridx-1,nr,nc); |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
105 else |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
106 ## Concatenate data into a single column vector. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
107 data = [r(end:-1:2)(:); c(:)]; |
4 | 108 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
109 ## Get slices. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
110 slices = cellslices (data, nc:-1:1, nc+nr-1:-1:nr); |
4 | 111 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
112 ## Form matrix. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
113 retval = horzcat (slices{:}); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
114 endif |
4 | 115 endfunction |
7411 | 116 |
117 %!assert((toeplitz (1) == 1 | |
118 %! && toeplitz ([1, 2, 3], [1; -3; -5]) == [1, -3, -5; 2, 1, -3; 3, 2, 1] | |
119 %! && toeplitz ([1, 2, 3], [1; -3i; -5i]) == [1, -3i, -5i; 2, 1, -3i; 3, 2, 1])); | |
120 | |
121 %!error toeplitz ([1, 2; 3, 4], 1); | |
122 | |
123 %!error toeplitz (); | |
124 | |
125 %!error toeplitz (1, 2, 3); | |
126 |