Mercurial > hg > octave-nkf
annotate scripts/special-matrix/hankel.m @ 20770:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 2645f9ef8c88 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19790
diff
changeset
|
1 ## Copyright (C) 1993-2015 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 |
20372
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
23 ## (optionally) the last row @var{r}. |
3426 | 24 ## |
20372
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
25 ## 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:
19898
diff
changeset
|
26 ## @var{r}, the last element of @var{c} is used. If the second argument is |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
27 ## omitted, it is assumed to be a vector of zeros with the same size as @var{c}. |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
28 ## |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
29 ## 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:
19898
diff
changeset
|
30 ## has the elements |
3369 | 31 ## @tex |
32 ## $$ | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
33 ## H(i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr} |
3369 | 34 ## $$ |
35 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
36 ## @ifnottex |
3426 | 37 ## |
3369 | 38 ## @example |
39 ## @group | |
4922 | 40 ## H(i,j) = c(i+j-1), i+j-1 <= m; |
41 ## H(i,j) = r(i+j-m), otherwise | |
3369 | 42 ## @end group |
43 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
44 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
45 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 ## @seealso{hadamard, toeplitz} |
3369 | 47 ## @end deftypefn |
4 | 48 |
2314 | 49 ## Author: jwe |
50 | |
2311 | 51 function retval = hankel (c, r) |
4 | 52 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
53 if (nargin < 1 || nargin > 2) |
6046 | 54 print_usage (); |
4 | 55 endif |
56 | |
2325 | 57 if (nargin == 1) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
58 |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
59 if (! isvector (c)) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
60 error ("hankel: C must be a vector"); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
61 endif |
1396 | 62 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
63 nr = length (c); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
64 nc = nr; |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
65 data = [c(:) ; zeros(nr, 1)]; |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
66 |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
67 else |
4 | 68 |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
69 if (! (isvector (c) && isvector (r))) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
70 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
|
71 elseif (r(1) != c(end)) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
72 warning ("hankel: column wins anti-diagonal conflict"); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
73 endif |
4 | 74 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
75 nr = length (c); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
76 nc = length (r); |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
77 data = [c(:) ; r(2:end)(:)]; |
1396 | 78 |
4 | 79 endif |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
80 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
81 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
|
82 retval = horzcat (slices{:}); |
4 | 83 |
84 endfunction | |
5731 | 85 |
7411 | 86 |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
87 %!assert (hankel (1), [1]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
88 %!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
|
89 %!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
|
90 %!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
|
91 %!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
|
92 %!assert (hankel (1:3,3:4), [1,2;2,3;3,4]) |
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
93 %!assert (hankel (1:3,4:6), [1,2,3;2,3,5;3,5,6]) |
7411 | 94 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
95 %!error hankel () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
96 %!error hankel (1, 2, 3) |
13888
c78ac846fcbc
hankel.m: Recode for 3.5X speedup
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
97 %!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
|
98 %!error <C and R must be vectors> hankel (1:4, [1, 2; 3, 4]) |
7411 | 99 |