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