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 |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
245
|
18 |
4
|
19 function retval = hankel (c, r) |
|
20 |
|
21 # usage: hankel (c, r) |
|
22 # |
|
23 # Return the Hankel matrix constructed given the first column |
|
24 # c, and (optionally) the last row r. |
|
25 # |
|
26 # If the second argument is omitted, the last row is taken to be the |
|
27 # same as the first column. If the last element of c is not the same |
|
28 # as the first element of r, the last element of c is used. |
|
29 # |
|
30 # See also: vander, hadamard, hilb, invhilb, toeplitz |
|
31 |
|
32 if (nargin == 1) |
|
33 r = c; |
|
34 elseif (nargin != 2) |
904
|
35 usage ("hankel (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 ("hankel: expecting vector arguments") |
|
43 endif |
|
44 |
|
45 if (c_nc != 1) |
1035
|
46 c = c.'; |
4
|
47 endif |
|
48 |
|
49 if (r_nr != 1) |
1035
|
50 r = r.'; |
4
|
51 endif |
|
52 |
|
53 if (r (1) != c (1)) |
904
|
54 warning ("hankel: column wins anti-diagonal conflict"); |
4
|
55 endif |
|
56 |
|
57 # This should probably be done with the colon operator... |
|
58 |
|
59 nc = length (r); |
|
60 nr = length (c); |
|
61 |
|
62 retval = zeros (nr, nc); |
|
63 |
|
64 for i = 1:min (nr, nc) |
|
65 retval (1:nr-i+1, i) = c (i:nr); |
|
66 endfor |
|
67 |
|
68 tmp = 1; |
|
69 if (nc <= nr) |
|
70 tmp = nr - nc + 2; |
|
71 endif |
|
72 |
|
73 for i = nr:-1:tmp |
|
74 retval (i, 2+nr-i:nc) = r (2:nc-nr+i); |
|
75 endfor |
|
76 |
|
77 endfunction |