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: 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 |
2325
|
26 ## anti-diagonal. If the last element of c is not the same as the first |
2311
|
27 ## element of r, the last element of c is used. |
|
28 ## |
|
29 ## See also: vander, hadamard, hilb, invhilb, toeplitz |
4
|
30 |
2314
|
31 ## Author: jwe |
|
32 |
2311
|
33 function retval = hankel (c, r) |
4
|
34 |
|
35 if (nargin == 1) |
1396
|
36 r = zeros (size (c)); |
4
|
37 elseif (nargin != 2) |
904
|
38 usage ("hankel (c, r)"); |
4
|
39 endif |
|
40 |
|
41 [c_nr, c_nc] = size (c); |
|
42 [r_nr, r_nc] = size (r); |
|
43 |
|
44 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
45 error ("hankel: expecting vector arguments"); |
4
|
46 endif |
|
47 |
2325
|
48 if (nargin == 1) |
1396
|
49 r (1) = c (length (c)); |
|
50 endif |
|
51 |
4
|
52 if (c_nc != 1) |
1035
|
53 c = c.'; |
4
|
54 endif |
|
55 |
|
56 if (r_nr != 1) |
1035
|
57 r = r.'; |
4
|
58 endif |
|
59 |
1396
|
60 nc = length (r); |
|
61 nr = length (c); |
|
62 |
|
63 if (r (1) != c (nr)) |
904
|
64 warning ("hankel: column wins anti-diagonal conflict"); |
4
|
65 endif |
|
66 |
2303
|
67 ## This should probably be done with the colon operator... |
4
|
68 |
|
69 retval = zeros (nr, nc); |
|
70 |
|
71 for i = 1:min (nr, nc) |
|
72 retval (1:nr-i+1, i) = c (i:nr); |
|
73 endfor |
|
74 |
|
75 tmp = 1; |
|
76 if (nc <= nr) |
|
77 tmp = nr - nc + 2; |
|
78 endif |
|
79 |
|
80 for i = nr:-1:tmp |
|
81 retval (i, 2+nr-i:nc) = r (2:nc-nr+i); |
|
82 endfor |
|
83 |
|
84 endfunction |