1014
|
1 # Copyright (C) 1993, 1994, 1995 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
4
|
19 function retval = toeplitz (c, r) |
|
20 |
|
21 # usage: toeplitz (c, r) |
|
22 # |
|
23 # Return the Toeplitz matrix constructed given the first column |
|
24 # c, and (optionally) the first row r. |
|
25 # |
|
26 # If the second argument is omitted, the first row is taken to be the |
|
27 # same as the first column. If the first element of c is not the same |
|
28 # as the first element of r, the first element of c is used. |
|
29 # |
|
30 # See also: hankel, vander, hadamard, hilb, invhib |
|
31 |
|
32 if (nargin == 1) |
|
33 r = c; |
|
34 elseif (nargin != 2) |
904
|
35 usage ("toeplitz (c, r)"); |
4
|
36 endif |
|
37 |
|
38 [c_nr, c_nc] = size (c); |
|
39 [r_nr, r_nc] = size (r); |
|
40 |
|
41 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
|
42 error ("toeplitz: expecting vector arguments") |
|
43 endif |
|
44 |
|
45 if (c_nc != 1) |
1015
|
46 c = c.'; |
4
|
47 endif |
|
48 |
|
49 if (r_nr != 1) |
1015
|
50 r = r.'; |
4
|
51 endif |
|
52 |
|
53 if (r (1) != c (1)) |
904
|
54 warning ("toeplitz: column wins diagonal conflict"); |
4
|
55 endif |
|
56 |
1016
|
57 # If we have a single complex argument, we want to return a |
|
58 # Hermitian-symmetric matrix (actually, this will really only be |
|
59 # Hermitian-symmetric if the first element of the vector is real). |
|
60 |
|
61 if (nargin == 1) |
|
62 c = conj (c); |
|
63 c(1) = conj (c(1)); |
|
64 endif |
|
65 |
4
|
66 # This should probably be done with the colon operator... |
|
67 |
|
68 nc = length (r); |
|
69 nr = length (c); |
|
70 |
|
71 retval = zeros (nr, nc); |
|
72 |
|
73 for i = 1:min (nc, nr) |
|
74 retval (i:nr, i) = c (1:nr-i+1); |
|
75 endfor |
|
76 |
|
77 for i = 1:min (nr, nc-1) |
|
78 retval (i, i+1:nc) = r (2:nc-i+1); |
|
79 endfor |
|
80 |
|
81 endfunction |