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 |
|
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 |
3369
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} hankel (@var{c}, @var{r}) |
|
22 ## Return the Hankel matrix constructed given the first column @var{c}, and |
|
23 ## (optionally) the last row @var{r}. If the last element of @var{c} is |
|
24 ## not the same as the first element of @var{r}, the last element of |
|
25 ## @var{c} is used. If the second argument is omitted, the last row is |
|
26 ## taken to be the same as the first column. |
|
27 ## |
|
28 ## A Hankel matrix formed from an m-vector @var{c}, and an n-vector |
|
29 ## @var{r}, has the elements |
|
30 ## @iftex |
|
31 ## @tex |
|
32 ## $$ |
|
33 ## H (i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr} |
|
34 ## $$ |
|
35 ## @end tex |
|
36 ## @end iftex |
|
37 ## @ifinfo |
|
38 ## |
|
39 ## @example |
|
40 ## @group |
|
41 ## H (i, j) = c (i+j-1), i+j-1 <= m; |
|
42 ## H (i, j) = r (i+j-m), otherwise |
|
43 ## @end group |
|
44 ## @end example |
|
45 ## @end ifinfo |
|
46 ## @end deftypefn |
|
47 |
3140
|
48 ## See also: vander, sylvester_matrix, hilb, invhilb, toeplitz |
4
|
49 |
2314
|
50 ## Author: jwe |
|
51 |
2311
|
52 function retval = hankel (c, r) |
4
|
53 |
|
54 if (nargin == 1) |
1396
|
55 r = zeros (size (c)); |
4
|
56 elseif (nargin != 2) |
904
|
57 usage ("hankel (c, r)"); |
4
|
58 endif |
|
59 |
|
60 [c_nr, c_nc] = size (c); |
|
61 [r_nr, r_nc] = size (r); |
|
62 |
|
63 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1)) |
1518
|
64 error ("hankel: expecting vector arguments"); |
4
|
65 endif |
|
66 |
2325
|
67 if (nargin == 1) |
1396
|
68 r (1) = c (length (c)); |
|
69 endif |
|
70 |
4
|
71 if (c_nc != 1) |
1035
|
72 c = c.'; |
4
|
73 endif |
|
74 |
|
75 if (r_nr != 1) |
1035
|
76 r = r.'; |
4
|
77 endif |
|
78 |
1396
|
79 nc = length (r); |
|
80 nr = length (c); |
|
81 |
|
82 if (r (1) != c (nr)) |
904
|
83 warning ("hankel: column wins anti-diagonal conflict"); |
4
|
84 endif |
|
85 |
2303
|
86 ## This should probably be done with the colon operator... |
4
|
87 |
|
88 retval = zeros (nr, nc); |
|
89 |
|
90 for i = 1:min (nr, nc) |
|
91 retval (1:nr-i+1, i) = c (i:nr); |
|
92 endfor |
|
93 |
|
94 tmp = 1; |
|
95 if (nc <= nr) |
|
96 tmp = nr - nc + 2; |
|
97 endif |
|
98 |
|
99 for i = nr:-1:tmp |
|
100 retval (i, 2+nr-i:nc) = r (2:nc-nr+i); |
|
101 endfor |
|
102 |
|
103 endfunction |