comparison FIXES/hankel.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 2ac2777b30bc
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 1996, 1997 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.
19
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 ## @seealso{vander, sylvester_matrix, hilb, invhilb, and toeplitz}
48
49 ## Author: jwe
50 ## Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
51 ## vectorize for speed
52
53 function retval = hankel (c, r)
54
55 if (nargin == 1)
56 r = zeros (size (c));
57 elseif (nargin != 2)
58 usage ("hankel (c, r)");
59 endif
60
61 [c_nr, c_nc] = size (c);
62 [r_nr, r_nc] = size (r);
63
64 if ((c_nr != 1 && c_nc != 1) || (r_nr != 1 && r_nc != 1))
65 error ("hankel: expecting vector arguments");
66 endif
67
68 if (nargin == 1)
69 r (1) = c (length (c));
70 endif
71
72 if (c_nc != 1)
73 c = c.';
74 endif
75
76 if (r_nc != 1)
77 r = r.';
78 endif
79
80 nc = length (r);
81 nr = length (c);
82
83 if (r (1) != c (nr))
84 warning ("hankel: column wins anti-diagonal conflict");
85 endif
86
87 if (nc > 1)
88 c = [ c ; r (2:nc) ];
89 endif
90 retval = c ( ones (nr, 1) * [1:nc] + [0:nr-1]' * ones (1, nc) );
91 retval = reshape (retval, nr, nc);
92
93 endfunction