7017
|
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004, |
|
2 ## 2005, 2006, 2007 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} {} toeplitz (@var{c}, @var{r}) |
|
22 ## Return the Toeplitz matrix constructed given the first column @var{c}, |
|
23 ## and (optionally) the first row @var{r}. If the first element of @var{c} |
|
24 ## is not the same as the first element of @var{r}, the first element of |
|
25 ## @var{c} is used. If the second argument is omitted, the first row is |
|
26 ## taken to be the same as the first column. |
3426
|
27 ## |
5016
|
28 ## A square Toeplitz matrix has the form: |
3369
|
29 ## @iftex |
|
30 ## @tex |
|
31 ## $$ |
5016
|
32 ## \left[\matrix{c_0 & r_1 & r_2 & \cdots & r_n\cr |
|
33 ## c_1 & c_0 & r_1 & \cdots & r_{n-1}\cr |
|
34 ## c_2 & c_1 & c_0 & \cdots & r_{n-2}\cr |
|
35 ## \vdots & \vdots & \vdots & \ddots & \vdots\cr |
|
36 ## c_n & c_{n-1} & c_{n-2} & \ldots & c_0}\right] |
3369
|
37 ## $$ |
|
38 ## @end tex |
|
39 ## @end iftex |
|
40 ## @ifinfo |
3426
|
41 ## |
3369
|
42 ## @example |
|
43 ## @group |
|
44 ## c(0) r(1) r(2) ... r(n) |
5016
|
45 ## c(1) c(0) r(1) ... r(n-1) |
|
46 ## c(2) c(1) c(0) ... r(n-2) |
|
47 ## . , , . . |
|
48 ## . , , . . |
|
49 ## . , , . . |
3369
|
50 ## c(n) c(n-1) c(n-2) ... c(0) |
|
51 ## @end group |
|
52 ## @end example |
|
53 ## @end ifinfo |
5781
|
54 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb} |
3369
|
55 ## @end deftypefn |
4
|
56 |
2314
|
57 ## Author: jwe |
|
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 |
|
67 [c_nr, c_nc] = size (c); |
|
68 [r_nr, r_nc] = size (r); |
|
69 |
|
70 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
71 error ("toeplitz: expecting vector arguments"); |
4
|
72 endif |
|
73 |
|
74 if (c_nc != 1) |
1015
|
75 c = c.'; |
4
|
76 endif |
|
77 |
|
78 if (r_nr != 1) |
1015
|
79 r = r.'; |
4
|
80 endif |
|
81 |
|
82 if (r (1) != c (1)) |
904
|
83 warning ("toeplitz: column wins diagonal conflict"); |
4
|
84 endif |
|
85 |
2303
|
86 ## If we have a single complex argument, we want to return a |
|
87 ## Hermitian-symmetric matrix (actually, this will really only be |
|
88 ## Hermitian-symmetric if the first element of the vector is real). |
1016
|
89 |
|
90 if (nargin == 1) |
|
91 c = conj (c); |
|
92 c(1) = conj (c(1)); |
|
93 endif |
|
94 |
2303
|
95 ## This should probably be done with the colon operator... |
4
|
96 |
|
97 nc = length (r); |
|
98 nr = length (c); |
|
99 |
5731
|
100 retval = resize (resize (c, 0), nr, nc); |
4
|
101 |
|
102 for i = 1:min (nc, nr) |
|
103 retval (i:nr, i) = c (1:nr-i+1); |
|
104 endfor |
|
105 |
|
106 for i = 1:min (nr, nc-1) |
|
107 retval (i, i+1:nc) = r (2:nc-i+1); |
|
108 endfor |
|
109 |
|
110 endfunction |