Mercurial > hg > octave-nkf
annotate scripts/special-matrix/hankel.m @ 12639:4d777e05d47c stable
doc: Review and update documentation for "Matrix Manipulation" chapter.
* matrix.txi, arrayfun.m, blkdiag.m, fliplr.m, flipud.m, logspace.m,
postpad.m, prepad.m, randi.m, repmat.m, rot90.m, rotdim.m, shiftdim.m,
sortrows.m, vech.m, xor.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m,
pascal.m, rosser.m, sylvester_matrix.m, toeplitz.m, vander.m, wilkinson.m,
bsxfun.cc, find.cc, lookup.cc, rand.cc, tril.cc, data.cc, arrayfun.m,
blkdiag.m, fliplr.m, flipud.m, logspace.m, postpad.m, prepad.m, randi.m,
repmat.m, rot90.m, rotdim.m, shiftdim.m, sortrows.m, vech.m, xor.m, hadamard.m,
hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m, sylvester_matrix.m,
toeplitz.m, vander.m, wilkinson.m, bsxfun.cc (bsxfun), find.cc (find),
lookup.cc (lookup), rand.cc (rand, randn, rande, randg, randp),
tril.cc (triu), data.cc (all, any, horzcat, vertcat, cat, permute, ipermute,
ones, zeros, eye, linspace, resize, reshape, issorted, diff):
Improve docstrings
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 01 May 2011 08:55:15 -0700 |
parents | fd0a3ac60b0e |
children | c78ac846fcbc |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1993-2011 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 -*- |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
20 ## @deftypefn {Function File} {} hankel (@var{c}) |
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
21 ## @deftypefnx {Function File} {} hankel (@var{c}, @var{r}) |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## Return the Hankel matrix constructed from the first column @var{c}, and |
3369 | 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 | |
4922 | 25 ## @var{c} is used. If the second argument is omitted, it is assumed to |
26 ## be a vector of zeros with the same size as @var{c}. | |
3426 | 27 ## |
3369 | 28 ## A Hankel matrix formed from an m-vector @var{c}, and an n-vector |
29 ## @var{r}, has the elements | |
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 | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
35 ## @ifnottex |
3426 | 36 ## |
3369 | 37 ## @example |
38 ## @group | |
4922 | 39 ## H(i,j) = c(i+j-1), i+j-1 <= m; |
40 ## H(i,j) = r(i+j-m), otherwise | |
3369 | 41 ## @end group |
42 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
44 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 ## @seealso{hadamard, 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]); | |
7411 | 108 |
109 %!assert((hankel (1) == 1 && hankel ([1, 2]) == [1, 2; 2, 0] | |
110 %! && hankel ([1, 2], [2; -1; -3]) == [1, 2, -1; 2, -1, -3])); | |
111 | |
112 %!error hankel ([1, 2; 3, 4], [1, 2; 3, 4]); | |
113 | |
114 %!error hankel (); | |
115 | |
116 %!error hankel (1, 2, 3); | |
117 |