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