2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
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 |
|
54 ## @end deftypefn |
5053
|
55 ## |
3408
|
56 ## @seealso{hankel, vander, sylvester_matrix, hilb, and invhib} |
4
|
57 |
2314
|
58 ## Author: jwe |
|
59 |
2311
|
60 function retval = toeplitz (c, r) |
4
|
61 |
|
62 if (nargin == 1) |
|
63 r = c; |
|
64 elseif (nargin != 2) |
904
|
65 usage ("toeplitz (c, r)"); |
4
|
66 endif |
|
67 |
|
68 [c_nr, c_nc] = size (c); |
|
69 [r_nr, r_nc] = size (r); |
|
70 |
|
71 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
72 error ("toeplitz: expecting vector arguments"); |
4
|
73 endif |
|
74 |
|
75 if (c_nc != 1) |
1015
|
76 c = c.'; |
4
|
77 endif |
|
78 |
|
79 if (r_nr != 1) |
1015
|
80 r = r.'; |
4
|
81 endif |
|
82 |
|
83 if (r (1) != c (1)) |
904
|
84 warning ("toeplitz: column wins diagonal conflict"); |
4
|
85 endif |
|
86 |
2303
|
87 ## If we have a single complex argument, we want to return a |
|
88 ## Hermitian-symmetric matrix (actually, this will really only be |
|
89 ## Hermitian-symmetric if the first element of the vector is real). |
1016
|
90 |
|
91 if (nargin == 1) |
|
92 c = conj (c); |
|
93 c(1) = conj (c(1)); |
|
94 endif |
|
95 |
2303
|
96 ## This should probably be done with the colon operator... |
4
|
97 |
|
98 nc = length (r); |
|
99 nr = length (c); |
|
100 |
|
101 retval = zeros (nr, nc); |
|
102 |
|
103 for i = 1:min (nc, nr) |
|
104 retval (i:nr, i) = c (1:nr-i+1); |
|
105 endfor |
|
106 |
|
107 for i = 1:min (nr, nc-1) |
|
108 retval (i, i+1:nc) = r (2:nc-i+1); |
|
109 endfor |
|
110 |
|
111 endfunction |