Mercurial > octave
annotate scripts/special-matrix/hankel.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1993-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
5 ## |
2313 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
2313 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
2313 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
245 | 22 |
3369 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
24 ## @deftypefn {} {} hankel (@var{c}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
25 ## @deftypefnx {} {} 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
|
26 ## Return the Hankel matrix constructed from the first column @var{c}, and |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## (optionally) the last row @var{r}. |
3426 | 28 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## If the last element of @var{c} is not the same as the first element of |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## @var{r}, the last element of @var{c} is used. If the second argument is |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
31 ## omitted, it is assumed to be a vector of zeros with the same size as |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21443
diff
changeset
|
32 ## @var{c}. |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 ## |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
34 ## A Hankel matrix formed from an m-vector @var{c}, and an n-vector @var{r}, |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
35 ## has the elements |
3369 | 36 ## @tex |
37 ## $$ | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
38 ## H(i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr} |
3369 | 39 ## $$ |
40 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
41 ## @ifnottex |
3426 | 42 ## |
3369 | 43 ## @example |
44 ## @group | |
4922 | 45 ## H(i,j) = c(i+j-1), i+j-1 <= m; |
46 ## H(i,j) = r(i+j-m), otherwise | |
3369 | 47 ## @end group |
48 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
49 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
50 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 ## @seealso{hadamard, toeplitz} |
3369 | 52 ## @end deftypefn |
4 | 53 |
2311 | 54 function retval = hankel (c, r) |
4 | 55 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
56 if (nargin < 1 || nargin > 2) |
6046 | 57 print_usage (); |
4 | 58 endif |
59 | |
2325 | 60 if (nargin == 1) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
61 |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
62 if (! isvector (c)) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
63 error ("hankel: C must be a vector"); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
64 endif |
1396 | 65 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
66 nr = length (c); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
67 nc = nr; |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
68 data = [c(:) ; zeros(nr, 1)]; |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
69 |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
70 else |
4 | 71 |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
72 if (! (isvector (c) && isvector (r))) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
73 error ("hankel: C and R must be vectors"); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
74 elseif (r(1) != c(end)) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
75 warning ("hankel: column wins anti-diagonal conflict"); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
76 endif |
4 | 77 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
78 nr = length (c); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
79 nc = length (r); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
80 data = [c(:) ; r(2:end)(:)]; |
1396 | 81 |
4 | 82 endif |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
83 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
84 slices = cellslices (data, 1:nc, nr:1:nc+nr-1); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
85 retval = horzcat (slices{:}); |
4 | 86 |
87 endfunction | |
5731 | 88 |
7411 | 89 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
90 %!assert (hankel (1), [1]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
91 %!assert (hankel ([1, 2]), [1, 2; 2, 0]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
92 %!assert (hankel ([1, 2], [2; -1; -3]), [1, 2, -1; 2, -1, -3]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
93 %!assert (hankel (1:3), [1,2,3;2,3,0;3,0,0]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
94 %!assert (hankel (1:3,3:6), [1,2,3,4;2,3,4,5;3,4,5,6]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
95 %!assert (hankel (1:3,3:4), [1,2;2,3;3,4]) |
21443
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
96 %!warning <column wins anti-diagonal conflict> |
acd6e203031d
Alter BIST tests stop emitting warnings during runtests invocation.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
97 %! assert (hankel (1:3,4:6), [1,2,3;2,3,5;3,5,6]); |
7411 | 98 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
99 %!error hankel () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
100 %!error hankel (1, 2, 3) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
101 %!error <C must be a vector> hankel ([1, 2; 3, 4]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
102 %!error <C and R must be vectors> hankel (1:4, [1, 2; 3, 4]) |