Mercurial > hg > octave-nkf
annotate scripts/special-matrix/toeplitz.m @ 10821:693e22af08ae
Grammarcheck documentation of m-files
Add newlines between @item fields for readability.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 26 Jul 2010 21:25:36 -0700 |
parents | 3140cb7a05a1 |
children | fd0a3ac60b0e |
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) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
47 ## . . . . . |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
48 ## . . . . . |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
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 | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
53 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
54 ## @end ifnottex |
5781 | 55 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb} |
3369 | 56 ## @end deftypefn |
4 | 57 |
9092 | 58 ## Author: jwe && jh |
2314 | 59 |
2311 | 60 function retval = toeplitz (c, r) |
4 | 61 |
62 if (nargin == 1) | |
63 r = c; | |
64 elseif (nargin != 2) | |
6046 | 65 print_usage (); |
4 | 66 endif |
67 | |
9092 | 68 if (! (isvector (c) && isvector (r))) |
1518 | 69 error ("toeplitz: expecting vector arguments"); |
4 | 70 endif |
71 | |
9092 | 72 nc = length (r); |
73 nr = length (c); | |
4 | 74 |
9092 | 75 if (nr == 0 || nc == 0) |
76 ## Empty matrix. | |
77 retval = zeros (nr, nc, class (c)); | |
78 return; | |
4 | 79 endif |
80 | |
81 if (r (1) != c (1)) | |
904 | 82 warning ("toeplitz: column wins diagonal conflict"); |
4 | 83 endif |
84 | |
2303 | 85 ## If we have a single complex argument, we want to return a |
86 ## Hermitian-symmetric matrix (actually, this will really only be | |
87 ## Hermitian-symmetric if the first element of the vector is real). | |
1016 | 88 |
9092 | 89 if (nargin == 1 && iscomplex (c)) |
1016 | 90 c = conj (c); |
91 c(1) = conj (c(1)); | |
92 endif | |
93 | |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
94 if (issparse(c) && issparse(r)) |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
95 c = c(:).'; |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
96 r = r(:).'; |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
97 cidx = find(c); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
98 ridx = find(r); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
99 |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
100 ## Ignore the first element in r. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
101 ridx = ridx(ridx > 1); |
4 | 102 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
103 ## Form matrix. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
104 retval = spdiags(repmat(c(cidx),nr,1),1-cidx,nr,nc)+... |
10549 | 105 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
|
106 else |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
107 ## Concatenate data into a single column vector. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
108 data = [r(end:-1:2)(:); c(:)]; |
4 | 109 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
110 ## Get slices. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
111 slices = cellslices (data, nc:-1:1, nc+nr-1:-1:nr); |
4 | 112 |
9126
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
113 ## Form matrix. |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
114 retval = horzcat (slices{:}); |
5780b3b80425
optimize toeplitz for sparse args
Jaroslav Hajek <highegg@gmail.com>
parents:
9092
diff
changeset
|
115 endif |
4 | 116 endfunction |
7411 | 117 |
118 %!assert((toeplitz (1) == 1 | |
119 %! && toeplitz ([1, 2, 3], [1; -3; -5]) == [1, -3, -5; 2, 1, -3; 3, 2, 1] | |
120 %! && toeplitz ([1, 2, 3], [1; -3i; -5i]) == [1, -3i, -5i; 2, 1, -3i; 3, 2, 1])); | |
121 | |
122 %!error toeplitz ([1, 2; 3, 4], 1); | |
123 | |
124 %!error toeplitz (); | |
125 | |
126 %!error toeplitz (1, 2, 3); | |
127 |