2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
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 |
2311
|
20 ## usage: toeplitz (c, r) |
|
21 ## |
|
22 ## Return the Toeplitz matrix constructed given the first column |
|
23 ## c, and (optionally) the first row r. |
|
24 ## |
|
25 ## If the second argument is omitted, the first row is taken to be the |
|
26 ## same as the first column. If the first element of c is not the same |
|
27 ## as the first element of r, the first element of c is used. |
|
28 ## |
|
29 ## See also: hankel, vander, hadamard, hilb, invhib |
4
|
30 |
2311
|
31 function retval = toeplitz (c, r) |
4
|
32 |
|
33 if (nargin == 1) |
|
34 r = c; |
|
35 elseif (nargin != 2) |
904
|
36 usage ("toeplitz (c, r)"); |
4
|
37 endif |
|
38 |
|
39 [c_nr, c_nc] = size (c); |
|
40 [r_nr, r_nc] = size (r); |
|
41 |
|
42 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
43 error ("toeplitz: expecting vector arguments"); |
4
|
44 endif |
|
45 |
|
46 if (c_nc != 1) |
1015
|
47 c = c.'; |
4
|
48 endif |
|
49 |
|
50 if (r_nr != 1) |
1015
|
51 r = r.'; |
4
|
52 endif |
|
53 |
|
54 if (r (1) != c (1)) |
904
|
55 warning ("toeplitz: column wins diagonal conflict"); |
4
|
56 endif |
|
57 |
2303
|
58 ## If we have a single complex argument, we want to return a |
|
59 ## Hermitian-symmetric matrix (actually, this will really only be |
|
60 ## Hermitian-symmetric if the first element of the vector is real). |
1016
|
61 |
|
62 if (nargin == 1) |
|
63 c = conj (c); |
|
64 c(1) = conj (c(1)); |
|
65 endif |
|
66 |
2303
|
67 ## This should probably be done with the colon operator... |
4
|
68 |
|
69 nc = length (r); |
|
70 nr = length (c); |
|
71 |
|
72 retval = zeros (nr, nc); |
|
73 |
|
74 for i = 1:min (nc, nr) |
|
75 retval (i:nr, i) = c (1:nr-i+1); |
|
76 endfor |
|
77 |
|
78 for i = 1:min (nr, nc-1) |
|
79 retval (i, i+1:nc) = r (2:nc-i+1); |
|
80 endfor |
|
81 |
|
82 endfunction |