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. |
|
27 ## |
|
28 ## A square Toeplitz matrix has the form |
|
29 ## @iftex |
|
30 ## @tex |
|
31 ## $$ |
|
32 ## \left[\matrix{c_0 & r_1 & r_2 & \ldots & r_n\cr |
|
33 ## c_1 & c_0 & r_1 & & c_{n-1}\cr |
|
34 ## c_2 & c_1 & c_0 & & c_{n-2}\cr |
|
35 ## \vdots & & & & \vdots\cr |
|
36 ## c_n & c_{n-1} & c_{n-2} & \ldots & c_0}\right]. |
|
37 ## $$ |
|
38 ## @end tex |
|
39 ## @end iftex |
|
40 ## @ifinfo |
|
41 ## |
|
42 ## @example |
|
43 ## @group |
|
44 ## c(0) r(1) r(2) ... r(n) |
|
45 ## c(1) c(0) r(1) r(n-1) |
|
46 ## c(2) c(1) c(0) r(n-2) |
|
47 ## . . |
|
48 ## . . |
|
49 ## . . |
|
50 ## |
|
51 ## c(n) c(n-1) c(n-2) ... c(0) |
|
52 ## @end group |
|
53 ## @end example |
|
54 ## @end ifinfo |
|
55 ## @end deftypefn |
|
56 |
3140
|
57 ## See also: hankel, vander, sylvester_matrix, hilb, invhib |
4
|
58 |
2314
|
59 ## Author: jwe |
|
60 |
2311
|
61 function retval = toeplitz (c, r) |
4
|
62 |
|
63 if (nargin == 1) |
|
64 r = c; |
|
65 elseif (nargin != 2) |
904
|
66 usage ("toeplitz (c, r)"); |
4
|
67 endif |
|
68 |
|
69 [c_nr, c_nc] = size (c); |
|
70 [r_nr, r_nc] = size (r); |
|
71 |
|
72 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
73 error ("toeplitz: expecting vector arguments"); |
4
|
74 endif |
|
75 |
|
76 if (c_nc != 1) |
1015
|
77 c = c.'; |
4
|
78 endif |
|
79 |
|
80 if (r_nr != 1) |
1015
|
81 r = r.'; |
4
|
82 endif |
|
83 |
|
84 if (r (1) != c (1)) |
904
|
85 warning ("toeplitz: column wins diagonal conflict"); |
4
|
86 endif |
|
87 |
2303
|
88 ## If we have a single complex argument, we want to return a |
|
89 ## Hermitian-symmetric matrix (actually, this will really only be |
|
90 ## Hermitian-symmetric if the first element of the vector is real). |
1016
|
91 |
|
92 if (nargin == 1) |
|
93 c = conj (c); |
|
94 c(1) = conj (c(1)); |
|
95 endif |
|
96 |
2303
|
97 ## This should probably be done with the colon operator... |
4
|
98 |
|
99 nc = length (r); |
|
100 nr = length (c); |
|
101 |
|
102 retval = zeros (nr, nc); |
|
103 |
|
104 for i = 1:min (nc, nr) |
|
105 retval (i:nr, i) = c (1:nr-i+1); |
|
106 endfor |
|
107 |
|
108 for i = 1:min (nr, nc-1) |
|
109 retval (i, i+1:nc) = r (2:nc-i+1); |
|
110 endfor |
|
111 |
|
112 endfunction |