2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
245
|
18 |
3369
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} hankel (@var{c}, @var{r}) |
|
21 ## Return the Hankel matrix constructed given the first column @var{c}, and |
|
22 ## (optionally) the last row @var{r}. If the last element of @var{c} is |
|
23 ## not the same as the first element of @var{r}, the last element of |
4922
|
24 ## @var{c} is used. If the second argument is omitted, it is assumed to |
|
25 ## be a vector of zeros with the same size as @var{c}. |
3426
|
26 ## |
3369
|
27 ## A Hankel matrix formed from an m-vector @var{c}, and an n-vector |
|
28 ## @var{r}, has the elements |
|
29 ## @iftex |
|
30 ## @tex |
|
31 ## $$ |
|
32 ## H (i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr} |
|
33 ## $$ |
|
34 ## @end tex |
|
35 ## @end iftex |
|
36 ## @ifinfo |
3426
|
37 ## |
3369
|
38 ## @example |
|
39 ## @group |
4922
|
40 ## H(i,j) = c(i+j-1), i+j-1 <= m; |
|
41 ## H(i,j) = r(i+j-m), otherwise |
3369
|
42 ## @end group |
|
43 ## @end example |
|
44 ## @end ifinfo |
5642
|
45 ## @seealso{vander, sylvester_matrix, hilb, invhilb, toeplitz} |
3369
|
46 ## @end deftypefn |
4
|
47 |
2314
|
48 ## Author: jwe |
|
49 |
2311
|
50 function retval = hankel (c, r) |
4
|
51 |
|
52 if (nargin == 1) |
5731
|
53 r = resize (resize (c, 0), size(c)); |
4
|
54 elseif (nargin != 2) |
6046
|
55 print_usage (); |
4
|
56 endif |
|
57 |
|
58 [c_nr, c_nc] = size (c); |
|
59 [r_nr, r_nc] = size (r); |
|
60 |
|
61 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
62 error ("hankel: expecting vector arguments"); |
4
|
63 endif |
|
64 |
2325
|
65 if (nargin == 1) |
1396
|
66 r (1) = c (length (c)); |
|
67 endif |
|
68 |
4
|
69 if (c_nc != 1) |
1035
|
70 c = c.'; |
4
|
71 endif |
|
72 |
|
73 if (r_nr != 1) |
1035
|
74 r = r.'; |
4
|
75 endif |
|
76 |
1396
|
77 nc = length (r); |
|
78 nr = length (c); |
|
79 |
|
80 if (r (1) != c (nr)) |
904
|
81 warning ("hankel: column wins anti-diagonal conflict"); |
4
|
82 endif |
|
83 |
2303
|
84 ## This should probably be done with the colon operator... |
4
|
85 |
5731
|
86 retval = resize (resize (c, 0), nr, nc); |
4
|
87 |
|
88 for i = 1:min (nr, nc) |
|
89 retval (1:nr-i+1, i) = c (i:nr); |
|
90 endfor |
|
91 |
|
92 tmp = 1; |
|
93 if (nc <= nr) |
|
94 tmp = nr - nc + 2; |
|
95 endif |
|
96 |
|
97 for i = nr:-1:tmp |
|
98 retval (i, 2+nr-i:nc) = r (2:nc-nr+i); |
|
99 endfor |
|
100 |
|
101 endfunction |
5731
|
102 |
|
103 %!assert(hankel(1:3),[1,2,3;2,3,0;3,0,0]) |
|
104 %!assert(hankel(1),[1]); |
|
105 %!assert(hankel(1:3,3:6),[1,2,3,4;2,3,4,5;3,4,5,6]); |
|
106 %!assert(hankel(1:3,3:4),[1,2;2,3;3,4]); |
|
107 %!assert(hankel(1:3,4:6),[1,2,3;2,3,5;3,5,6]); |