Mercurial > octave
annotate scripts/special-matrix/gallery.m @ 31551:fd29c7a50a78 stable
maint: use commas, semicolons consistently with Octave conventions.
* makeValidName.m: Remove %!test and move BIST %!asserts to column 1.
* base64decode.m, base64encode.m, which.m, logm.m, uniquetol.m, perms.m:
Delete semicolon (';') at end of %!assert BIST.
* lin2mu.m, interp2.m, interpn.m, lsqnonneg.m, pqpnonneg.m, uniquetol.m,
betainc.m, normalize.m: Add semicolon (';') to end of assert statement within
%!test BIST.
* __memoize__.m, tar_is_bsd.m, publish.m: Add semicolon (';') to line with
keyword "persistent".
* stft.m: Use comma (',') after "case" keyword when code immediately follows.
* gallery.m: Align commas used in case statements in massive switch block.
Remove unnecessary parentheses around a numeric case argument.
* ranks.m: Remove semicolon (';') from case statemnt argument.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 26 Nov 2022 06:32:08 -0800 |
parents | c8ad083a5802 |
children | 597f3ee61a48 |
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:
30379
diff
changeset
|
3 ## Copyright (C) 1989-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
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/>. |
16634 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23384
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
16634 | 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:
23384
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. |
16634 | 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. |
16634 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
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:
23384
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 ######################################################################## |
16634 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
27 ## @deftypefn {} {} gallery (@var{name}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
28 ## @deftypefnx {} {} gallery (@var{name}, @var{args}) |
16634 | 29 ## Create interesting matrices for testing. |
30 ## | |
31 ## @end deftypefn | |
32 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
33 ## @deftypefn {} {@var{c} =} gallery ("cauchy", @var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
34 ## @deftypefnx {} {@var{c} =} gallery ("cauchy", @var{x}, @var{y}) |
16634 | 35 ## Create a Cauchy matrix. |
36 ## | |
37 ## @end deftypefn | |
38 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
39 ## @deftypefn {} {@var{c} =} gallery ("chebspec", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
40 ## @deftypefnx {} {@var{c} =} gallery ("chebspec", @var{n}, @var{k}) |
16634 | 41 ## Create a Chebyshev spectral differentiation matrix. |
42 ## | |
43 ## @end deftypefn | |
44 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
45 ## @deftypefn {} {@var{c} =} gallery ("chebvand", @var{p}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
46 ## @deftypefnx {} {@var{c} =} gallery ("chebvand", @var{m}, @var{p}) |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
47 ## Create a @nospell{Vandermonde}-like matrix for the Chebyshev polynomials. |
16634 | 48 ## |
49 ## @end deftypefn | |
50 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
51 ## @deftypefn {} {@var{a} =} gallery ("chow", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
52 ## @deftypefnx {} {@var{a} =} gallery ("chow", @var{n}, @var{alpha}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
53 ## @deftypefnx {} {@var{a} =} gallery ("chow", @var{n}, @var{alpha}, @var{delta}) |
16634 | 54 ## Create a Chow matrix -- a singular Toeplitz lower Hessenberg matrix. |
55 ## | |
56 ## @end deftypefn | |
57 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
58 ## @deftypefn {} {@var{c} =} gallery ("circul", @var{v}) |
16634 | 59 ## Create a circulant matrix. |
60 ## | |
61 ## @end deftypefn | |
62 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
63 ## @deftypefn {} {@var{a} =} gallery ("clement", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
64 ## @deftypefnx {} {@var{a} =} gallery ("clement", @var{n}, @var{k}) |
16634 | 65 ## Create a tridiagonal matrix with zero diagonal entries. |
66 ## | |
67 ## @end deftypefn | |
68 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
69 ## @deftypefn {} {@var{c} =} gallery ("compar", @var{a}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
70 ## @deftypefnx {} {@var{c} =} gallery ("compar", @var{a}, @var{k}) |
16634 | 71 ## Create a comparison matrix. |
72 ## | |
73 ## @end deftypefn | |
74 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
75 ## @deftypefn {} {@var{a} =} gallery ("condex", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
76 ## @deftypefnx {} {@var{a} =} gallery ("condex", @var{n}, @var{k}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
77 ## @deftypefnx {} {@var{a} =} gallery ("condex", @var{n}, @var{k}, @var{theta}) |
27931
0fa21907e54c
doc: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
78 ## Create a @nospell{"counterexample"} matrix to a condition estimator. |
16634 | 79 ## |
80 ## @end deftypefn | |
81 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
82 ## @deftypefn {} {@var{a} =} gallery ("cycol", [@var{m} @var{n}]) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
83 ## @deftypefnx {} {@var{a} =} gallery ("cycol", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
84 ## @deftypefnx {} {@var{a} =} gallery (@dots{}, @var{k}) |
16634 | 85 ## Create a matrix whose columns repeat cyclically. |
86 ## | |
87 ## @end deftypefn | |
88 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
89 ## @deftypefn {} {[@var{c}, @var{d}, @var{e}] =} gallery ("dorr", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
90 ## @deftypefnx {} {[@var{c}, @var{d}, @var{e}] =} gallery ("dorr", @var{n}, @var{theta}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
91 ## @deftypefnx {} {@var{a} =} gallery ("dorr", @dots{}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
92 ## Create a diagonally dominant, ill-conditioned, tridiagonal matrix. |
16634 | 93 ## |
94 ## @end deftypefn | |
95 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
96 ## @deftypefn {} {@var{a} =} gallery ("dramadah", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
97 ## @deftypefnx {} {@var{a} =} gallery ("dramadah", @var{n}, @var{k}) |
16634 | 98 ## Create a (0, 1) matrix whose inverse has large integer entries. |
99 ## | |
100 ## @end deftypefn | |
101 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
102 ## @deftypefn {} {@var{a} =} gallery ("fiedler", @var{c}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
103 ## Create a symmetric @nospell{Fiedler} matrix. |
16634 | 104 ## |
105 ## @end deftypefn | |
106 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
107 ## @deftypefn {} {@var{a} =} gallery ("forsythe", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
108 ## @deftypefnx {} {@var{a} =} gallery ("forsythe", @var{n}, @var{alpha}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
109 ## @deftypefnx {} {@var{a} =} gallery ("forsythe", @var{n}, @var{alpha}, @var{lambda}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
110 ## Create a @nospell{Forsythe} matrix (a perturbed Jordan block). |
16634 | 111 ## |
112 ## @end deftypefn | |
113 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
114 ## @deftypefn {} {@var{f} =} gallery ("frank", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
115 ## @deftypefnx {} {@var{f} =} gallery ("frank", @var{n}, @var{k}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
116 ## Create a Frank matrix (ill-conditioned eigenvalues). |
16634 | 117 ## |
118 ## @end deftypefn | |
119 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
120 ## @deftypefn {} {@var{c} =} gallery ("gcdmat", @var{n}) |
16634 | 121 ## Create a greatest common divisor matrix. |
122 ## | |
123 ## @var{c} is an @var{n}-by-@var{n} matrix whose values correspond to the | |
124 ## greatest common divisor of its coordinate values, i.e., @var{c}(i,j) | |
125 ## correspond @code{gcd (i, j)}. | |
126 ## @end deftypefn | |
127 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
128 ## @deftypefn {} {@var{a} =} gallery ("gearmat", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
129 ## @deftypefnx {} {@var{a} =} gallery ("gearmat", @var{n}, @var{i}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
130 ## @deftypefnx {} {@var{a} =} gallery ("gearmat", @var{n}, @var{i}, @var{j}) |
16634 | 131 ## Create a Gear matrix. |
132 ## | |
133 ## @end deftypefn | |
134 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
135 ## @deftypefn {} {@var{g} =} gallery ("grcar", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
136 ## @deftypefnx {} {@var{g} =} gallery ("grcar", @var{n}, @var{k}) |
16634 | 137 ## Create a Toeplitz matrix with sensitive eigenvalues. |
138 ## | |
139 ## @end deftypefn | |
140 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
141 ## @deftypefn {} {@var{a} =} gallery ("hanowa", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
142 ## @deftypefnx {} {@var{a} =} gallery ("hanowa", @var{n}, @var{d}) |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16766
diff
changeset
|
143 ## Create a matrix whose eigenvalues lie on a vertical line in the complex |
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16766
diff
changeset
|
144 ## plane. |
16634 | 145 ## |
146 ## @end deftypefn | |
147 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
148 ## @deftypefn {} {@var{v} =} gallery ("house", @var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
149 ## @deftypefnx {} {[@var{v}, @var{beta}] =} gallery ("house", @var{x}) |
16634 | 150 ## Create a householder matrix. |
151 ## | |
152 ## @end deftypefn | |
153 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
154 ## @deftypefn {} {@var{a} =} gallery ("integerdata", @var{imax}, [@var{M} @var{N} @dots{}], @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
155 ## @deftypefnx {} {@var{a} =} gallery ("integerdata", @var{imax}, @var{M}, @var{N}, @dots{}, @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
156 ## @deftypefnx {} {@var{a} =} gallery ("integerdata", [@var{imin}, @var{imax}], [@var{M} @var{N} @dots{}], @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
157 ## @deftypefnx {} {@var{a} =} gallery ("integerdata", [@var{imin}, @var{imax}], @var{M}, @var{N}, @dots{}, @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
158 ## @deftypefnx {} {@var{a} =} gallery ("integerdata", @dots{}, "@var{class}") |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
159 ## Create a matrix with random integers in the range [1, @var{imax}]. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
160 ## If @var{imin} is given then the integers are in the range |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
161 ## [@var{imin}, @var{imax}]. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
162 ## |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
163 ## The second input is a matrix of dimensions describing the size of the |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
164 ## output. The dimensions can also be input as comma-separated arguments. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
165 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
166 ## The input @var{j} is an integer index in the range [0, 2^32-1]. The values |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
167 ## of the output matrix are always exactly the same (reproducibility) for a |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
168 ## given size input and @var{j} index. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
169 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
170 ## The final optional argument determines the class of the resulting matrix. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
171 ## Possible values for @var{class}: @qcode{"uint8"}, @qcode{"uint16"}, |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
172 ## @qcode{"uint32"}, @qcode{"int8"}, @qcode{"int16"}, int32", @qcode{"single"}, |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
173 ## @qcode{"double"}. The default is @qcode{"double"}. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
174 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
175 ## @end deftypefn |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
176 ## |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
177 ## @deftypefn {} {@var{a} =} gallery ("invhess", @var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
178 ## @deftypefnx {} {@var{a} =} gallery ("invhess", @var{x}, @var{y}) |
16634 | 179 ## Create the inverse of an upper Hessenberg matrix. |
180 ## | |
181 ## @end deftypefn | |
182 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
183 ## @deftypefn {} {@var{a} =} gallery ("invol", @var{n}) |
16634 | 184 ## Create an involutory matrix. |
185 ## | |
186 ## @end deftypefn | |
187 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
188 ## @deftypefn {} {@var{a} =} gallery ("ipjfact", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
189 ## @deftypefnx {} {@var{a} =} gallery ("ipjfact", @var{n}, @var{k}) |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
190 ## Create a Hankel matrix with factorial elements. |
16634 | 191 ## |
192 ## @end deftypefn | |
193 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
194 ## @deftypefn {} {@var{a} =} gallery ("jordbloc", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
195 ## @deftypefnx {} {@var{a} =} gallery ("jordbloc", @var{n}, @var{lambda}) |
16634 | 196 ## Create a Jordan block. |
197 ## | |
198 ## @end deftypefn | |
199 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
200 ## @deftypefn {} {@var{u} =} gallery ("kahan", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
201 ## @deftypefnx {} {@var{u} =} gallery ("kahan", @var{n}, @var{theta}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
202 ## @deftypefnx {} {@var{u} =} gallery ("kahan", @var{n}, @var{theta}, @var{pert}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
203 ## Create a @nospell{Kahan} matrix (upper trapezoidal). |
16634 | 204 ## |
205 ## @end deftypefn | |
206 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
207 ## @deftypefn {} {@var{a} =} gallery ("kms", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
208 ## @deftypefnx {} {@var{a} =} gallery ("kms", @var{n}, @var{rho}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
209 ## Create a @nospell{Kac-Murdock-Szego} Toeplitz matrix. |
16634 | 210 ## |
211 ## @end deftypefn | |
212 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
213 ## @deftypefn {} {@var{b} =} gallery ("krylov", @var{a}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
214 ## @deftypefnx {} {@var{b} =} gallery ("krylov", @var{a}, @var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
215 ## @deftypefnx {} {@var{b} =} gallery ("krylov", @var{a}, @var{x}, @var{j}) |
16634 | 216 ## Create a Krylov matrix. |
217 ## | |
218 ## @end deftypefn | |
219 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
220 ## @deftypefn {} {@var{a} =} gallery ("lauchli", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
221 ## @deftypefnx {} {@var{a} =} gallery ("lauchli", @var{n}, @var{mu}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
222 ## Create a @nospell{Lauchli} matrix (rectangular). |
16634 | 223 ## |
224 ## @end deftypefn | |
225 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
226 ## @deftypefn {} {@var{a} =} gallery ("lehmer", @var{n}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
227 ## Create a @nospell{Lehmer} matrix (symmetric positive definite). |
16634 | 228 ## |
229 ## @end deftypefn | |
230 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
231 ## @deftypefn {} {@var{t} =} gallery ("lesp", @var{n}) |
16634 | 232 ## Create a tridiagonal matrix with real, sensitive eigenvalues. |
233 ## | |
234 ## @end deftypefn | |
235 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
236 ## @deftypefn {} {@var{a} =} gallery ("lotkin", @var{n}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
237 ## Create a @nospell{Lotkin} matrix. |
16634 | 238 ## |
239 ## @end deftypefn | |
240 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
241 ## @deftypefn {} {@var{a} =} gallery ("minij", @var{n}) |
16634 | 242 ## Create a symmetric positive definite matrix MIN(i,j). |
243 ## | |
244 ## @end deftypefn | |
245 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
246 ## @deftypefn {} {@var{a} =} gallery ("moler", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
247 ## @deftypefnx {} {@var{a} =} gallery ("moler", @var{n}, @var{alpha}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
248 ## Create a @nospell{Moler} matrix (symmetric positive definite). |
16634 | 249 ## |
250 ## @end deftypefn | |
251 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
252 ## @deftypefn {} {[@var{a}, @var{t}] =} gallery ("neumann", @var{n}) |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
253 ## Create a singular matrix from the discrete @nospell{Neumann} problem |
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
254 ## (sparse). |
16634 | 255 ## |
256 ## @end deftypefn | |
257 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
258 ## @deftypefn {} {@var{a} =} gallery ("normaldata", [@var{M} @var{N} @dots{}], @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
259 ## @deftypefnx {} {@var{a} =} gallery ("normaldata", @var{M}, @var{N}, @dots{}, @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
260 ## @deftypefnx {} {@var{a} =} gallery ("normaldata", @dots{}, "@var{class}") |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
261 ## Create a matrix with random samples from the standard normal distribution |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
262 ## (mean = 0, std = 1). |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
263 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
264 ## The first input is a matrix of dimensions describing the size of the output. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
265 ## The dimensions can also be input as comma-separated arguments. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
266 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
267 ## The input @var{j} is an integer index in the range [0, 2^32-1]. The values |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
268 ## of the output matrix are always exactly the same (reproducibility) for a |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
269 ## given size input and @var{j} index. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
270 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
271 ## The final optional argument determines the class of the resulting matrix. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
272 ## Possible values for @var{class}: @qcode{"single"}, @qcode{"double"}. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
273 ## The default is @qcode{"double"}. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
274 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
275 ## @end deftypefn |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
276 ## |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
277 ## @deftypefn {} {@var{q} =} gallery ("orthog", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
278 ## @deftypefnx {} {@var{q} =} gallery ("orthog", @var{n}, @var{k}) |
16634 | 279 ## Create orthogonal and nearly orthogonal matrices. |
280 ## | |
281 ## @end deftypefn | |
282 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
283 ## @deftypefn {} {@var{a} =} gallery ("parter", @var{n}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
284 ## Create a @nospell{Parter} matrix (a Toeplitz matrix with singular values |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
285 ## near pi). |
16634 | 286 ## |
287 ## @end deftypefn | |
288 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
289 ## @deftypefn {} {@var{p} =} gallery ("pei", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
290 ## @deftypefnx {} {@var{p} =} gallery ("pei", @var{n}, @var{alpha}) |
16634 | 291 ## Create a Pei matrix. |
292 ## | |
293 ## @end deftypefn | |
294 ## | |
27085
47b81207cb32
gallery.m: Fix typo in docstring for poisson (bug #56267).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
295 ## @deftypefn {} {@var{a} =} gallery ("poisson", @var{n}) |
16634 | 296 ## Create a block tridiagonal matrix from Poisson's equation (sparse). |
297 ## | |
298 ## @end deftypefn | |
299 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
300 ## @deftypefn {} {@var{a} =} gallery ("prolate", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
301 ## @deftypefnx {} {@var{a} =} gallery ("prolate", @var{n}, @var{w}) |
16634 | 302 ## Create a prolate matrix (symmetric, ill-conditioned Toeplitz matrix). |
303 ## | |
304 ## @end deftypefn | |
305 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
306 ## @deftypefn {} {@var{h} =} gallery ("randhess", @var{x}) |
16634 | 307 ## Create a random, orthogonal upper Hessenberg matrix. |
308 ## | |
309 ## @end deftypefn | |
310 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
311 ## @deftypefn {} {@var{a} =} gallery ("rando", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
312 ## @deftypefnx {} {@var{a} =} gallery ("rando", @var{n}, @var{k}) |
16634 | 313 ## Create a random matrix with elements -1, 0 or 1. |
314 ## | |
315 ## @end deftypefn | |
316 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
317 ## @deftypefn {} {@var{a} =} gallery ("randsvd", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
318 ## @deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
319 ## @deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
320 ## @deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode}, @var{kl}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
321 ## @deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode}, @var{kl}, @var{ku}) |
16634 | 322 ## Create a random matrix with pre-assigned singular values. |
323 ## | |
324 ## @end deftypefn | |
325 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
326 ## @deftypefn {} {@var{a} =} gallery ("redheff", @var{n}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
327 ## Create a zero and ones matrix of @nospell{Redheffer} associated with the |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
328 ## Riemann hypothesis. |
16634 | 329 ## |
330 ## @end deftypefn | |
331 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
332 ## @deftypefn {} {@var{a} =} gallery ("riemann", @var{n}) |
16634 | 333 ## Create a matrix associated with the Riemann hypothesis. |
334 ## | |
335 ## @end deftypefn | |
336 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
337 ## @deftypefn {} {@var{a} =} gallery ("ris", @var{n}) |
16634 | 338 ## Create a symmetric Hankel matrix. |
339 ## | |
340 ## @end deftypefn | |
341 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
342 ## @deftypefn {} {@var{a} =} gallery ("smoke", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
343 ## @deftypefnx {} {@var{a} =} gallery ("smoke", @var{n}, @var{k}) |
27931
0fa21907e54c
doc: grammarcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
344 ## Create a complex matrix, with a @nospell{"smoke ring"} pseudospectrum. |
16634 | 345 ## |
346 ## @end deftypefn | |
347 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
348 ## @deftypefn {} {@var{t} =} gallery ("toeppd", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
349 ## @deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
350 ## @deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m}, @var{w}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
351 ## @deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m}, @var{w}, @var{theta}) |
16634 | 352 ## Create a symmetric positive definite Toeplitz matrix. |
353 ## | |
354 ## @end deftypefn | |
355 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
356 ## @deftypefn {} {@var{p} =} gallery ("toeppen", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
357 ## @deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
358 ## @deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
359 ## @deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
360 ## @deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c}, @var{d}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
361 ## @deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c}, @var{d}, @var{e}) |
16634 | 362 ## Create a pentadiagonal Toeplitz matrix (sparse). |
363 ## | |
364 ## @end deftypefn | |
365 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
366 ## @deftypefn {} {@var{a} =} gallery ("tridiag", @var{x}, @var{y}, @var{z}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
367 ## @deftypefnx {} {@var{a} =} gallery ("tridiag", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
368 ## @deftypefnx {} {@var{a} =} gallery ("tridiag", @var{n}, @var{c}, @var{d}, @var{e}) |
16634 | 369 ## Create a tridiagonal matrix (sparse). |
370 ## | |
371 ## @end deftypefn | |
372 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
373 ## @deftypefn {} {@var{t} =} gallery ("triw", @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
374 ## @deftypefnx {} {@var{t} =} gallery ("triw", @var{n}, @var{alpha}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
375 ## @deftypefnx {} {@var{t} =} gallery ("triw", @var{n}, @var{alpha}, @var{k}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
376 ## Create an upper triangular matrix discussed by |
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
377 ## @nospell{Kahan, Golub, and Wilkinson}. |
16634 | 378 ## |
379 ## @end deftypefn | |
380 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
381 ## @deftypefn {} {@var{a} =} gallery ("uniformdata", [@var{M} @var{N} @dots{}], @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
382 ## @deftypefnx {} {@var{a} =} gallery ("uniformdata", @var{M}, @var{N}, @dots{}, @var{j}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
383 ## @deftypefnx {} {@var{a} =} gallery ("uniformdata", @dots{}, "@var{class}") |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
384 ## Create a matrix with random samples from the standard uniform distribution |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
385 ## (range [0,1]). |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
386 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
387 ## The first input is a matrix of dimensions describing the size of the output. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
388 ## The dimensions can also be input as comma-separated arguments. |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
389 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
390 ## The input @var{j} is an integer index in the range [0, 2^32-1]. The values |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
391 ## of the output matrix are always exactly the same (reproducibility) for a |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
392 ## given size input and @var{j} index. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
393 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
394 ## The final optional argument determines the class of the resulting matrix. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
395 ## Possible values for @var{class}: @qcode{"single"}, @qcode{"double"}. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17199
diff
changeset
|
396 ## The default is @qcode{"double"}. |
16982
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
397 ## |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
398 ## @end deftypefn |
badc46a0a230
doc: Document 'uniformdata', 'normaldata', 'integerdata' matrices in gallery.m.
Rik <rik@octave.org>
parents:
16980
diff
changeset
|
399 ## |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
400 ## @deftypefn {} {@var{a} =} gallery ("wathen", @var{nx}, @var{ny}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
401 ## @deftypefnx {} {@var{a} =} gallery ("wathen", @var{nx}, @var{ny}, @var{k}) |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
18846
diff
changeset
|
402 ## Create the @nospell{Wathen} matrix. |
16634 | 403 ## |
404 ## @end deftypefn | |
405 ## | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20299
diff
changeset
|
406 ## @deftypefn {} {[@var{a}, @var{b}] =} gallery ("wilk", @var{n}) |
16634 | 407 ## Create various specific matrices devised/discussed by Wilkinson. |
408 ## | |
409 ## @end deftypefn | |
410 | |
411 ## Code for most of the individual matrices (except binomial, gcdmat, | |
412 ## integerdata, leslie, normaldata, randcolu, randcorr, randjorth, sampling, | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
413 ## uniformdata) by Nicholas J. Higham <Nicholas.J.Higham@manchester.ac.uk> |
16634 | 414 ## Adapted for Octave and into single gallery function by Carnë Draug |
415 | |
28904
930cb0ae24fd
maint: Don't enclose single output of function with '[]'.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
416 function varargout = gallery (name, varargin) |
16634 | 417 |
418 if (nargin < 1) | |
419 print_usage (); | |
420 elseif (! ischar (name)) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
421 error ("gallery: NAME must be a string"); |
16634 | 422 endif |
423 | |
424 ## NOTE: there isn't a lot of input check in the individual functions | |
425 ## that actually build the functions. This is by design. The original | |
426 ## code by Higham did not perform it and was propagated to Matlab, so | |
427 ## for compatibility, we also don't make it. For example, arguments | |
428 ## that behave as switches, and in theory accepting a value of 0 or 1, | |
429 ## will use a value of 0, for any value other than 1 (only check made | |
430 ## is if the value is equal to 1). It will often also accept string | |
431 ## values instead of numeric. Only input check added was where it | |
432 ## would be causing an error anyway. | |
433 | |
434 ## we will always want to return at least 1 output | |
435 n_out = nargout; | |
436 if (n_out == 0) | |
437 n_out = 1; | |
438 endif | |
439 | |
440 switch (tolower (name)) | |
441 case "binomial" | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
442 error ("gallery: matrix %s not implemented", name); |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
443 case "cauchy" , [varargout{1:n_out}] = cauchy (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
444 case "chebspec" , [varargout{1:n_out}] = chebspec (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
445 case "chebvand" , [varargout{1:n_out}] = chebvand (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
446 case "chow" , [varargout{1:n_out}] = chow (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
447 case "circul" , [varargout{1:n_out}] = circul (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
448 case "clement" , [varargout{1:n_out}] = clement (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
449 case "compar" , [varargout{1:n_out}] = compar (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
450 case "condex" , [varargout{1:n_out}] = condex (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
451 case "cycol" , [varargout{1:n_out}] = cycol (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
452 case "dorr" , [varargout{1:n_out}] = dorr (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
453 case "dramadah" , [varargout{1:n_out}] = dramadah (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
454 case "fiedler" , [varargout{1:n_out}] = fiedler (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
455 case "forsythe" , [varargout{1:n_out}] = forsythe (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
456 case "frank" , [varargout{1:n_out}] = frank (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
457 case "gearmat" , [varargout{1:n_out}] = gearmat (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
458 case "gcdmat" , [varargout{1:n_out}] = gcdmat (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
459 case "grcar" , [varargout{1:n_out}] = grcar (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
460 case "hanowa" , [varargout{1:n_out}] = hanowa (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
461 case "house" , [varargout{1:n_out}] = house (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
462 case "integerdata" , [varargout{1:n_out}] = integerdata (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
463 case "invhess" , [varargout{1:n_out}] = invhess (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
464 case "invol" , [varargout{1:n_out}] = invol (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
465 case "ipjfact" , [varargout{1:n_out}] = ipjfact (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
466 case "jordbloc" , [varargout{1:n_out}] = jordbloc (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
467 case "kahan" , [varargout{1:n_out}] = kahan (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
468 case "kms" , [varargout{1:n_out}] = kms (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
469 case "krylov" , [varargout{1:n_out}] = krylov (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
470 case "lauchli" , [varargout{1:n_out}] = lauchli (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
471 case "lehmer" , [varargout{1:n_out}] = lehmer (varargin{:}); |
16634 | 472 case "leslie" |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
473 error ("gallery: matrix %s not implemented", name); |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
474 case "lesp" , [varargout{1:n_out}] = lesp (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
475 case "lotkin" , [varargout{1:n_out}] = lotkin (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
476 case "minij" , [varargout{1:n_out}] = minij (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
477 case "moler" , [varargout{1:n_out}] = moler (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
478 case "neumann" , [varargout{1:n_out}] = neumann (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
479 case "normaldata" , [varargout{1:n_out}] = normaldata (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
480 case "orthog" , [varargout{1:n_out}] = orthog (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
481 case "parter" , [varargout{1:n_out}] = parter (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
482 case "pei" , [varargout{1:n_out}] = pei (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
483 case "poisson" , [varargout{1:n_out}] = poisson (varargin{:}); |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
484 case "prolate" , [varargout{1:n_out}] = prolate (varargin{:}); |
16634 | 485 case "randcolu" |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
486 error ("gallery: matrix %s not implemented", name); |
16634 | 487 case "randcorr" |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
488 error ("gallery: matrix %s not implemented", name); |
16634 | 489 case "randhess" , [varargout{1:n_out}] = randhess (varargin{:}); |
490 case "randjorth" | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
491 error ("gallery: matrix %s not implemented", name); |
16634 | 492 case "rando" , [varargout{1:n_out}] = rando (varargin{:}); |
493 case "randsvd" , [varargout{1:n_out}] = randsvd (varargin{:}); | |
494 case "redheff" , [varargout{1:n_out}] = redheff (varargin{:}); | |
495 case "riemann" , [varargout{1:n_out}] = riemann (varargin{:}); | |
496 case "ris" , [varargout{1:n_out}] = ris (varargin{:}); | |
497 case "sampling" | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
498 error ("gallery: matrix %s not implemented", name); |
16634 | 499 case "smoke" , [varargout{1:n_out}] = smoke (varargin{:}); |
500 case "toeppd" , [varargout{1:n_out}] = toeppd (varargin{:}); | |
501 case "toeppen" , [varargout{1:n_out}] = toeppen (varargin{:}); | |
502 case "tridiag" , [varargout{1:n_out}] = tridiag (varargin{:}); | |
503 case "triw" , [varargout{1:n_out}] = triw (varargin{:}); | |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
504 case "uniformdata" , [varargout{1:n_out}] = uniformdata (varargin{:}); |
16634 | 505 case "wathen" , [varargout{1:n_out}] = wathen (varargin{:}); |
506 case "wilk" , [varargout{1:n_out}] = wilk (varargin{:}); | |
507 otherwise | |
508 error ("gallery: unknown matrix with NAME %s", name); | |
509 endswitch | |
510 | |
511 endfunction | |
512 | |
513 function C = cauchy (x, y) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
514 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
515 ## CAUCHY Cauchy matrix. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
516 ## C = CAUCHY(X, Y), where X, Y are N-vectors, is the N-by-N matrix |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
517 ## with C(i,j) = 1/(X(i)+Y(j)). By default, Y = X. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
518 ## Special case: if X is a scalar CAUCHY(X) is the same as CAUCHY(1:X). |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
519 ## Explicit formulas are known for DET(C) (which is nonzero if X and Y |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
520 ## both have distinct elements) and the elements of INV(C). |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
521 ## C is totally positive if 0 < X(1) < ... < X(N) and |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
522 ## 0 < Y(1) < ... < Y(N). |
16634 | 523 ## |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
524 ## References: |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
525 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
526 ## Society for Industrial and Applied Mathematics, Philadelphia, PA, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
527 ## USA, 1996; sec. 26.1. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
528 ## D.E. Knuth, The Art of Computer Programming, Volume 1, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
529 ## Fundamental Algorithms, second edition, Addison-Wesley, Reading, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
530 ## Massachusetts, 1973, p. 36. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
531 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
532 ## Linear Algebra and Appl., 149 (1991), pp. 1-18. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
533 ## O. Taussky and M. Marcus, Eigenvalues of finite matrices, in |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
534 ## Survey of Numerical Analysis, J. Todd, ed., McGraw-Hill, New York, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
535 ## pp. 279-313, 1962. (States the totally positive property on p. 295.) |
16634 | 536 |
537 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
538 error ("gallery: 1 or 2 arguments are required for cauchy matrix"); |
16634 | 539 elseif (! isnumeric (x)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
540 error ("gallery: X must be numeric for cauchy matrix"); |
16634 | 541 elseif (nargin == 2 && ! isnumeric (y)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
542 error ("gallery: Y must be numeric for cauchy matrix"); |
16634 | 543 endif |
544 | |
545 n = numel (x); | |
546 if (isscalar (x) && fix (x) == x) | |
547 n = x; | |
548 x = 1:n; | |
549 elseif (n > 1 && isvector (x)) | |
550 ## do nothing | |
551 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
552 error ("gallery: X be an integer or a vector for cauchy matrix"); |
16634 | 553 endif |
554 | |
555 if (nargin == 1) | |
556 y = x; | |
557 endif | |
558 | |
559 ## Ensure x and y are column vectors | |
560 x = x(:); | |
561 y = y(:); | |
562 if (numel (x) != numel (y)) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
563 error ("gallery: X and Y must be vectors of same length for cauchy matrix"); |
16634 | 564 endif |
565 | |
30326
cd7c824f3f22
eliminate use of .+ and .- operators in Octave sources
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
566 C = 1 ./ (x + y.'); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
567 |
16634 | 568 endfunction |
569 | |
570 function C = chebspec (n, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
571 |
16634 | 572 ## CHEBSPEC Chebyshev spectral differentiation matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
573 ## C = CHEBSPEC(N, K) is a Chebyshev spectral differentiation |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
574 ## matrix of order N. K = 0 (the default) or 1. |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
575 ## For K = 0 ('no boundary conditions'), C is nilpotent, with |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
576 ## C^N = 0 and it has the null vector ONES(N,1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
577 ## C is similar to a Jordan block of size N with eigenvalue zero. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
578 ## For K = 1, C is nonsingular and well-conditioned, and its eigenvalues |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
579 ## have negative real parts. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
580 ## For both K, the computed eigenvector matrix X from EIG is |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
581 ## ill-conditioned (MESH(REAL(X)) is interesting). |
16634 | 582 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
583 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
584 ## C. Canuto, M.Y. Hussaini, A. Quarteroni and T.A. Zang, Spectral |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
585 ## Methods in Fluid Dynamics, Springer-Verlag, Berlin, 1988; p. 69. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
586 ## L.N. Trefethen and M.R. Trummer, An instability phenomenon in |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
587 ## spectral methods, SIAM J. Numer. Anal., 24 (1987), pp. 1008-1023. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
588 ## D. Funaro, Computing the inverse of the Chebyshev collocation |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
589 ## derivative, SIAM J. Sci. Stat. Comput., 9 (1988), pp. 1050-1057. |
16634 | 590 |
591 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
592 error ("gallery: 1 to 2 arguments are required for chebspec matrix"); |
16634 | 593 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
594 error ("gallery: N must be an integer for chebspec matrix"); |
16634 | 595 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
596 error ("gallery: K must be a scalar for chebspec matrix"); |
16634 | 597 endif |
598 | |
599 ## k = 1 case obtained from k = 0 case with one bigger n. | |
600 switch (k) | |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
601 case 0, # do nothing |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
602 case 1, n = n + 1; |
16634 | 603 otherwise |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
604 error ("gallery: K should be either 0 or 1 for chebspec matrix"); |
16634 | 605 endswitch |
606 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
607 n -= 1; |
16634 | 608 C = zeros (n+1); |
609 | |
610 one = ones (n+1, 1); | |
611 x = cos ((0:n)' * (pi/n)); | |
612 d = ones (n+1, 1); | |
613 d(1) = 2; | |
614 d(n+1) = 2; | |
615 | |
616 ## eye(size(C)) on next line avoids div by zero. | |
617 C = (d * (one./d)') ./ (x*one'-one*x' + eye (size (C))); | |
618 | |
619 ## Now fix diagonal and signs. | |
620 C(1,1) = (2*n^2+1)/6; | |
621 for i = 2:n+1 | |
622 if (rem (i, 2) == 0) | |
623 C(:,i) = -C(:,i); | |
624 C(i,:) = -C(i,:); | |
625 endif | |
626 if (i < n+1) | |
627 C(i,i) = -x(i)/(2*(1-x(i)^2)); | |
628 else | |
629 C(n+1,n+1) = -C(1,1); | |
630 endif | |
631 endfor | |
632 | |
633 if (k == 1) | |
634 C = C(2:n+1,2:n+1); | |
635 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
636 |
16634 | 637 endfunction |
638 | |
639 function C = chebvand (m, p) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
640 |
16634 | 641 ## CHEBVAND Vandermonde-like matrix for the Chebyshev polynomials. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
642 ## C = CHEBVAND(P), where P is a vector, produces the (primal) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
643 ## Chebyshev Vandermonde matrix based on the points P, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
644 ## i.e., C(i,j) = T_{i-1}(P(j)), where T_{i-1} is the Chebyshev |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
645 ## polynomial of degree i-1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
646 ## CHEBVAND(M,P) is a rectangular version of CHEBVAND(P) with M rows. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
647 ## Special case: If P is a scalar then P equally spaced points on |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
648 ## [0,1] are used. |
16634 | 649 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
650 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
651 ## N.J. Higham, Stability analysis of algorithms for solving confluent |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
652 ## Vandermonde-like systems, SIAM J. Matrix Anal. Appl., 11 (1990), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
653 ## pp. 23-41. |
16634 | 654 |
655 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
656 error ("gallery: 1 or 2 arguments are required for chebvand matrix"); |
16634 | 657 endif |
658 | |
659 ## because the order of the arguments changes if nargin is 1 or 2 ... | |
660 | |
661 if (nargin == 1) | |
662 p = m; | |
663 endif | |
664 | |
665 n = numel (p); | |
666 if (! isnumeric (p)) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
667 error ("gallery: P must be numeric for chebvand matrix"); |
16634 | 668 elseif (isscalar (p) && fix (p) == p) |
669 n = p; | |
670 p = linspace (0, 1, n); | |
671 elseif (n > 1 && isvector (p)) | |
672 ## do nothing | |
673 endif | |
674 p = p(:).'; # Ensure p is a row vector. | |
675 | |
676 if (nargin == 1) | |
677 m = n; | |
678 elseif (! isnumeric (m) || ! isscalar (m)) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
679 error ("gallery: M must be a scalar for chebvand matrix"); |
16634 | 680 endif |
681 | |
682 C = ones (m, n); | |
683 if (m != 1) | |
684 C(2,:) = p; | |
685 ## Use Chebyshev polynomial recurrence. | |
686 for i = 3:m | |
687 C(i,:) = 2.*p.*C(i-1,:) - C(i-2,:); | |
688 endfor | |
689 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
690 |
16634 | 691 endfunction |
692 | |
693 function A = chow (n, alpha = 1, delta = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
694 |
16634 | 695 ## CHOW Chow matrix - a singular Toeplitz lower Hessenberg matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
696 ## A = CHOW(N, ALPHA, DELTA) is a Toeplitz lower Hessenberg matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
697 ## A = H(ALPHA) + DELTA*EYE, where H(i,j) = ALPHA^(i-j+1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
698 ## H(ALPHA) has p = FLOOR(N/2) zero eigenvalues, the rest being |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
699 ## 4*ALPHA*COS( k*PI/(N+2) )^2, k=1:N-p. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
700 ## Defaults: ALPHA = 1, DELTA = 0. |
16634 | 701 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
702 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
703 ## T.S. Chow, A class of Hessenberg matrices with known |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
704 ## eigenvalues and inverses, SIAM Review, 11 (1969), pp. 391-395. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
705 ## G. Fairweather, On the eigenvalues and eigenvectors of a class of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
706 ## Hessenberg matrices, SIAM Review, 13 (1971), pp. 220-221. |
16634 | 707 |
708 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
709 error ("gallery: 1 to 3 arguments are required for chow matrix"); |
16634 | 710 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
711 error ("gallery: N must be an integer for chow matrix"); |
16634 | 712 elseif (! isnumeric (alpha) || ! isscalar (alpha)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
713 error ("gallery: ALPHA must be a scalar for chow matrix"); |
16634 | 714 elseif (! isnumeric (delta) || ! isscalar (delta)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
715 error ("gallery: DELTA must be a scalar for chow matrix"); |
16634 | 716 endif |
717 | |
718 A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
719 |
16634 | 720 endfunction |
721 | |
722 function C = circul (v) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
723 |
16634 | 724 ## CIRCUL Circulant matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
725 ## C = CIRCUL(V) is the circulant matrix whose first row is V. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
726 ## (A circulant matrix has the property that each row is obtained |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
727 ## from the previous one by cyclically permuting the entries one step |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
728 ## forward; it is a special Toeplitz matrix in which the diagonals |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
729 ## 'wrap round'.) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
730 ## Special case: if V is a scalar then C = CIRCUL(1:V). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
731 ## The eigensystem of C (N-by-N) is known explicitly. If t is an Nth |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
732 ## root of unity, then the inner product of V with W = [1 t t^2 ... t^N] |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
733 ## is an eigenvalue of C, and W(N:-1:1) is an eigenvector of C. |
16634 | 734 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
735 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
736 ## P.J. Davis, Circulant Matrices, John Wiley, 1977. |
16634 | 737 |
738 if (nargin != 1) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
739 error ("gallery: 1 argument is required for circul matrix"); |
16634 | 740 elseif (! isnumeric (v)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
741 error ("gallery: V must be numeric for circul matrix"); |
16634 | 742 endif |
743 | |
16734
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
744 n = numel (v); |
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
745 if (isscalar (v) && fix (v) == v) |
16634 | 746 n = v; |
747 v = 1:n; | |
16734
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
748 elseif (n > 1 && isvector (v)) |
16634 | 749 ## do nothing |
750 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
751 error ("gallery: X must be a scalar or a vector for circul matrix"); |
16634 | 752 endif |
753 | |
754 v = v(:).'; # Make sure v is a row vector | |
755 C = toeplitz ([v(1) v(n:-1:2)], v); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
756 |
16634 | 757 endfunction |
758 | |
759 function A = clement (n, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
760 |
16634 | 761 ## CLEMENT Clement matrix - tridiagonal with zero diagonal entries. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
762 ## CLEMENT(N, K) is a tridiagonal matrix with zero diagonal entries |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
763 ## and known eigenvalues. It is singular if N is odd. About 64 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
764 ## percent of the entries of the inverse are zero. The eigenvalues |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
765 ## are plus and minus the numbers N-1, N-3, N-5, ..., (1 or 0). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
766 ## For K = 0 (the default) the matrix is unsymmetric, while for |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
767 ## K = 1 it is symmetric. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
768 ## CLEMENT(N, 1) is diagonally similar to CLEMENT(N). |
16634 | 769 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
770 ## Similar properties hold for TRIDIAG(X,Y,Z) where Y = ZEROS(N,1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
771 ## The eigenvalues still come in plus/minus pairs but they are not |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
772 ## known explicitly. |
16634 | 773 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
774 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
775 ## P.A. Clement, A class of triple-diagonal matrices for test |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
776 ## purposes, SIAM Review, 1 (1959), pp. 50-52. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
777 ## A. Edelman and E. Kostlan, The road from Kac's matrix to Kac's |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
778 ## random polynomials. In John~G. Lewis, editor, Proceedings of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
779 ## the Fifth SIAM Conference on Applied Linear Algebra Society |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
780 ## for Industrial and Applied Mathematics, Philadelphia, 1994, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
781 ## pp. 503-507. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
782 ## O. Taussky and J. Todd, Another look at a matrix of Mark Kac, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
783 ## Linear Algebra and Appl., 150 (1991), pp. 341-360. |
16634 | 784 |
785 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
786 error ("gallery: 1 or 2 arguments are required for clement matrix"); |
16634 | 787 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
788 error ("gallery: N must be an integer for clement matrix"); |
16634 | 789 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
790 error ("gallery: K must be a numeric scalar for clement matrix"); |
16634 | 791 endif |
792 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
793 n -= 1; |
16634 | 794 x = n:-1:1; |
795 z = 1:n; | |
796 | |
797 if (k == 0) | |
798 A = diag (x, -1) + diag (z, 1); | |
799 elseif (k == 1) | |
800 y = sqrt (x.*z); | |
801 A = diag (y, -1) + diag (y, 1); | |
802 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
803 error ("gallery: K must have a value of 0 or 1 for clement matrix"); |
16634 | 804 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
805 |
16634 | 806 endfunction |
807 | |
808 function C = compar (A, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
809 |
16634 | 810 ## COMP Comparison matrices. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
811 ## COMP(A) is DIAG(B) - TRIL(B,-1) - TRIU(B,1), where B = ABS(A). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
812 ## COMP(A, 1) is A with each diagonal element replaced by its |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
813 ## absolute value, and each off-diagonal element replaced by minus |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
814 ## the absolute value of the largest element in absolute value in |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
815 ## its row. However, if A is triangular COMP(A, 1) is too. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
816 ## COMP(A, 0) is the same as COMP(A). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
817 ## COMP(A) is often denoted by M(A) in the literature. |
16634 | 818 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
819 ## Reference (e.g.): |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
820 ## N.J. Higham, A survey of condition number estimation for |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
821 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. |
16634 | 822 |
823 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
824 error ("gallery: 1 or 2 arguments are required for compar matrix"); |
16634 | 825 elseif (! isnumeric (A) || ndims (A) != 2) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
826 error ("gallery: A must be a 2-D matrix for compar matrix"); |
16634 | 827 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
828 error ("gallery: K must be a numeric scalar for compar matrix"); |
16634 | 829 endif |
830 | |
831 [m, n] = size (A); | |
832 p = min (m, n); | |
833 | |
834 if (k == 0) | |
835 ## This code uses less temporary storage than | |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
836 ## the 'high level' definition above. |
16634 | 837 C = -abs (A); |
838 for j = 1:p | |
839 C(j,j) = abs (A(j,j)); | |
840 endfor | |
841 | |
842 elseif (k == 1) | |
843 C = A'; | |
844 for j = 1:p | |
845 C(k,k) = 0; | |
846 endfor | |
847 mx = max (abs (C)); | |
848 C = -mx'*ones (1, n); | |
849 for j = 1:p | |
850 C(j,j) = abs (A(j,j)); | |
851 endfor | |
852 if (all (A == tril (A))), C = tril (C); endif | |
853 if (all (A == triu (A))), C = triu (C); endif | |
854 | |
855 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
856 error ("gallery: K must have a value of 0 or 1 for compar matrix"); |
16634 | 857 endif |
858 | |
859 endfunction | |
860 | |
861 function A = condex (n, k = 4, theta = 100) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
862 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
863 ## CONDEX 'Counterexamples' to matrix condition number estimators. |
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
864 ## CONDEX(N, K, THETA) is a 'counterexample' matrix to a condition |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
865 ## estimator. It has order N and scalar parameter THETA (default 100). |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
866 ## If N is not equal to the 'natural' size of the matrix then |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
867 ## the matrix is padded out with an identity matrix to order N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
868 ## The matrix, its natural size, and the estimator to which it applies |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
869 ## are specified by K (default K = 4) as follows: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
870 ## K = 1: 4-by-4, LINPACK (RCOND) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
871 ## K = 2: 3-by-3, LINPACK (RCOND) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
872 ## K = 3: arbitrary, LINPACK (RCOND) (independent of THETA) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
873 ## K = 4: N >= 4, SONEST (Higham 1988) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
874 ## (Note that in practice the K = 4 matrix is not usually a |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
875 ## counterexample because of the rounding errors in forming it.) |
16634 | 876 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
877 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
878 ## A.K. Cline and R.K. Rew, A set of counter-examples to three |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
879 ## condition number estimators, SIAM J. Sci. Stat. Comput., |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
880 ## 4 (1983), pp. 602-611. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
881 ## N.J. Higham, FORTRAN codes for estimating the one-norm of a real or |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
882 ## complex matrix, with applications to condition estimation |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
883 ## (Algorithm 674), ACM Trans. Math. Soft., 14 (1988), pp. 381-396. |
16634 | 884 |
885 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
886 error ("gallery: 1 to 3 arguments are required for condex matrix"); |
16634 | 887 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
888 error ("gallery: N must be an integer for condex matrix"); |
16634 | 889 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
890 error ("gallery: K must be a numeric scalar for condex matrix"); |
16634 | 891 elseif (! isnumeric (theta) || ! isscalar (theta)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
892 error ("gallery: THETA must be a numeric scalar for condex matrix"); |
16634 | 893 endif |
894 | |
895 if (k == 1) # Cline and Rew (1983), Example B. | |
896 A = [1 -1 -2*theta 0 | |
897 0 1 theta -theta | |
898 0 1 1+theta -(theta+1) | |
899 0 0 0 theta]; | |
900 | |
901 elseif (k == 2) # Cline and Rew (1983), Example C. | |
902 A = [1 1-2/theta^2 -2 | |
903 0 1/theta -1/theta | |
904 0 0 1]; | |
905 | |
906 elseif (k == 3) # Cline and Rew (1983), Example D. | |
907 A = gallery ("triw", n, -1)'; | |
908 A(n,n) = -1; | |
909 | |
910 elseif (k == 4) # Higham (1988), p. 390. | |
911 x = ones (n, 3); # First col is e | |
912 x(2:n,2) = zeros (n-1, 1); # Second col is e(1) | |
913 | |
914 ## Third col is special vector b in SONEST | |
915 x(:, 3) = (-1).^[0:n-1]' .* ( 1 + [0:n-1]'/(n-1) ); | |
916 | |
917 Q = orth (x); # Q*Q' is now the orthogonal projector onto span(e(1),e,b)). | |
918 P = eye (n) - Q*Q'; | |
919 A = eye (n) + theta*P; | |
920 | |
921 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
922 error ("gallery: unknown estimator K '%d' for condex matrix", k); |
16634 | 923 endif |
924 | |
925 ## Pad out with identity as necessary. | |
926 m = columns (A); | |
927 if (m < n) | |
928 for i = n:-1:m+1 | |
929 A(i,i) = 1; | |
930 endfor | |
931 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
932 |
16634 | 933 endfunction |
934 | |
20298
ababbe103048
gallery: allow N to be a 2 element vectors for cycol matrices.
Carnë Draug <carandraug@octave.org>
parents:
20297
diff
changeset
|
935 function A = cycol (n, k = max (round (n(end)/4), 1)) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
936 |
16634 | 937 ## CYCOL Matrix whose columns repeat cyclically. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
938 ## A = CYCOL([M N], K) is an M-by-N matrix of the form A = B(1:M,1:N) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
939 ## where B = [C C C...] and C = RANDN(M, K). Thus A's columns repeat |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
940 ## cyclically, and A has rank at most K. K need not divide N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
941 ## K defaults to ROUND(N/4). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
942 ## CYCOL(N, K), where N is a scalar, is the same as CYCOL([N N], K). |
16634 | 943 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
944 ## This type of matrix can lead to underflow problems for Gaussian |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
945 ## elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989). |
16634 | 946 |
947 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
948 error ("gallery: 1 or 2 arguments are required for cycol matrix"); |
16634 | 949 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
950 error ("gallery: N must be a 1 or 2 element integer for cycol matrix"); |
16634 | 951 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
952 error ("gallery: K must be a scalar for cycol matrix"); |
16634 | 953 endif |
954 | |
955 ## Parameter n specifies dimension: m-by-n | |
956 m = n(1); | |
957 n = n(end); | |
958 | |
959 A = randn (m, k); | |
960 for i = 2:ceil (n/k) | |
961 A = [A A(:,1:k)]; | |
962 endfor | |
963 A = A(:,1:n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
964 |
16634 | 965 endfunction |
966 | |
967 function [c, d, e] = dorr (n, theta = 0.01) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
968 |
16634 | 969 ## DORR Dorr matrix - diagonally dominant, ill conditioned, tridiagonal. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
970 ## [C, D, E] = DORR(N, THETA) returns the vectors defining a row diagonally |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
971 ## dominant, tridiagonal M-matrix that is ill conditioned for small |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
972 ## values of the parameter THETA >= 0. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
973 ## If only one output parameter is supplied then |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
974 ## C = FULL(TRIDIAG(C,D,E)), i.e., the matrix iself is returned. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
975 ## The columns of INV(C) vary greatly in norm. THETA defaults to 0.01. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
976 ## The amount of diagonal dominance is given by (ignoring rounding errors): |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
977 ## COMP(C)*ONES(N,1) = THETA*(N+1)^2 * [1 0 0 ... 0 1]'. |
16634 | 978 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
979 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
980 ## F.W. Dorr, An example of ill-conditioning in the numerical |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
981 ## solution of singular perturbation problems, Math. Comp., 25 (1971), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
982 ## pp. 271-283. |
16634 | 983 |
984 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
985 error ("gallery: 1 or 2 arguments are required for dorr matrix"); |
16634 | 986 elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
987 error ("gallery: N must be an integer for dorr matrix"); |
16634 | 988 elseif (! isscalar (theta) || ! isnumeric (theta)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
989 error ("gallery: THETA must be a numeric scalar for dorr matrix"); |
16634 | 990 endif |
991 | |
992 c = zeros (n, 1); | |
993 e = c; | |
994 d = c; | |
995 ## All length n for convenience. Make c, e of length n-1 later. | |
996 | |
997 h = 1/(n+1); | |
998 m = floor ((n+1)/2); | |
999 term = theta/h^2; | |
1000 | |
1001 i = (1:m)'; | |
1002 c(i) = -term * ones (m, 1); | |
1003 e(i) = c(i) - (0.5-i*h)/h; | |
1004 d(i) = -(c(i) + e(i)); | |
1005 | |
1006 i = (m+1:n)'; | |
1007 e(i) = -term * ones (n-m, 1); | |
1008 c(i) = e(i) + (0.5-i*h)/h; | |
1009 d(i) = -(c(i) + e(i)); | |
1010 | |
1011 c = c(2:n); | |
1012 e = e(1:n-1); | |
1013 | |
1014 if (nargout <= 1) | |
1015 c = tridiag (c, d, e); | |
1016 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1017 |
16634 | 1018 endfunction |
1019 | |
1020 function A = dramadah (n, k = 1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1021 |
16634 | 1022 ## DRAMADAH A (0,1) matrix whose inverse has large integer entries. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1023 ## An anti-Hadamard matrix A is a matrix with elements 0 or 1 for |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1024 ## which MU(A) := NORM(INV(A),'FRO') is maximal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1025 ## A = DRAMADAH(N, K) is an N-by-N (0,1) matrix for which MU(A) is |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1026 ## relatively large, although not necessarily maximal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1027 ## Available types (the default is K = 1): |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1028 ## K = 1: A is Toeplitz, with ABS(DET(A)) = 1, and MU(A) > c(1.75)^N, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1029 ## where c is a constant. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1030 ## K = 2: A is upper triangular and Toeplitz. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1031 ## The inverses of both types have integer entries. |
16634 | 1032 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1033 ## Another interesting (0,1) matrix: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1034 ## K = 3: A has maximal determinant among (0,1) lower Hessenberg |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1035 ## matrices: det(A) = the n'th Fibonacci number. A is Toeplitz. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1036 ## The eigenvalues have an interesting distribution in the complex |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1037 ## plane. |
16634 | 1038 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1039 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1040 ## R.L. Graham and N.J.A. Sloane, Anti-Hadamard matrices, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1041 ## Linear Algebra and Appl., 62 (1984), pp. 113-137. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1042 ## L. Ching, The maximum determinant of an nxn lower Hessenberg |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1043 ## (0,1) matrix, Linear Algebra and Appl., 183 (1993), pp. 147-153. |
16634 | 1044 |
1045 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1046 error ("gallery: 1 to 2 arguments are required for dramadah matrix"); |
16634 | 1047 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1048 error ("gallery: N must be an integer for dramadah matrix"); |
16634 | 1049 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1050 error ("gallery: K must be a numeric scalar for dramadah matrix"); |
16634 | 1051 endif |
1052 | |
1053 switch (k) | |
1054 case (1) # Toeplitz | |
1055 c = ones (n, 1); | |
1056 for i = 2:4:n | |
1057 m = min (1, n-i); | |
1058 c(i:i+m) = zeros (m+1, 1); | |
1059 endfor | |
1060 r = zeros (n, 1); | |
1061 r(1:4) = [1 1 0 1]; | |
1062 if (n < 4) | |
1063 r = r(1:n); | |
1064 endif | |
1065 A = toeplitz (c, r); | |
1066 | |
1067 case (2) # Upper triangular and Toeplitz | |
1068 c = zeros (n, 1); | |
1069 c(1) = 1; | |
1070 r = ones (n, 1); | |
1071 for i= 3:2:n | |
1072 r(i) = 0; | |
1073 endfor | |
1074 A = toeplitz (c, r); | |
1075 | |
1076 case (3) # Lower Hessenberg | |
1077 c = ones (n, 1); | |
1078 for i= 2:2:n | |
1079 c(i) = 0; | |
1080 endfor | |
1081 A = toeplitz (c, [1 1 zeros(1,n-2)]); | |
1082 | |
1083 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1084 error ("gallery: unknown K '%d' for dramadah matrix", k); |
16634 | 1085 endswitch |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1086 |
16634 | 1087 endfunction |
1088 | |
1089 function A = fiedler (c) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1090 |
16634 | 1091 ## FIEDLER Fiedler matrix - symmetric. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1092 ## FIEDLER(C), where C is an n-vector, is the n-by-n symmetric |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1093 ## matrix with elements ABS(C(i)-C(j)). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1094 ## Special case: if C is a scalar, then A = FIEDLER(1:C) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1095 ## (i.e. A(i,j) = ABS(i-j)). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1096 ## Properties: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1097 ## FIEDLER(N) has a dominant positive eigenvalue and all the other |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1098 ## eigenvalues are negative (Szego, 1936). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1099 ## Explicit formulas for INV(A) and DET(A) are given by Todd (1977) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1100 ## and attributed to Fiedler. These indicate that INV(A) is |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1101 ## tridiagonal except for nonzero (1,n) and (n,1) elements. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1102 ## [I think these formulas are valid only if the elements of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1103 ## C are in increasing or decreasing order---NJH.] |
16634 | 1104 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1105 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1106 ## G. Szego, Solution to problem 3705, Amer. Math. Monthly, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1107 ## 43 (1936), pp. 246-259. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1108 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1109 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 159. |
16634 | 1110 |
1111 if (nargin != 1) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1112 error ("gallery: 1 argument is required for fiedler matrix"); |
16634 | 1113 elseif (! isnumeric (c)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1114 error ("gallery: C must be numeric for fiedler matrix"); |
16634 | 1115 endif |
1116 | |
1117 n = numel (c); | |
1118 if (isscalar (c) && fix (c) == c) | |
1119 n = c; | |
1120 c = 1:n; | |
1121 elseif (n > 1 && isvector (c)) | |
1122 ## do nothing | |
1123 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1124 error ("gallery: C must be an integer or a vector for fiedler matrix"); |
16634 | 1125 endif |
1126 c = c(:).'; # Ensure c is a row vector. | |
1127 | |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
1128 A = abs (c - c.'); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1129 |
16634 | 1130 endfunction |
1131 | |
1132 function A = forsythe (n, alpha = sqrt (eps), lambda = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1133 |
16634 | 1134 ## FORSYTHE Forsythe matrix - a perturbed Jordan block. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1135 ## FORSYTHE(N, ALPHA, LAMBDA) is the N-by-N matrix equal to |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1136 ## JORDBLOC(N, LAMBDA) except it has an ALPHA in the (N,1) position. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1137 ## It has the characteristic polynomial |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1138 ## DET(A-t*EYE) = (LAMBDA-t)^N - (-1)^N ALPHA. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1139 ## ALPHA defaults to SQRT(EPS) and LAMBDA to 0. |
16634 | 1140 |
1141 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1142 error ("gallery: 1 to 3 arguments are required for forsythe matrix"); |
16634 | 1143 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1144 error ("gallery: N must be an integer for forsythe matrix"); |
16634 | 1145 elseif (! isnumeric (alpha) || ! isscalar (alpha)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1146 error ("gallery: ALPHA must be a numeric scalar for forsythe matrix"); |
16634 | 1147 elseif (! isnumeric (lambda) || ! isscalar (lambda)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1148 error ("gallery: LAMBDA must be a numeric scalar for forsythe matrix"); |
16634 | 1149 endif |
1150 | |
1151 A = jordbloc (n, lambda); | |
1152 A(n,1) = alpha; | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1153 |
16634 | 1154 endfunction |
1155 | |
1156 function F = frank (n, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1157 |
16634 | 1158 ## FRANK Frank matrix---ill conditioned eigenvalues. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1159 ## F = FRANK(N, K) is the Frank matrix of order N. It is upper |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1160 ## Hessenberg with determinant 1. K = 0 is the default; if K = 1 the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1161 ## elements are reflected about the anti-diagonal (1,N)--(N,1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1162 ## F has all positive eigenvalues and they occur in reciprocal pairs |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1163 ## (so that 1 is an eigenvalue if N is odd). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1164 ## The eigenvalues of F may be obtained in terms of the zeros of the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1165 ## Hermite polynomials. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1166 ## The FLOOR(N/2) smallest eigenvalues of F are ill conditioned, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1167 ## the more so for bigger N. |
16634 | 1168 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1169 ## DET(FRANK(N)') comes out far from 1 for large N---see Frank (1958) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1170 ## and Wilkinson (1960) for discussions. |
16634 | 1171 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1172 ## This version incorporates improvements suggested by W. Kahan. |
16634 | 1173 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1174 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1175 ## W.L. Frank, Computing eigenvalues of complex matrices by determinant |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1176 ## evaluation and by methods of Danilewski and Wielandt, J. Soc. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1177 ## Indust. Appl. Math., 6 (1958), pp. 378-392 (see pp. 385, 388). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1178 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1179 ## computation of the Jordan canonical form, SIAM Review, 18 (1976), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1180 ## pp. 578-619 (Section 13). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1181 ## H. Rutishauser, On test matrices, Programmation en Mathematiques |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1182 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1183 ## 1966, pp. 349-365. Section 9. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1184 ## J.H. Wilkinson, Error analysis of floating-point computation, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1185 ## Numer. Math., 2 (1960), pp. 319-340 (Section 8). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1186 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1187 ## Press, 1965 (pp. 92-93). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1188 ## The next two references give details of the eigensystem, as does |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1189 ## Rutishauser (see above). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1190 ## P.J. Eberlein, A note on the matrices denoted by B_n, SIAM J. Appl. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1191 ## Math., 20 (1971), pp. 87-92. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1192 ## J.M. Varah, A generalization of the Frank matrix, SIAM J. Sci. Stat. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1193 ## Comput., 7 (1986), pp. 835-839. |
16634 | 1194 |
1195 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1196 error ("gallery: 1 to 2 arguments are required for frank matrix"); |
16634 | 1197 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1198 error ("gallery: N must be an integer for frank matrix"); |
16634 | 1199 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1200 error ("gallery: K must be a numeric scalar for frank matrix"); |
16634 | 1201 endif |
1202 | |
1203 p = n:-1:1; | |
1204 F = triu (p(ones (n, 1), :) - diag (ones (n-1, 1), -1), -1); | |
1205 | |
1206 switch (k) | |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
1207 case 0, # do nothing |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
1208 case 1, F = F(p,p)'; |
16634 | 1209 otherwise |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1210 error ("gallery: K must have a value of 0 or 1 for frank matrix"); |
16634 | 1211 endswitch |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1212 |
16634 | 1213 endfunction |
1214 | |
1215 function c = gcdmat (n) | |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
1216 |
16634 | 1217 if (nargin != 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1218 error ("gallery: 1 argument is required for gcdmat matrix"); |
16634 | 1219 elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1220 error ("gallery: N must be an integer for gcdmat matrix"); |
16634 | 1221 endif |
1222 c = gcd (repmat ((1:n)', [1 n]), repmat (1:n, [n 1])); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1223 |
16634 | 1224 endfunction |
1225 | |
1226 function A = gearmat (n, i = n, j = -n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1227 |
16634 | 1228 ## NOTE: this function was named gearm in the original Test Matrix Toolbox |
1229 ## GEARMAT Gear matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1230 ## A = GEARMAT(N,I,J) is the N-by-N matrix with ones on the sub- and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1231 ## super-diagonals, SIGN(I) in the (1,ABS(I)) position, SIGN(J) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1232 ## in the (N,N+1-ABS(J)) position, and zeros everywhere else. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1233 ## Defaults: I = N, j = -N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1234 ## All eigenvalues are of the form 2*COS(a) and the eigenvectors |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1235 ## are of the form [SIN(w+a), SIN(w+2a), ..., SIN(w+Na)]. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1236 ## The values of a and w are given in the reference below. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1237 ## A can have double and triple eigenvalues and can be defective. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1238 ## GEARMAT(N) is singular. |
16634 | 1239 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1240 ## (GEAR is a Simulink function, hence GEARMAT for Gear matrix.) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1241 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1242 ## C.W. Gear, A simple set of test matrices for eigenvalue programs, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1243 ## Math. Comp., 23 (1969), pp. 119-125. |
16634 | 1244 |
1245 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1246 error ("gallery: 1 to 3 arguments are required for gearmat matrix"); |
16634 | 1247 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1248 error ("gallery: N must be an integer for gearmat matrix"); |
20294
2102c4582e32
gallery: fix chebspec, cycol, gearmat, hanowa, lauchli, and pei (bug #45466)
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
20231
diff
changeset
|
1249 elseif (! isnumeric (i) || ! isscalar (i) || i == 0 || abs (i) > n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1250 error ("gallery: I must be a nonzero scalar, and abs (I) <= N for gearmat matrix"); |
20294
2102c4582e32
gallery: fix chebspec, cycol, gearmat, hanowa, lauchli, and pei (bug #45466)
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
20231
diff
changeset
|
1251 elseif (! isnumeric (j) || ! isscalar (j) || i == 0 || abs (j) > n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1252 error ("gallery: J must be a nonzero scalar, and abs (J) <= N for gearmat matrix"); |
16634 | 1253 endif |
1254 | |
1255 A = diag (ones (n-1, 1), -1) + diag (ones (n-1, 1), 1); | |
1256 A(1, abs (i)) = sign (i); | |
1257 A(n, n+1 - abs (j)) = sign (j); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1258 |
16634 | 1259 endfunction |
1260 | |
1261 function G = grcar (n, k = 3) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1262 |
16634 | 1263 ## GRCAR Grcar matrix - a Toeplitz matrix with sensitive eigenvalues. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1264 ## GRCAR(N, K) is an N-by-N matrix with -1s on the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1265 ## subdiagonal, 1s on the diagonal, and K superdiagonals of 1s. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1266 ## The default is K = 3. The eigenvalues of this matrix form an |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1267 ## interesting pattern in the complex plane (try PS(GRCAR(32))). |
16634 | 1268 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1269 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1270 ## J.F. Grcar, Operator coefficient methods for linear equations, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1271 ## Report SAND89-8691, Sandia National Laboratories, Albuquerque, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1272 ## New Mexico, 1989 (Appendix 2). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1273 ## N.M. Nachtigal, L. Reichel and L.N. Trefethen, A hybrid GMRES |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1274 ## algorithm for nonsymmetric linear systems, SIAM J. Matrix Anal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1275 ## Appl., 13 (1992), pp. 796-825. |
16634 | 1276 |
1277 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1278 error ("gallery: 1 to 2 arguments are required for grcar matrix"); |
16634 | 1279 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1280 error ("gallery: N must be an integer for grcar matrix"); |
16634 | 1281 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1282 error ("gallery: K must be a numeric scalar for grcar matrix"); |
16634 | 1283 endif |
1284 | |
1285 G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1286 |
16634 | 1287 endfunction |
1288 | |
1289 function A = hanowa (n, d = -1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1290 |
16634 | 1291 ## HANOWA A matrix whose eigenvalues lie on a vertical line in the complex plane. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1292 ## HANOWA(N, d) is the N-by-N block 2x2 matrix (thus N = 2M must be even) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1293 ## [d*EYE(M) -DIAG(1:M) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1294 ## DIAG(1:M) d*EYE(M)] |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1295 ## It has complex eigenvalues lambda(k) = d +/- k*i (1 <= k <= M). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1296 ## Parameter d defaults to -1. |
16634 | 1297 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1298 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1299 ## E. Hairer, S.P. Norsett and G. Wanner, Solving Ordinary |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1300 ## Differential Equations I: Nonstiff Problems, Springer-Verlag, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1301 ## Berlin, 1987. (pp. 86-87) |
16634 | 1302 |
1303 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1304 error ("gallery: 1 to 2 arguments are required for hanowa matrix"); |
16634 | 1305 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1306 error ("gallery: N must be an integer for hanowa matrix"); |
16634 | 1307 elseif (rem (n, 2) != 0) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1308 error ("gallery: N must be even for hanowa matrix"); |
20294
2102c4582e32
gallery: fix chebspec, cycol, gearmat, hanowa, lauchli, and pei (bug #45466)
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
20231
diff
changeset
|
1309 elseif (! isnumeric (d) || ! isscalar (d)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1310 error ("gallery: D must be a numeric scalar for hanowa matrix"); |
16634 | 1311 endif |
1312 | |
1313 m = n/2; | |
1314 A = [ d*eye(m) -diag(1:m) | |
1315 diag(1:m) d*eye(m) ]; | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1316 |
16634 | 1317 endfunction |
1318 | |
1319 function [v, beta] = house (x) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1320 |
16634 | 1321 ## HOUSE Householder matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1322 ## If [v, beta] = HOUSE(x) then H = EYE - beta*v*v' is a Householder |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1323 ## matrix such that Hx = -sign(x(1))*norm(x)*e_1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1324 ## NB: If x = 0 then v = 0, beta = 1 is returned. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1325 ## x can be real or complex. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1326 ## sign(x) := exp(i*arg(x)) ( = x./abs(x) when x ~= 0). |
16634 | 1327 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1328 ## Theory: (textbook references Golub & Van Loan 1989, 38-43; |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1329 ## Stewart 1973, 231-234, 262; Wilkinson 1965, 48-50). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1330 ## Hx = y: (I - beta*v*v')x = -s*e_1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1331 ## Must have |s| = norm(x), v = x+s*e_1, and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1332 ## x'y = x'Hx =(x'Hx)' real => arg(s) = arg(x(1)). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1333 ## So take s = sign(x(1))*norm(x) (which avoids cancellation). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1334 ## v'v = (x(1)+s)^2 + x(2)^2 + ... + x(n)^2 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1335 ## = 2*norm(x)*(norm(x) + |x(1)|). |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1336 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1337 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1338 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1339 ## Johns Hopkins University Press, Baltimore, Maryland, 1989. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1340 ## G.W. Stewart, Introduction to Matrix Computations, Academic Press, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1341 ## New York, 1973, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1342 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1343 ## Press, 1965. |
16634 | 1344 |
1345 if (nargin != 1) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1346 error ("gallery: 1 argument is required for house matrix"); |
20295
557979395ca9
gallery: allow single element vectors for 'house'.
Carnë Draug <carandraug@octave.org>
parents:
20294
diff
changeset
|
1347 elseif (! isnumeric (x) || ! isvector (x)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1348 error ("gallery: X must be a vector for house matrix"); |
16634 | 1349 endif |
1350 | |
1351 ## must be a column vector | |
1352 x = x(:); | |
1353 | |
1354 s = norm (x) * (sign (x(1)) + (x(1) == 0)); # Modification for sign (0) == 1. | |
1355 v = x; | |
1356 if (s == 0) | |
1357 ## Quit if x is the zero vector. | |
1358 beta = 1; | |
1359 else | |
1360 v(1) = v(1) + s; | |
1361 beta = 1/(s'*v(1)); # NB the conjugated s. | |
1362 ## beta = 1/(abs (s) * (abs (s) +abs(x(1)) would guarantee beta real. | |
1363 ## But beta as above can be non-real (due to rounding) only when x is complex. | |
1364 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1365 |
16634 | 1366 endfunction |
1367 | |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1368 function A = integerdata (varargin) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1369 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1370 if (nargin < 3) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1371 error ("gallery: At least 3 arguments required for integerdata matrix"); |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1372 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1373 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1374 if (isnumeric (varargin{end})) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1375 jidx = varargin{end}; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1376 svec = [varargin{:}]; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1377 varargin(end) = []; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1378 elseif (ischar (varargin{end})) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1379 if (nargin < 4) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1380 error (["gallery: CLASS argument requires 4 inputs " ... |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1381 "for integerdata matrix."]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1382 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1383 jidx = varargin{end-1}; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1384 svec = [varargin{1:end-1}]; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1385 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1386 else |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1387 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1388 "for integerdata matrix"]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1389 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1390 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1391 if (! (isnumeric (jidx) && isscalar (jidx) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1392 && jidx == fix (jidx) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1393 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1394 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1395 "for integerdata matrix"]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1396 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1397 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1398 ## Save and restore random state. Initialization done so that reproducible |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1399 ## data is available from gallery depending on the jidx and size vector. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1400 randstate = rand ("state"); |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1401 unwind_protect |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1402 rand ("state", svec); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1403 A = randi (varargin{:}); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1404 unwind_protect_cleanup |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1405 rand ("state", randstate); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1406 end_unwind_protect |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1407 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1408 endfunction |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1409 |
16634 | 1410 function A = invhess (x, y) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1411 |
16634 | 1412 ## INVHESS Inverse of an upper Hessenberg matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1413 ## INVHESS(X, Y), where X is an N-vector and Y an N-1 vector, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1414 ## is the matrix whose lower triangle agrees with that of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1415 ## ONES(N,1)*X' and whose strict upper triangle agrees with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1416 ## that of [1 Y]*ONES(1,N). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1417 ## The matrix is nonsingular if X(1) ~= 0 and X(i+1) ~= Y(i) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1418 ## for all i, and its inverse is an upper Hessenberg matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1419 ## If Y is omitted it defaults to -X(1:N-1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1420 ## Special case: if X is a scalar INVHESS(X) is the same as |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1421 ## INVHESS(1:X). |
16634 | 1422 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1423 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1424 ## F.N. Valvi and V.S. Geroyannis, Analytic inverses and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1425 ## determinants for a class of matrices, IMA Journal of Numerical |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1426 ## Analysis, 7 (1987), pp. 123-128. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1427 ## W.-L. Cao and W.J. Stewart, A note on inverses of Hessenberg-like |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1428 ## matrices, Linear Algebra and Appl., 76 (1986), pp. 233-240. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1429 ## Y. Ikebe, On inverses of Hessenberg matrices, Linear Algebra and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1430 ## Appl., 24 (1979), pp. 93-97. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1431 ## P. Rozsa, On the inverse of band matrices, Integral Equations and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1432 ## Operator Theory, 10 (1987), pp. 82-95. |
16634 | 1433 |
1434 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1435 error ("gallery: 1 to 2 arguments are required for invhess matrix"); |
16634 | 1436 elseif (! isnumeric (x)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1437 error ("gallery: X must be numeric for invhess matrix"); |
16634 | 1438 endif |
1439 | |
1440 if (isscalar (x) && fix (x) == x) | |
1441 n = x; | |
1442 x = 1:n; | |
1443 elseif (! isscalar (x) && isvector (x)) | |
20297
26fc9bbb8762
gallery: fix typo on variable name for invhess matrix.
Carnë Draug <carandraug@octave.org>
parents:
20296
diff
changeset
|
1444 n = numel (x); |
16634 | 1445 else |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1446 error ("gallery: X must be an integer scalar, or a vector for invhess matrix"); |
16634 | 1447 endif |
1448 | |
1449 if (nargin < 2) | |
1450 y = -x(1:end-1); | |
1451 elseif (! isvector (y) || numel (y) != numel (x) -1) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1452 error ("gallery: Y must be a vector of length -1 than X for invhess matrix"); |
16634 | 1453 endif |
1454 | |
1455 x = x(:); | |
1456 y = y(:); | |
1457 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1458 ## FIXME: On next line, z = x'; A = z(ones(n,1),:) would be more efficient. |
16634 | 1459 A = ones (n, 1) * x'; |
1460 for j = 2:n | |
1461 A(1:j-1,j) = y(1:j-1); | |
1462 endfor | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1463 |
16634 | 1464 endfunction |
1465 | |
1466 function A = invol (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1467 |
16634 | 1468 ## INVOL An involutory matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1469 ## A = INVOL(N) is an N-by-N involutory (A*A = EYE(N)) and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1470 ## ill-conditioned matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1471 ## It is a diagonally scaled version of HILB(N). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1472 ## NB: B = (EYE(N)-A)/2 and B = (EYE(N)+A)/2 are idempotent (B*B = B). |
16634 | 1473 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1474 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1475 ## A.S. Householder and J.A. Carpenter, The singular values |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1476 ## of involutory and of idempotent matrices, Numer. Math. 5 (1963), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1477 ## pp. 234-237. |
16634 | 1478 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1479 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1480 error ("gallery: 1 argument is required for invol matrix"); |
16634 | 1481 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1482 error ("gallery: N must be an integer for invol matrix"); |
16634 | 1483 endif |
1484 | |
1485 A = hilb (n); | |
1486 | |
1487 d = -n; | |
1488 A(:, 1) = d * A(:, 1); | |
1489 | |
1490 for i = 1:n-1 | |
1491 d = -(n+i)*(n-i)*d/(i*i); | |
1492 A(i+1,:) = d * A(i+1,:); | |
1493 endfor | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1494 |
16634 | 1495 endfunction |
1496 | |
1497 function [A, detA] = ipjfact (n, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1498 |
16634 | 1499 ## IPJFACT A Hankel matrix with factorial elements. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1500 ## A = IPJFACT(N, K) is the matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1501 ## A(i,j) = (i+j)! (K = 0, default) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1502 ## A(i,j) = 1/(i+j)! (K = 1) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1503 ## Both are Hankel matrices. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1504 ## The determinant and inverse are known explicitly. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1505 ## If a second output argument is present, d = DET(A) is returned: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1506 ## [A, d] = IPJFACT(N, K); |
16634 | 1507 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1508 ## Suggested by P. R. Graves-Morris. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1509 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1510 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1511 ## M.J.C. Gover, The explicit inverse of factorial Hankel matrices, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1512 ## Dept. of Mathematics, University of Bradford, 1993. |
16634 | 1513 |
1514 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1515 error ("gallery: 1 to 2 arguments are required for ipjfact matrix"); |
16634 | 1516 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1517 error ("gallery: N must be an integer for ipjfact matrix"); |
16634 | 1518 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1519 error ("gallery: K must be a numeric scalar for ipjfact matrix"); |
16634 | 1520 endif |
1521 | |
1522 c = cumprod (2:n+1); | |
1523 d = cumprod (n+1:2*n) * c(n-1); | |
1524 | |
1525 A = hankel (c, d); | |
1526 | |
1527 switch (k) | |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
1528 case 0, # do nothing |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
1529 case 1, A = ones (n) ./ A; |
16634 | 1530 otherwise |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1531 error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); |
16634 | 1532 endswitch |
1533 | |
1534 if (nargout == 2) | |
1535 d = 1; | |
1536 | |
1537 if (k == 0) | |
1538 for i = 1:n-1 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1539 d *= prod (1:i+1) * prod (1:n-i); |
16634 | 1540 endfor |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1541 d *= prod (1:n+1); |
16634 | 1542 |
1543 elseif (k == 1) | |
1544 for i = 0:n-1 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1545 d *= prod (1:i) / prod (1:n+1+i); |
16634 | 1546 endfor |
1547 if (rem (n*(n-1)/2, 2)) | |
1548 d = -d; | |
1549 endif | |
1550 | |
1551 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1552 error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); |
16634 | 1553 endif |
1554 | |
1555 detA = d; | |
1556 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1557 |
16634 | 1558 endfunction |
1559 | |
1560 function J = jordbloc (n, lambda = 1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1561 |
16634 | 1562 ## JORDBLOC Jordan block. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1563 ## JORDBLOC(N, LAMBDA) is the N-by-N Jordan block with eigenvalue |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1564 ## LAMBDA. LAMBDA = 1 is the default. |
16634 | 1565 |
1566 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1567 error ("gallery: 1 to 2 arguments are required for jordbloc matrix"); |
16634 | 1568 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1569 error ("gallery: N must be an integer for jordbloc matrix"); |
16634 | 1570 elseif (! isnumeric (lambda) || ! isscalar (lambda)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1571 error ("gallery: LAMBDA must be a numeric scalar for jordbloc matrix"); |
16634 | 1572 endif |
1573 | |
1574 J = lambda * eye (n) + diag (ones (n-1, 1), 1); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1575 |
16634 | 1576 endfunction |
1577 | |
1578 function U = kahan (n, theta = 1.2, pert = 25) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1579 |
16634 | 1580 ## KAHAN Kahan matrix - upper trapezoidal. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1581 ## KAHAN(N, THETA) is an upper trapezoidal matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1582 ## that has some interesting properties regarding estimation of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1583 ## condition and rank. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1584 ## The matrix is N-by-N unless N is a 2-vector, in which case it |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1585 ## is N(1)-by-N(2). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1586 ## The parameter THETA defaults to 1.2. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1587 ## The useful range of THETA is 0 < THETA < PI. |
16634 | 1588 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1589 ## To ensure that the QR factorization with column pivoting does not |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1590 ## interchange columns in the presence of rounding errors, the diagonal |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1591 ## is perturbed by PERT*EPS*diag( [N:-1:1] ). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1592 ## The default is PERT = 25, which ensures no interchanges for KAHAN(N) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1593 ## up to at least N = 90 in IEEE arithmetic. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1594 ## KAHAN(N, THETA, PERT) uses the given value of PERT. |
16634 | 1595 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1596 ## The inverse of KAHAN(N, THETA) is known explicitly: see |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1597 ## Higham (1987, p. 588), for example. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1598 ## The diagonal perturbation was suggested by Christian Bischof. |
16634 | 1599 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1600 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1601 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1602 ## 9 (1966), pp. 757-801. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1603 ## N.J. Higham, A survey of condition number estimation for |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1604 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. |
16634 | 1605 |
1606 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1607 error ("gallery: 1 to 3 arguments are required for kahan matrix"); |
16634 | 1608 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1609 error ("gallery: N must be a 1 or 2 element integer for kahan matrix"); |
16634 | 1610 elseif (! isnumeric (theta) || ! isscalar (theta)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1611 error ("gallery: THETA must be a numeric scalar for kahan matrix"); |
16634 | 1612 elseif (! isnumeric (pert) || ! isscalar (pert)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1613 error ("gallery: PERT must be a numeric scalar for kahan matrix"); |
16634 | 1614 endif |
1615 | |
1616 ## Parameter n specifies dimension: r-by-n | |
1617 r = n(1); | |
1618 n = n(end); | |
1619 | |
1620 s = sin (theta); | |
1621 c = cos (theta); | |
1622 | |
1623 U = eye (n) - c * triu (ones (n), 1); | |
1624 U = diag (s.^[0:n-1]) * U + pert*eps* diag ([n:-1:1]); | |
1625 if (r > n) | |
1626 U(r,n) = 0; # Extend to an r-by-n matrix | |
1627 else | |
1628 U = U(1:r,:); # Reduce to an r-by-n matrix | |
1629 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1630 |
16634 | 1631 endfunction |
1632 | |
1633 function A = kms (n, rho = 0.5) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1634 |
16634 | 1635 ## KMS Kac-Murdock-Szego Toeplitz matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1636 ## A = KMS(N, RHO) is the N-by-N Kac-Murdock-Szego Toeplitz matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1637 ## A(i,j) = RHO^(ABS((i-j))) (for real RHO). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1638 ## If RHO is complex, then the same formula holds except that elements |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1639 ## below the diagonal are conjugated. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1640 ## RHO defaults to 0.5. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1641 ## Properties: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1642 ## A has an LDL' factorization with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1643 ## L = INV(TRIW(N,-RHO,1)'), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1644 ## D(i,i) = (1-ABS(RHO)^2)*EYE(N) except D(1,1) = 1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1645 ## A is positive definite if and only if 0 < ABS(RHO) < 1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1646 ## INV(A) is tridiagonal. |
16634 | 1647 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1648 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1649 ## W.F. Trench, Numerical solution of the eigenvalue problem |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1650 ## for Hermitian Toeplitz matrices, SIAM J. Matrix Analysis and Appl., |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1651 ## 10 (1989), pp. 135-146 (and see the references therein). |
16634 | 1652 |
1653 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1654 error ("gallery: 1 to 2 arguments are required for lauchli matrix"); |
16634 | 1655 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1656 error ("gallery: N must be an integer for lauchli matrix"); |
20294
2102c4582e32
gallery: fix chebspec, cycol, gearmat, hanowa, lauchli, and pei (bug #45466)
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
20231
diff
changeset
|
1657 elseif (! isscalar (rho)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1658 error ("gallery: RHO must be a scalar for lauchli matrix"); |
16634 | 1659 endif |
1660 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1661 A = (1:n)'*ones (1,n); |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1662 A = abs (A - A'); |
16634 | 1663 A = rho .^ A; |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1664 if (imag (rho)) |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1665 A = conj (tril (A,-1)) + triu (A); |
16634 | 1666 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1667 |
16634 | 1668 endfunction |
1669 | |
1670 function B = krylov (A, x, j) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1671 |
16634 | 1672 ## KRYLOV Krylov matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1673 ## KRYLOV(A, x, j) is the Krylov matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1674 ## [x, Ax, A^2x, ..., A^(j-1)x], |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1675 ## where A is an n-by-n matrix and x is an n-vector. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1676 ## Defaults: x = ONES(n,1), j = n. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1677 ## KRYLOV(n) is the same as KRYLOV(RANDN(n)). |
16634 | 1678 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1679 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1680 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1681 ## Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369. |
16634 | 1682 |
1683 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1684 error ("gallery: 1 to 3 arguments are required for krylov matrix"); |
16634 | 1685 elseif (! isnumeric (A) || ! issquare (A) || ndims (A) != 2) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1686 error ("gallery: A must be a square 2-D matrix for krylov matrix"); |
16634 | 1687 endif |
1688 | |
1689 n = length (A); | |
1690 if (isscalar (A)) | |
1691 n = A; | |
1692 A = randn (n); | |
1693 endif | |
1694 | |
1695 if (nargin < 2) | |
1696 x = ones (n, 1); | |
1697 elseif (! isvector (x) || numel (x) != n) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1698 error ("gallery: X must be a vector of length equal to A for krylov matrix"); |
16634 | 1699 endif |
1700 | |
1701 if (nargin < 3) | |
1702 j = n; | |
1703 elseif (! isnumeric (j) || ! isscalar (j) || fix (j) != j) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1704 error ("gallery: J must be an integer for krylov matrix"); |
16634 | 1705 endif |
1706 | |
1707 B = ones (n, j); | |
1708 B(:,1) = x(:); | |
1709 for i = 2:j | |
1710 B(:,i) = A*B(:,i-1); | |
1711 endfor | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1712 |
16634 | 1713 endfunction |
1714 | |
1715 function A = lauchli (n, mu = sqrt (eps)) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1716 |
16634 | 1717 ## LAUCHLI Lauchli matrix - rectangular. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1718 ## LAUCHLI(N, MU) is the (N+1)-by-N matrix [ONES(1,N); MU*EYE(N))]. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1719 ## It is a well-known example in least squares and other problems |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1720 ## that indicates the dangers of forming A'*A. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1721 ## MU defaults to SQRT(EPS). |
16634 | 1722 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1723 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1724 ## P. Lauchli, Jordan-Elimination und Ausgleichung nach |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1725 ## kleinsten Quadraten, Numer. Math, 3 (1961), pp. 226-240. |
16634 | 1726 |
1727 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1728 error ("gallery: 1 to 2 arguments are required for lauchli matrix"); |
16634 | 1729 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1730 error ("gallery: N must be an integer for lauchli matrix"); |
16634 | 1731 elseif (! isscalar (mu)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1732 error ("gallery: MU must be a scalar for lauchli matrix"); |
16634 | 1733 endif |
1734 | |
1735 A = [ones(1, n) | |
1736 mu*eye(n) ]; | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1737 |
16634 | 1738 endfunction |
1739 | |
1740 function A = lehmer (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1741 |
16634 | 1742 ## LEHMER Lehmer matrix - symmetric positive definite. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1743 ## A = LEHMER(N) is the symmetric positive definite N-by-N matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1744 ## A(i,j) = i/j for j >= i. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1745 ## A is totally nonnegative. INV(A) is tridiagonal, and explicit |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1746 ## formulas are known for its entries. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1747 ## N <= COND(A) <= 4*N*N. |
16634 | 1748 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1749 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1750 ## M. Newman and J. Todd, The evaluation of matrix inversion |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1751 ## programs, J. Soc. Indust. Appl. Math., 6 (1958), pp. 466-476. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1752 ## Solutions to problem E710 (proposed by D.H. Lehmer): The inverse |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1753 ## of a matrix, Amer. Math. Monthly, 53 (1946), pp. 534-535. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1754 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1755 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 154. |
16634 | 1756 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1757 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1758 error ("gallery: 1 argument is required for lehmer matrix"); |
16634 | 1759 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1760 error ("gallery: N must be an integer for lehmer matrix"); |
16634 | 1761 endif |
1762 | |
1763 A = ones (n, 1) * (1:n); | |
1764 A = A./A'; | |
1765 A = tril (A) + tril (A, -1)'; | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1766 |
16634 | 1767 endfunction |
1768 | |
1769 function T = lesp (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1770 |
16634 | 1771 ## LESP A tridiagonal matrix with real, sensitive eigenvalues. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1772 ## LESP(N) is an N-by-N matrix whose eigenvalues are real and smoothly |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1773 ## distributed in the interval approximately [-2*N-3.5, -4.5]. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1774 ## The sensitivities of the eigenvalues increase exponentially as |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1775 ## the eigenvalues grow more negative. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1776 ## The matrix is similar to the symmetric tridiagonal matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1777 ## the same diagonal entries and with off-diagonal entries 1, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1778 ## via a similarity transformation with D = diag(1!,2!,...,N!). |
16634 | 1779 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1780 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1781 ## H.W.J. Lenferink and M.N. Spijker, On the use of stability regions in |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1782 ## the numerical analysis of initial value problems, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1783 ## Math. Comp., 57 (1991), pp. 221-237. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1784 ## L.N. Trefethen, Pseudospectra of matrices, in Numerical Analysis 1991, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1785 ## Proceedings of the 14th Dundee Conference, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1786 ## D.F. Griffiths and G.A. Watson, eds, Pitman Research Notes in |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1787 ## Mathematics, volume 260, Longman Scientific and Technical, Essex, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1788 ## UK, 1992, pp. 234-266. |
16634 | 1789 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1790 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1791 error ("gallery: 1 argument is required for lesp matrix"); |
16634 | 1792 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1793 error ("gallery: N must be an integer for lesp matrix"); |
16634 | 1794 endif |
1795 | |
1796 x = 2:n; | |
1797 T = full (tridiag (ones (size (x)) ./x, -(2*[x n+1]+1), x)); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1798 |
16634 | 1799 endfunction |
1800 | |
1801 function A = lotkin (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1802 |
16634 | 1803 ## LOTKIN Lotkin matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1804 ## A = LOTKIN(N) is the Hilbert matrix with its first row altered to |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1805 ## all ones. A is unsymmetric, ill-conditioned, and has many negative |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1806 ## eigenvalues of small magnitude. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1807 ## The inverse has integer entries and is known explicitly. |
16634 | 1808 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1809 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1810 ## M. Lotkin, A set of test matrices, MTAC, 9 (1955), pp. 153-161. |
16634 | 1811 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1812 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1813 error ("gallery: 1 argument is required for lotkin matrix"); |
16634 | 1814 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1815 error ("gallery: N must be an integer for lotkin matrix"); |
16634 | 1816 endif |
1817 | |
1818 A = hilb (n); | |
1819 A(1,:) = ones (1, n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1820 |
16634 | 1821 endfunction |
1822 | |
1823 function A = minij (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1824 |
16634 | 1825 ## MINIJ Symmetric positive definite matrix MIN(i,j). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1826 ## A = MINIJ(N) is the N-by-N symmetric positive definite matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1827 ## A(i,j) = MIN(i,j). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1828 ## Properties, variations: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1829 ## INV(A) is tridiagonal: it is minus the second difference matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1830 ## except its (N,N) element is 1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1831 ## 2*A-ONES(N) (Givens' matrix) has tridiagonal inverse and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1832 ## eigenvalues .5*sec^2([2r-1)PI/4N], r=1:N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1833 ## (N+1)*ONES(N)-A also has a tridiagonal inverse. |
16634 | 1834 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1835 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1836 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1837 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 158. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1838 ## D.E. Rutherford, Some continuant determinants arising in physics and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1839 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1840 ## (For the eigenvalues of Givens' matrix.) |
16634 | 1841 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1842 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1843 error ("gallery: 1 argument is required for minij matrix"); |
16634 | 1844 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1845 error ("gallery: N must be an integer for minij matrix"); |
16634 | 1846 endif |
1847 | |
19944
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
1848 A = bsxfun (@min, 1:n, (1:n)'); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1849 |
16634 | 1850 endfunction |
1851 | |
1852 function A = moler (n, alpha = -1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1853 |
16634 | 1854 ## MOLER Moler matrix - symmetric positive definite. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1855 ## A = MOLER(N, ALPHA) is the symmetric positive definite N-by-N matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1856 ## U'*U where U = TRIW(N, ALPHA). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1857 ## For ALPHA = -1 (the default) A(i,j) = MIN(i,j)-2, A(i,i) = i. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1858 ## A has one small eigenvalue. |
16634 | 1859 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1860 ## Nash (1990) attributes the ALPHA = -1 matrix to Moler. |
16634 | 1861 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1862 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1863 ## J.C. Nash, Compact Numerical Methods for Computers: Linear |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1864 ## Algebra and Function Minimisation, second edition, Adam Hilger, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1865 ## Bristol, 1990 (Appendix 1). |
16634 | 1866 |
1867 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1868 error ("gallery: 1 to 2 arguments are required for moler matrix"); |
16634 | 1869 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1870 error ("gallery: N must be an integer for moler matrix"); |
16634 | 1871 elseif (! isscalar (alpha)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1872 error ("gallery: ALPHA must be a scalar for moler matrix"); |
16634 | 1873 endif |
1874 | |
1875 A = triw (n, alpha)' * triw (n, alpha); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1876 |
16634 | 1877 endfunction |
1878 | |
1879 function [A, T] = neumann (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1880 |
16634 | 1881 ## NEUMANN Singular matrix from the discrete Neumann problem (sparse). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1882 ## NEUMANN(N) is the singular, row diagonally dominant matrix resulting |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1883 ## from discretizing the Neumann problem with the usual five point |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1884 ## operator on a regular mesh. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1885 ## It has a one-dimensional null space with null vector ONES(N,1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1886 ## The dimension N should be a perfect square, or else a 2-vector, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1887 ## in which case the dimension of the matrix is N(1)*N(2). |
16634 | 1888 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1889 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1890 ## R.J. Plemmons, Regular splittings and the discrete Neumann |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1891 ## problem, Numer. Math., 25 (1976), pp. 153-161. |
16634 | 1892 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1893 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1894 error ("gallery: 1 argument is required for neumann matrix"); |
16634 | 1895 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1896 error ("gallery: N must be a 1 or 2 element integer for neumann matrix"); |
16634 | 1897 endif |
1898 | |
1899 if (isscalar (n)) | |
1900 m = sqrt (n); | |
1901 if (m^2 != n) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1902 error ("gallery: N must be a perfect square for neumann matrix"); |
16634 | 1903 endif |
1904 n(1) = m; | |
1905 n(2) = m; | |
1906 endif | |
1907 | |
1908 T = tridiag (n(1), -1, 2, -1); | |
1909 T(1,2) = -2; | |
1910 T(n(1),n(1)-1) = -2; | |
1911 | |
1912 A = kron (T, eye (n(2))) + kron (eye (n(2)), T); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1913 |
16634 | 1914 endfunction |
1915 | |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1916 function A = normaldata (varargin) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1917 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1918 if (nargin < 2) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1919 error ("gallery: At least 2 arguments required for normaldata matrix"); |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1920 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1921 if (isnumeric (varargin{end})) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1922 jidx = varargin{end}; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1923 svec = [varargin{:}]; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1924 varargin(end) = []; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1925 elseif (ischar (varargin{end})) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1926 if (nargin < 3) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1927 error (["gallery: CLASS argument requires 3 inputs " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1928 "for normaldata matrix."]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1929 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1930 jidx = varargin{end-1}; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1931 svec = [varargin{1:end-1}]; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1932 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1933 else |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1934 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1935 "for normaldata matrix"]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1936 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1937 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1938 if (! (isnumeric (jidx) && isscalar (jidx) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1939 && jidx == fix (jidx) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1940 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1941 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1942 "for normaldata matrix"]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1943 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1944 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1945 ## Save and restore random state. Initialization done so that reproducible |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1946 ## data is available from gallery depending on the jidx and size vector. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1947 randstate = randn ("state"); |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1948 unwind_protect |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1949 randn ("state", svec); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1950 A = randn (varargin{:}); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1951 unwind_protect_cleanup |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1952 randn ("state", randstate); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1953 end_unwind_protect |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1954 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1955 endfunction |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1956 |
16634 | 1957 function Q = orthog (n, k = 1) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
1958 |
16634 | 1959 ## ORTHOG Orthogonal and nearly orthogonal matrices. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1960 ## Q = ORTHOG(N, K) selects the K'th type of matrix of order N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1961 ## K > 0 for exactly orthogonal matrices, K < 0 for diagonal scalings of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1962 ## orthogonal matrices. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1963 ## Available types: (K = 1 is the default) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1964 ## K = 1: Q(i,j) = SQRT(2/(n+1)) * SIN( i*j*PI/(n+1) ) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1965 ## Symmetric eigenvector matrix for second difference matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1966 ## K = 2: Q(i,j) = 2/SQRT(2*n+1)) * SIN( 2*i*j*PI/(2*n+1) ) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1967 ## Symmetric. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1968 ## K = 3: Q(r,s) = EXP(2*PI*i*(r-1)*(s-1)/n) / SQRT(n) (i=SQRT(-1)) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1969 ## Unitary, the Fourier matrix. Q^4 is the identity. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1970 ## This is essentially the same matrix as FFT(EYE(N))/SQRT(N)! |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1971 ## K = 4: Helmert matrix: a permutation of a lower Hessenberg matrix, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1972 ## whose first row is ONES(1:N)/SQRT(N). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1973 ## K = 5: Q(i,j) = SIN( 2*PI*(i-1)*(j-1)/n ) + COS( 2*PI*(i-1)*(j-1)/n ). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1974 ## Symmetric matrix arising in the Hartley transform. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1975 ## K = -1: Q(i,j) = COS( (i-1)*(j-1)*PI/(n-1) ) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1976 ## Chebyshev Vandermonde-like matrix, based on extrema of T(n-1). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1977 ## K = -2: Q(i,j) = COS( (i-1)*(j-1/2)*PI/n) ) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1978 ## Chebyshev Vandermonde-like matrix, based on zeros of T(n). |
16634 | 1979 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1980 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1981 ## N.J. Higham and D.J. Higham, Large growth factors in Gaussian |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1982 ## elimination with pivoting, SIAM J. Matrix Analysis and Appl., |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1983 ## 10 (1989), pp. 155-164. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1984 ## P. Morton, On the eigenvectors of Schur's matrix, J. Number Theory, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1985 ## 12 (1980), pp. 122-127. (Re. ORTHOG(N, 3)) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1986 ## H.O. Lancaster, The Helmert Matrices, Amer. Math. Monthly, 72 (1965), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1987 ## pp. 4-12. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1988 ## D. Bini and P. Favati, On a matrix algebra related to the discrete |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1989 ## Hartley transform, SIAM J. Matrix Anal. Appl., 14 (1993), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1990 ## pp. 500-507. |
16634 | 1991 |
1992 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1993 error ("gallery: 1 to 2 arguments are required for orthog matrix"); |
16634 | 1994 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1995 error ("gallery: N must be an integer for orthog matrix"); |
16634 | 1996 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1997 error ("gallery: K must be a numeric scalar for orthog matrix"); |
16634 | 1998 endif |
1999 | |
2000 switch (k) | |
2001 case (1) | |
2002 ## E'vectors second difference matrix | |
2003 m = (1:n)'*(1:n) * (pi/(n+1)); | |
2004 Q = sin (m) * sqrt (2/(n+1)); | |
2005 | |
2006 case (2) | |
2007 m = (1:n)'*(1:n) * (2*pi/(2*n+1)); | |
2008 Q = sin (m) * (2/ sqrt (2*n+1)); | |
2009 | |
2010 case (3) | |
2011 ## Vandermonde based on roots of unity | |
2012 m = 0:n-1; | |
2013 Q = exp (m'*m*2*pi* sqrt (-1) / n) / sqrt (n); | |
2014 | |
2015 case (4) | |
2016 ## Helmert matrix | |
2017 Q = tril (ones (n)); | |
2018 Q(1,2:n) = ones (1, n-1); | |
2019 for i = 2:n | |
2020 Q(i,i) = -(i-1); | |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2021 endfor |
16634 | 2022 Q = diag (sqrt ([n 1:n-1] .* [1:n])) \ Q; |
2023 | |
2024 case (5) | |
2025 ## Hartley matrix | |
2026 m = (0:n-1)'*(0:n-1) * (2*pi/n); | |
2027 Q = (cos (m) + sin (m)) / sqrt (n); | |
2028 | |
2029 case (-1) | |
2030 ## extrema of T(n-1) | |
2031 m = (0:n-1)'*(0:n-1) * (pi/(n-1)); | |
2032 Q = cos (m); | |
2033 | |
2034 case (-2) | |
2035 ## zeros of T(n) | |
2036 m = (0:n-1)'*(.5:n-.5) * (pi/n); | |
2037 Q = cos (m); | |
2038 | |
2039 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2040 error ("gallery: unknown K '%d' for orthog matrix", k); |
16634 | 2041 endswitch |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2042 |
16634 | 2043 endfunction |
2044 | |
2045 function A = parter (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2046 |
16634 | 2047 ## PARTER Parter matrix - a Toeplitz matrix with singular values near PI. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2048 ## PARTER(N) is the matrix with (i,j) element 1/(i-j+0.5). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2049 ## It is a Cauchy matrix and a Toeplitz matrix. |
16634 | 2050 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2051 ## At the Second SIAM Conference on Linear Algebra, Raleigh, N.C., |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2052 ## 1985, Cleve Moler noted that most of the singular values of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2053 ## PARTER(N) are very close to PI. An explanation of the phenomenon |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2054 ## was given by Parter; see also the paper by Tyrtyshnikov. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2055 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2056 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2057 ## The MathWorks Newsletter, Volume 1, Issue 1, March 1986, page 2. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2058 ## S.V. Parter, On the distribution of the singular values of Toeplitz |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2059 ## matrices, Linear Algebra and Appl., 80 (1986), pp. 115-130. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2060 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2061 ## Linear Algebra and Appl., 149 (1991), pp. 1-18. |
16634 | 2062 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2063 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2064 error ("gallery: 1 argument is required for parter matrix"); |
16634 | 2065 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2066 error ("gallery: N must be an integer for parter matrix"); |
16634 | 2067 endif |
2068 | |
2069 A = cauchy ((1:n) + 0.5, -(1:n)); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2070 |
16634 | 2071 endfunction |
2072 | |
2073 function P = pei (n, alpha = 1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2074 |
16634 | 2075 ## PEI Pei matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2076 ## PEI(N, ALPHA), where ALPHA is a scalar, is the symmetric matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2077 ## ALPHA*EYE(N) + ONES(N). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2078 ## If ALPHA is omitted then ALPHA = 1 is used. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2079 ## The matrix is singular for ALPHA = 0, -N. |
16634 | 2080 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2081 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2082 ## M.L. Pei, A test matrix for inversion procedures, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2083 ## Comm. ACM, 5 (1962), p. 508. |
16634 | 2084 |
2085 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2086 error ("gallery: 1 to 2 arguments are required for pei matrix"); |
16634 | 2087 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2088 error ("gallery: N must be an integer for pei matrix"); |
20294
2102c4582e32
gallery: fix chebspec, cycol, gearmat, hanowa, lauchli, and pei (bug #45466)
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
20231
diff
changeset
|
2089 elseif (! isnumeric (alpha) || ! isscalar (alpha)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2090 error ("gallery: ALPHA must be a scalar for pei matrix"); |
16634 | 2091 endif |
2092 | |
2093 P = alpha * eye (n) + ones (n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2094 |
16634 | 2095 endfunction |
2096 | |
2097 function A = poisson (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2098 |
16634 | 2099 ## POISSON Block tridiagonal matrix from Poisson's equation (sparse). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2100 ## POISSON(N) is the block tridiagonal matrix of order N^2 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2101 ## resulting from discretizing Poisson's equation with the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2102 ## 5-point operator on an N-by-N mesh. |
16634 | 2103 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2104 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2105 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2106 ## Johns Hopkins University Press, Baltimore, Maryland, 1989 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2107 ## (Section 4.5.4). |
16634 | 2108 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2109 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2110 error ("gallery: 1 argument is required for poisson matrix"); |
16634 | 2111 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2112 error ("gallery: N must be an integer for poisson matrix"); |
16634 | 2113 endif |
2114 | |
2115 S = tridiag (n, -1, 2, -1); | |
2116 I = speye (n); | |
2117 A = kron (I, S) + kron (S, I); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2118 |
16634 | 2119 endfunction |
2120 | |
2121 function A = prolate (n, w = 0.25) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2122 |
16634 | 2123 ## PROLATE Prolate matrix - symmetric, ill-conditioned Toeplitz matrix. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2124 ## A = PROLATE(N, W) is the N-by-N prolate matrix with parameter W. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2125 ## It is a symmetric Toeplitz matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2126 ## If 0 < W < 0.5 then |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2127 ## - A is positive definite |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2128 ## - the eigenvalues of A are distinct, lie in (0, 1), and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2129 ## tend to cluster around 0 and 1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2130 ## W defaults to 0.25. |
16634 | 2131 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2132 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2133 ## J.M. Varah. The Prolate matrix. Linear Algebra and Appl., |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2134 ## 187:269--278, 1993. |
16634 | 2135 |
2136 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2137 error ("gallery: 1 to 2 arguments are required for prolate matrix"); |
16634 | 2138 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2139 error ("gallery: N must be an integer for prolate matrix"); |
16634 | 2140 elseif (! isnumeric (w) || ! isscalar (w)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2141 error ("gallery: W must be a scalar for prolate matrix"); |
16634 | 2142 endif |
2143 | |
2144 a = zeros (n, 1); | |
2145 a(1) = 2*w; | |
2146 a(2:n) = sin (2*pi*w*(1:n-1)) ./ (pi*(1:n-1)); | |
2147 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
2148 A = toeplitz (a); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2149 |
16634 | 2150 endfunction |
2151 | |
2152 function H = randhess (x) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2153 |
16634 | 2154 ## NOTE: this function was named ohess in the original Test Matrix Toolbox |
2155 ## RANDHESS Random, orthogonal upper Hessenberg matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2156 ## H = RANDHESS(N) is an N-by-N real, random, orthogonal |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2157 ## upper Hessenberg matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2158 ## Alternatively, H = RANDHESS(X), where X is an arbitrary real |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2159 ## N-vector (N > 1) constructs H non-randomly using the elements |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2160 ## of X as parameters. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2161 ## In both cases H is constructed via a product of N-1 Givens rotations. |
16634 | 2162 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2163 ## Note: See Gragg (1986) for how to represent an N-by-N (complex) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2164 ## unitary Hessenberg matrix with positive subdiagonal elements in terms |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2165 ## of 2N-1 real parameters (the Schur parametrization). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2166 ## This M-file handles the real case only and is intended simply as a |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2167 ## convenient way to generate random or non-random orthogonal Hessenberg |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2168 ## matrices. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2169 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2170 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2171 ## W.B. Gragg, The QR algorithm for unitary Hessenberg matrices, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2172 ## J. Comp. Appl. Math., 16 (1986), pp. 1-8. |
16634 | 2173 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2174 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2175 error ("gallery: 1 argument is required for randhess matrix"); |
16634 | 2176 elseif (! isnumeric (x) || ! isreal (x)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2177 error ("gallery: N or X must be numeric real values for randhess matrix"); |
16634 | 2178 endif |
2179 | |
2180 if (isscalar (x)) | |
2181 n = x; | |
2182 x = rand (n-1, 1) * 2*pi; | |
2183 H = eye (n); | |
2184 H(n,n) = sign (randn); | |
2185 elseif (isvector (x)) | |
2186 n = numel (x); | |
2187 H = eye (n); | |
2188 H(n,n) = sign (x(n)) + (x(n) == 0); # Second term ensures H(n,n) nonzero. | |
2189 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2190 error ("gallery: N or X must be a scalar or a vector for randhess matrix"); |
16634 | 2191 endif |
2192 | |
2193 for i = n:-1:2 | |
2194 ## Apply Givens rotation through angle x(i-1). | |
2195 theta = x(i-1); | |
2196 c = cos (theta); | |
2197 s = sin (theta); | |
2198 H([i-1 i], :) = [ c*H(i-1,:)+s*H(i,:) | |
2199 -s*H(i-1,:)+c*H(i,:) ]; | |
2200 endfor | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2201 |
16634 | 2202 endfunction |
2203 | |
2204 function A = rando (n, k = 1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2205 |
16634 | 2206 ## RANDO Random matrix with elements -1, 0 or 1. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2207 ## A = RANDO(N, K) is a random N-by-N matrix with elements from |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2208 ## one of the following discrete distributions (default K = 1): |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2209 ## K = 1: A(i,j) = 0 or 1 with equal probability, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2210 ## K = 2: A(i,j) = -1 or 1 with equal probability, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2211 ## K = 3: A(i,j) = -1, 0 or 1 with equal probability. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2212 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). |
16634 | 2213 |
2214 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2215 error ("gallery: 1 to 2 arguments are required for rando matrix"); |
16634 | 2216 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2217 error ("gallery: N must be an integer for rando matrix"); |
16634 | 2218 elseif (! isnumeric (k) || ! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2219 error ("gallery: K must be a numeric scalar for smoke matrix"); |
16634 | 2220 endif |
2221 | |
2222 ## Parameter n specifies dimension: m-by-n. | |
2223 m = n(1); | |
2224 n = n(end); | |
2225 | |
2226 switch (k) | |
2227 case (1), A = floor ( rand(m, n) + 0.5); # {0, 1} | |
2228 case (2), A = 2*floor ( rand(m, n) + 0.5) -1; # {-1, 1} | |
2229 case (3), A = round (3*rand(m, n) - 1.5); # {-1, 0, 1} | |
2230 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2231 error ("gallery: unknown K '%d' for smoke matrix", k); |
16634 | 2232 endswitch |
2233 | |
2234 endfunction | |
2235 | |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2236 function A = randsvd (n, kappa = sqrt (1/eps), mode = 3, kl = max (n) -1, |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2237 ku = kl) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2238 |
16634 | 2239 ## RANDSVD Random matrix with pre-assigned singular values. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2240 ## RANDSVD(N, KAPPA, MODE, KL, KU) is a (banded) random matrix of order N |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2241 ## with COND(A) = KAPPA and singular values from the distribution MODE. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2242 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2243 ## Available types: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2244 ## MODE = 1: one large singular value, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2245 ## MODE = 2: one small singular value, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2246 ## MODE = 3: geometrically distributed singular values, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2247 ## MODE = 4: arithmetically distributed singular values, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2248 ## MODE = 5: random singular values with unif. dist. logarithm. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2249 ## If omitted, MODE defaults to 3, and KAPPA defaults to SQRT(1/EPS). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2250 ## If MODE < 0 then the effect is as for ABS(MODE) except that in the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2251 ## original matrix of singular values the order of the diagonal entries |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2252 ## is reversed: small to large instead of large to small. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2253 ## KL and KU are the lower and upper bandwidths respectively; if they |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2254 ## are omitted a full matrix is produced. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2255 ## If only KL is present, KU defaults to KL. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2256 ## Special case: if KAPPA < 0 then a random full symmetric positive |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2257 ## definite matrix is produced with COND(A) = -KAPPA and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2258 ## eigenvalues distributed according to MODE. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2259 ## KL and KU, if present, are ignored. |
16634 | 2260 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2261 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2262 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2263 ## Society for Industrial and Applied Mathematics, Philadelphia, PA, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2264 ## USA, 1996; sec. 26.3. |
16634 | 2265 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2266 ## This routine is similar to the more comprehensive Fortran routine xLATMS |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2267 ## in the following reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2268 ## J.W. Demmel and A. McKenney, A test matrix generation suite, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2269 ## LAPACK Working Note #9, Courant Institute of Mathematical Sciences, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2270 ## New York, 1989. |
16634 | 2271 |
2272 if (nargin < 1 || nargin > 5) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2273 error ("gallery: 1 to 5 arguments are required for randsvd matrix"); |
16634 | 2274 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2275 error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix"); |
16634 | 2276 elseif (! isnumeric (kappa) || ! isscalar (kappa)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2277 error ("gallery: KAPPA must be a numeric scalar for randsvd matrix"); |
16634 | 2278 elseif (abs (kappa) < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2279 error ("gallery: KAPPA must larger than or equal to 1 for randsvd matrix"); |
16634 | 2280 elseif (! isnumeric (mode) || ! isscalar (mode)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2281 error ("gallery: MODE must be a numeric scalar for randsvd matrix"); |
16634 | 2282 elseif (! isnumeric (kl) || ! isscalar (kl)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2283 error ("gallery: KL must be a numeric scalar for randsvd matrix"); |
16634 | 2284 elseif (! isnumeric (ku) || ! isscalar (ku)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2285 error ("gallery: KU must be a numeric scalar for randsvd matrix"); |
16634 | 2286 endif |
2287 | |
2288 posdef = 0; | |
2289 if (kappa < 0) | |
2290 posdef = 1; | |
2291 kappa = -kappa; | |
2292 endif | |
2293 | |
2294 ## Parameter n specifies dimension: m-by-n. | |
2295 m = n(1); | |
2296 n = n(end); | |
2297 p = min ([m n]); | |
2298 | |
2299 ## If A will be a vector | |
2300 if (p == 1) | |
2301 A = randn (m, n); | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2302 A /= norm (A); |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2303 return; |
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2304 endif |
16634 | 2305 |
2306 ## Set up vector sigma of singular values. | |
2307 switch (abs (mode)) | |
2308 case (1) | |
2309 sigma = ones (p, 1) ./ kappa; | |
2310 sigma(1) = 1; | |
2311 case (2) | |
2312 sigma = ones (p, 1); | |
2313 sigma(p) = 1 / kappa; | |
2314 case (3) | |
2315 factor = kappa^(-1/(p-1)); | |
2316 sigma = factor.^[0:p-1]; | |
2317 case (4) | |
2318 sigma = ones (p, 1) - (0:p-1)'/(p-1)*(1-1/kappa); | |
2319 case (5) | |
2320 ## In this case cond (A) <= kappa. | |
2321 rand ("uniform"); | |
2322 sigma = exp (-rand (p, 1) * log (kappa)); | |
2323 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2324 error ("gallery: unknown MODE '%d' for randsvd matrix", mode); |
16634 | 2325 endswitch |
2326 | |
2327 ## Convert to diagonal matrix of singular values. | |
2328 if (mode < 0) | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2329 sigma = sigma(p:-1:1); |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2330 endif |
16634 | 2331 sigma = diag (sigma); |
2332 | |
2333 if (posdef) | |
2334 ## handle case where KAPPA was negative | |
2335 Q = qmult (p); | |
2336 A = Q' * sigma * Q; | |
2337 A = (A + A') / 2; # Ensure matrix is symmetric. | |
17312
088d014a7fe2
Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents:
17306
diff
changeset
|
2338 return; |
16634 | 2339 endif |
2340 | |
2341 if (m != n) | |
2342 ## Expand to m-by-n diagonal matrix | |
2343 sigma(m, n) = 0; | |
17306
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2344 endif |
16634 | 2345 |
2346 if (kl == 0 && ku == 0) | |
2347 ## Diagonal matrix requested - nothing more to do. | |
2348 A = sigma; | |
2349 else | |
2350 ## A = U*sigma*V, where U, V are random orthogonal matrices from the | |
2351 ## Haar distribution. | |
2352 A = qmult (sigma'); | |
2353 A = qmult (A'); | |
2354 | |
2355 if (kl < n-1 || ku < n-1) | |
2356 ## Bandwidth reduction | |
2357 A = bandred (A, kl, ku); | |
2358 endif | |
2359 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2360 |
16634 | 2361 endfunction |
2362 | |
2363 function A = redheff (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2364 |
16634 | 2365 ## REDHEFF A (0,1) matrix of Redheffer associated with the Riemann hypothesis. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2366 ## A = REDHEFF(N) is an N-by-N matrix of 0s and 1s defined by |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2367 ## A(i,j) = 1 if j = 1 or if i divides j, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2368 ## A(i,j) = 0 otherwise. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2369 ## It has N - FLOOR(LOG2(N)) - 1 eigenvalues equal to 1, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2370 ## a real eigenvalue (the spectral radius) approximately SQRT(N), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2371 ## a negative eigenvalue approximately -SQRT(N), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2372 ## and the remaining eigenvalues are provably ``small''. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2373 ## Barrett and Jarvis (1992) conjecture that |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2374 ## ``the small eigenvalues all lie inside the unit circle |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2375 ## ABS(Z) = 1'', |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2376 ## and a proof of this conjecture, together with a proof that some |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2377 ## eigenvalue tends to zero as N tends to infinity, would yield |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2378 ## a new proof of the prime number theorem. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2379 ## The Riemann hypothesis is true if and only if |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2380 ## DET(A) = O( N^(1/2+epsilon) ) for every epsilon > 0 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2381 ## ('!' denotes factorial). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2382 ## See also RIEMANN. |
16634 | 2383 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2384 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2385 ## W.W. Barrett and T.J. Jarvis, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2386 ## Spectral Properties of a Matrix of Redheffer, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2387 ## Linear Algebra and Appl., 162 (1992), pp. 673-683. |
16634 | 2388 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2389 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2390 error ("gallery: 1 argument is required for redheff matrix"); |
16634 | 2391 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2392 error ("gallery: N must be an integer for redheff matrix"); |
16634 | 2393 endif |
2394 | |
2395 i = (1:n)' * ones (1, n); | |
2396 A = ! rem (i', i); | |
2397 A(:,1) = ones (n, 1); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2398 |
16634 | 2399 endfunction |
2400 | |
2401 function A = riemann (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2402 |
16634 | 2403 ## RIEMANN A matrix associated with the Riemann hypothesis. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2404 ## A = RIEMANN(N) is an N-by-N matrix for which the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2405 ## Riemann hypothesis is true if and only if |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2406 ## DET(A) = O( N! N^(-1/2+epsilon) ) for every epsilon > 0 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2407 ## ('!' denotes factorial). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2408 ## A = B(2:N+1, 2:N+1), where |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2409 ## B(i,j) = i-1 if i divides j and -1 otherwise. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2410 ## Properties include, with M = N+1: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2411 ## Each eigenvalue E(i) satisfies ABS(E(i)) <= M - 1/M. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2412 ## i <= E(i) <= i+1 with at most M-SQRT(M) exceptions. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2413 ## All integers in the interval (M/3, M/2] are eigenvalues. |
16634 | 2414 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2415 ## See also REDHEFF. |
16634 | 2416 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2417 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2418 ## F. Roesler, Riemann's hypothesis as an eigenvalue problem, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2419 ## Linear Algebra and Appl., 81 (1986), pp. 153-198. |
16634 | 2420 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2421 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2422 error ("gallery: 1 argument is required for riemann matrix"); |
16634 | 2423 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2424 error ("gallery: N must be an integer for riemann matrix"); |
16634 | 2425 endif |
2426 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2427 n += 1; |
16634 | 2428 i = (2:n)' * ones (1, n-1); |
2429 j = i'; | |
2430 A = i .* (! rem (j, i)) - ones (n-1); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2431 |
16634 | 2432 endfunction |
2433 | |
2434 function A = ris (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2435 |
16634 | 2436 ## NOTE: this function was named dingdong in the original Test Matrix Toolbox |
2437 ## RIS Dingdong matrix - a symmetric Hankel matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2438 ## A = RIS(N) is the symmetric N-by-N Hankel matrix with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2439 ## A(i,j) = 0.5/(N-i-j+1.5). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2440 ## The eigenvalues of A cluster around PI/2 and -PI/2. |
16634 | 2441 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2442 ## Invented by F.N. Ris. |
16634 | 2443 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2444 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2445 ## J.C. Nash, Compact Numerical Methods for Computers: Linear |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2446 ## Algebra and Function Minimisation, second edition, Adam Hilger, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2447 ## Bristol, 1990 (Appendix 1). |
16634 | 2448 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2449 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2450 error ("gallery: 1 argument is required for ris matrix"); |
16634 | 2451 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2452 error ("gallery: N must be an integer for ris matrix"); |
16634 | 2453 endif |
2454 | |
2455 p = -2*(1:n) + (n+1.5); | |
2456 A = cauchy (p); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2457 |
16634 | 2458 endfunction |
2459 | |
2460 function A = smoke (n, k = 0) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2461 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2462 ## SMOKE Smoke matrix - complex, with a 'smoke ring' pseudospectrum. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2463 ## SMOKE(N) is an N-by-N matrix with 1s on the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2464 ## superdiagonal, 1 in the (N,1) position, and powers of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2465 ## roots of unity along the diagonal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2466 ## SMOKE(N, 1) is the same except for a zero (N,1) element. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2467 ## The eigenvalues of SMOKE(N, 1) are the N'th roots of unity; |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2468 ## those of SMOKE(N) are the N'th roots of unity times 2^(1/N). |
16634 | 2469 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2470 ## Try PS(SMOKE(32)). For SMOKE(N, 1) the pseudospectrum looks |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2471 ## like a sausage folded back on itself. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2472 ## GERSH(SMOKE(N, 1)) is interesting. |
16634 | 2473 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2474 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2475 ## L. Reichel and L.N. Trefethen, Eigenvalues and pseudo-eigenvalues of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2476 ## Toeplitz matrices, Linear Algebra and Appl., 162-164:153-185, 1992. |
16634 | 2477 |
2478 if (nargin < 1 || nargin > 2) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2479 error ("gallery: 1 to 2 arguments are required for smoke matrix"); |
16634 | 2480 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2481 error ("gallery: N must be an integer for smoke matrix"); |
16634 | 2482 elseif (! isnumeric (n) || ! isscalar (n)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2483 error ("gallery: K must be a numeric scalar for smoke matrix"); |
16634 | 2484 endif |
2485 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
2486 w = exp (2*pi*i/n); |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
2487 A = diag ( [w.^(1:n-1) 1] ) + diag (ones (n-1,1), 1); |
16634 | 2488 |
2489 switch (k) | |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
2490 case 0, A(n,1) = 1; |
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31548
diff
changeset
|
2491 case 1, # do nothing |
16634 | 2492 otherwise, |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2493 error ("gallery: K must have a value of 0 or 1 for smoke matrix"); |
16634 | 2494 endswitch |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2495 |
16634 | 2496 endfunction |
2497 | |
2498 function T = toeppd (n, m = n, w = rand (m,1), theta = rand (m,1)) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2499 |
16634 | 2500 ## NOTE: this function was named pdtoep in the original Test Matrix Toolbox |
2501 ## TOEPPD Symmetric positive definite Toeplitz matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2502 ## TOEPPD(N, M, W, THETA) is an N-by-N symmetric positive (semi-) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2503 ## definite (SPD) Toeplitz matrix, comprised of the sum of M rank 2 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2504 ## (or, for certain THETA, rank 1) SPD Toeplitz matrices. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2505 ## Specifically, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2506 ## T = W(1)*T(THETA(1)) + ... + W(M)*T(THETA(M)), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2507 ## where T(THETA(k)) has (i,j) element COS(2*PI*THETA(k)*(i-j)). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2508 ## Defaults: M = N, W = RAND(M,1), THETA = RAND(M,1). |
16634 | 2509 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2510 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2511 ## G. Cybenko and C.F. Van Loan, Computing the minimum eigenvalue of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2512 ## a symmetric positive definite Toeplitz matrix, SIAM J. Sci. Stat. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2513 ## Comput., 7 (1986), pp. 123-131. |
16634 | 2514 |
2515 if (nargin < 1 || nargin > 4) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2516 error ("gallery: 1 to 4 arguments are required for toeppd matrix"); |
16634 | 2517 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2518 error ("gallery: N must be a numeric integer for toeppd matrix"); |
16634 | 2519 elseif (! isnumeric (m) || ! isscalar (m) || fix (m) != m) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2520 error ("gallery: M must be a numeric integer for toeppd matrix"); |
16634 | 2521 elseif (numel (w) != m || numel (theta) != m) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2522 error ("gallery: W and THETA must be vectors of length M for toeppd matrix"); |
16634 | 2523 endif |
2524 | |
2525 T = zeros (n); | |
2526 E = 2*pi * ((1:n)' * ones (1, n) - ones (n, 1) * (1:n)); | |
2527 | |
2528 for i = 1:m | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2529 T += w(i) * cos (theta(i)*E); |
16634 | 2530 endfor |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2531 |
16634 | 2532 endfunction |
2533 | |
2534 function P = toeppen (n, a = 1, b = -10, c = 0, d = 10, e = 1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2535 |
16634 | 2536 ## NOTE: this function was named pentoep in the original Test Matrix Toolbox |
2537 ## TOEPPEN Pentadiagonal Toeplitz matrix (sparse). | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2538 ## P = TOEPPEN(N, A, B, C, D, E) is the N-by-N pentadiagonal |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2539 ## Toeplitz matrix with diagonals composed of the numbers |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2540 ## A =: P(3,1), B =: P(2,1), C =: P(1,1), D =: P(1,2), E =: P(1,3). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2541 ## Default: (A,B,C,D,E) = (1,-10,0,10,1) (a matrix of Rutishauser). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2542 ## This matrix has eigenvalues lying approximately on |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2543 ## the line segment 2*cos(2*t) + 20*i*sin(t). |
16634 | 2544 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2545 ## Interesting plots are |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2546 ## PS(FULL(TOEPPEN(32,0,1,0,0,1/4))) - 'triangle' |
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2547 ## PS(FULL(TOEPPEN(32,0,1/2,0,0,1))) - 'propeller' |
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2548 ## PS(FULL(TOEPPEN(32,0,1/2,1,1,1))) - 'fish' |
16634 | 2549 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2550 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2551 ## R.M. Beam and R.F. Warming, The asymptotic spectra of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2552 ## banded Toeplitz and quasi-Toeplitz matrices, SIAM J. Sci. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2553 ## Comput. 14 (4), 1993, pp. 971-1006. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2554 ## H. Rutishauser, On test matrices, Programmation en Mathematiques |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2555 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2556 ## 1966, pp. 349-365. |
16634 | 2557 |
2558 if (nargin < 1 || nargin > 6) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2559 error ("gallery: 1 to 6 arguments are required for toeppen matrix"); |
16634 | 2560 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2561 error ("gallery: N must be a numeric integer for toeppen matrix"); |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30326
diff
changeset
|
2562 elseif (any (! cellfun ("isnumeric", {a b c d e})) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30326
diff
changeset
|
2563 || any (cellfun ("numel", {a b c d e}) != 1)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2564 error ("gallery: A, B, C, D and E must be numeric scalars for toeppen matrix"); |
16634 | 2565 endif |
2566 | |
2567 P = spdiags ([a*ones(n,1) b*ones(n,1) c*ones(n,1) d*ones(n,1) e*ones(n,1)], | |
2568 -2:2, n, n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2569 |
16634 | 2570 endfunction |
2571 | |
2572 function T = tridiag (n, x = -1, y = 2, z = -1) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2573 |
16634 | 2574 ## TRIDIAG Tridiagonal matrix (sparse). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2575 ## TRIDIAG(X, Y, Z) is the tridiagonal matrix with subdiagonal X, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2576 ## diagonal Y, and superdiagonal Z. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2577 ## X and Z must be vectors of dimension one less than Y. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2578 ## Alternatively TRIDIAG(N, C, D, E), where C, D, and E are all |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2579 ## scalars, yields the Toeplitz tridiagonal matrix of order N |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2580 ## with subdiagonal elements C, diagonal elements D, and superdiagonal |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2581 ## elements E. This matrix has eigenvalues (Todd 1977) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2582 ## D + 2*SQRT(C*E)*COS(k*PI/(N+1)), k=1:N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2583 ## TRIDIAG(N) is the same as TRIDIAG(N,-1,2,-1), which is |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2584 ## a symmetric positive definite M-matrix (the negative of the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2585 ## second difference matrix). |
16634 | 2586 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2587 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2588 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2589 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 155. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2590 ## D.E. Rutherford, Some continuant determinants arising in physics and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2591 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. |
16634 | 2592 |
2593 if (nargin != 1 && nargin != 3 && nargin != 4) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2594 error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix"); |
16634 | 2595 elseif (nargin == 3) |
2596 z = y; | |
2597 y = x; | |
2598 x = n; | |
2599 endif | |
2600 | |
2601 ## Force column vectors | |
2602 x = x(:); | |
2603 y = y(:); | |
2604 z = z(:); | |
2605 | |
2606 if (isscalar (x) && isscalar (y) && isscalar (z)) | |
2607 x *= ones (n-1, 1); | |
2608 z *= ones (n-1, 1); | |
2609 y *= ones (n, 1); | |
2610 elseif (numel (y) != numel (x) + 1) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2611 error ("gallery: X must have one element less than Y for tridiag matrix"); |
16634 | 2612 elseif (numel (y) != numel (z) + 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2613 error ("gallery: Z must have one element less than Y for tridiag matrix"); |
16634 | 2614 endif |
2615 | |
2616 ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. | |
2617 n = numel (y); | |
2618 T = spdiags ([[x;0] y [0;z]], -1:1, n, n); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2619 |
16634 | 2620 endfunction |
2621 | |
18846
3d33fe79816c
gallery.m: Return correct matrix if 3rd argument is not specified.
Rik <rik@octave.org>
parents:
18812
diff
changeset
|
2622 function t = triw (n, alpha = -1, k = n(end) - 1) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2623 |
16634 | 2624 ## TRIW Upper triangular matrix discussed by Wilkinson and others. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2625 ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2626 ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2627 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2) and |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2628 ## upper trapezoidal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2629 ## Defaults: ALPHA = -1, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2630 ## K = N - 1 (full upper triangle). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2631 ## TRIW(N) is a matrix discussed by Kahan, Golub and Wilkinson. |
16634 | 2632 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2633 ## Ostrowski (1954) shows that |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2634 ## COND(TRIW(N,2)) = COT(PI/(4*N))^2, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2635 ## and for large ABS(ALPHA), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2636 ## COND(TRIW(N,ALPHA)) is approximately ABS(ALPHA)^N*SIN(PI/(4*N-2)). |
16634 | 2637 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2638 ## Adding -2^(2-N) to the (N,1) element makes TRIW(N) singular, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2639 ## as does adding -2^(1-N) to all elements in the first column. |
16634 | 2640 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2641 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2642 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2643 ## computation of the Jordan canonical form, SIAM Review, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2644 ## 18(4), 1976, pp. 578-619. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2645 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2646 ## 9 (1966), pp. 757-801. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2647 ## A.M. Ostrowski, On the spectrum of a one-parametric family of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2648 ## matrices, J. Reine Angew. Math., 193 (3/4), 1954, pp. 143-160. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2649 ## J.H. Wilkinson, Singular-value decomposition---basic aspects, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2650 ## in D.A.H. Jacobs, ed., Numerical Software---Needs and Availability, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2651 ## Academic Press, London, 1978, pp. 109-135. |
16634 | 2652 |
2653 if (nargin < 1 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2654 error ("gallery: 1 to 3 arguments are required for triw matrix"); |
16634 | 2655 elseif (! isnumeric (n) || all (numel (n) != [1 2])) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2656 error ("gallery: N must be a 1 or 2 elements vector for triw matrix"); |
16634 | 2657 elseif (! isscalar (alpha)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2658 error ("gallery: ALPHA must be a scalar for triw matrix"); |
18846
3d33fe79816c
gallery.m: Return correct matrix if 3rd argument is not specified.
Rik <rik@octave.org>
parents:
18812
diff
changeset
|
2659 elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k || k < 0) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2660 error ("gallery: K must be a numeric integer >= 0 for triw matrix"); |
16634 | 2661 endif |
2662 | |
2663 m = n(1); # Parameter n specifies dimension: m-by-n. | |
2664 n = n(end); | |
2665 | |
2666 t = tril (eye (m, n) + alpha * triu (ones (m, n), 1), k); | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2667 |
16634 | 2668 endfunction |
2669 | |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2670 function A = uniformdata (varargin) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2671 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2672 if (nargin < 2) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2673 error ("gallery: At least 2 arguments required for uniformdata matrix"); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2674 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2675 if (isnumeric (varargin{end})) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2676 jidx = varargin{end}; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2677 svec = [varargin{:}]; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2678 varargin(end) = []; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2679 elseif (ischar (varargin{end})) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2680 if (nargin < 3) |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2681 error (["gallery: CLASS argument requires 3 inputs " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2682 "for uniformdata matrix."]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2683 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2684 jidx = varargin{end-1}; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2685 svec = [varargin{1:end-1}]; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2686 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2687 else |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2688 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2689 "for uniformdata matrix"]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2690 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2691 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2692 if (! (isnumeric (jidx) && isscalar (jidx) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2693 && jidx == fix (jidx) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2694 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2695 error (["gallery: J must be an integer in the range [0, 2^32-1] " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2696 "for uniformdata matrix"]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2697 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2698 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2699 ## Save and restore random state. Initialization done so that reproducible |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2700 ## data is available from gallery depending on the jidx and size vector. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2701 randstate = rand ("state"); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2702 unwind_protect |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2703 rand ("state", svec); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2704 A = rand (varargin{:}); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2705 unwind_protect_cleanup |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2706 rand ("state", randstate); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2707 end_unwind_protect |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2708 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2709 endfunction |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2710 |
16634 | 2711 function A = wathen (nx, ny, k = 0) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2712 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2713 ## WATHEN returns the Wathen matrix. |
16634 | 2714 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2715 ## Discussion: |
16634 | 2716 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2717 ## The Wathen matrix is a finite element matrix which is sparse. |
16634 | 2718 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2719 ## The entries of the matrix depend in part on a physical quantity |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2720 ## related to density. That density is here assigned random values between |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2721 ## 0 and 100. |
16634 | 2722 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2723 ## A = WATHEN ( NX, NY ) is a sparse random N-by-N finite element matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2724 ## where N = 3*NX*NY + 2*NX + 2*NY + 1. |
16634 | 2725 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2726 ## A is the consistent mass matrix for a regular NX-by-NY |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2727 ## grid of 8-node (serendipity) elements in 2 space dimensions. |
16634 | 2728 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2729 ## Here is an illustration for NX = 3, NX = 2: |
16634 | 2730 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2731 ## 23-24-25-26-27-28-29 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2732 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2733 ## 19 20 21 22 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2734 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2735 ## 12-13-14-15-16-17-18 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2736 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2737 ## 8 9 10 11 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2738 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2739 ## 1--2--3--4--5--6--7 |
16634 | 2740 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2741 ## For this example, the total number of nodes is, as expected, |
16634 | 2742 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2743 ## N = 3 * 3 * 2 + 2 * 2 + 2 * 3 + 1 = 29. |
16634 | 2744 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2745 ## A is symmetric positive definite for any (positive) values of |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2746 ## the density, RHO(NX,NY), which is chosen randomly in this routine. |
16634 | 2747 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2748 ## In particular, if D = DIAG(DIAG(A)), then |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2749 ## 0.25 <= EIG(INV(D)*A) <= 4.5 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2750 ## for any positive integers NX and NY and any densities RHO(NX,NY). |
16634 | 2751 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2752 ## A = WATHEN ( NX, NY, 1 ) returns the diagonally scaled matrix. |
16634 | 2753 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2754 ## Modified: |
16634 | 2755 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2756 ## 17 September 2007 |
16634 | 2757 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2758 ## Author: |
16634 | 2759 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2760 ## Nicholas Higham |
16634 | 2761 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2762 ## Reference: |
16634 | 2763 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2764 ## Nicholas Higham, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2765 ## Algorithm 694: A Collection of Test Matrices in MATLAB, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2766 ## ACM Transactions on Mathematical Software, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2767 ## Volume 17, Number 3, September 1991, pages 289-305. |
16634 | 2768 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2769 ## Andrew Wathen, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2770 ## Realistic eigenvalue bounds for the Galerkin mass matrix, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2771 ## IMA Journal of Numerical Analysis, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2772 ## Volume 7, 1987, pages 449-457. |
16634 | 2773 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2774 ## Parameters: |
16634 | 2775 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2776 ## Input, integer NX, NY, the number of elements in the X and Y directions |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2777 ## of the finite element grid. NX and NY must each be at least 1. |
16634 | 2778 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2779 ## Optional input, integer K, is used to request that the diagonally scaled |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2780 ## version of the matrix be returned. This happens if K is specified with |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2781 ## the value 1. |
16634 | 2782 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2783 ## Output, sparse real A(N,N), the matrix. The dimension N is determined by |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2784 ## NX and NY, as described above. A is stored in the MATLAB sparse matrix |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2785 ## format. |
16634 | 2786 |
2787 if (nargin < 2 || nargin > 3) | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2788 error ("gallery: 2 or 3 arguments are required for wathen matrix"); |
16634 | 2789 elseif (! isnumeric (nx) || ! isscalar (nx) || nx < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2790 error ("gallery: NX must be a positive scalar for wathen matrix"); |
16634 | 2791 elseif (! isnumeric (ny) || ! isscalar (ny) || ny < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2792 error ("gallery: NY must be a positive scalar for wathen matrix"); |
16634 | 2793 elseif (! isscalar (k)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2794 error ("gallery: K must be a scalar for wathen matrix"); |
16634 | 2795 endif |
2796 | |
2797 e1 = [ 6 -6 2 -8 | |
2798 -6 32 -6 20 | |
2799 2 -6 6 -6 | |
2800 -8 20 -6 32 ]; | |
2801 | |
2802 e2 = [ 3 -8 2 -6 | |
2803 -8 16 -8 20 | |
2804 2 -8 3 -8 | |
2805 -6 20 -8 16 ]; | |
2806 | |
2807 e = [ e1 e2 | |
2808 e2' e1] / 45; | |
2809 | |
2810 n = 3*nx*ny + 2*nx + 2*ny + 1; | |
2811 | |
2812 A = sparse (n, n); | |
2813 | |
2814 rho = 100 * rand (nx, ny); | |
2815 | |
2816 for j = 1:ny | |
2817 for i = 1:nx | |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2818 ## |
16634 | 2819 ## For the element (I,J), determine the indices of the 8 nodes. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2820 ## |
16634 | 2821 nn(1) = 3*j*nx + 2*i + 2*j + 1; |
2822 nn(2) = nn(1) - 1; | |
2823 nn(3) = nn(2) - 1; | |
2824 nn(4) = (3*j - 1) * nx + 2*j + i - 1; | |
2825 nn(5) = 3 * (j-1) * nx + 2*i + 2*j - 3; | |
2826 nn(6) = nn(5) + 1; | |
2827 nn(7) = nn(6) + 1; | |
2828 nn(8) = nn(4) + 1; | |
2829 | |
2830 em = e * rho(i,j); | |
2831 | |
2832 for krow = 1:8 | |
2833 for kcol = 1:8 | |
2834 A(nn(krow),nn(kcol)) = A(nn(krow),nn(kcol)) + em(krow,kcol); | |
2835 endfor | |
2836 endfor | |
2837 | |
2838 endfor | |
2839 endfor | |
2840 | |
2841 ## If requested, return A with diagonal scaling. | |
2842 if (k) | |
2843 A = diag (diag (A)) \ A; | |
2844 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2845 |
16634 | 2846 endfunction |
2847 | |
2848 function [A, b] = wilk (n) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2849 |
16634 | 2850 ## WILK Various specific matrices devised/discussed by Wilkinson. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2851 ## [A, b] = WILK(N) is the matrix or system of order N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2852 ## N = 3: upper triangular system Ux=b illustrating inaccurate solution. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2853 ## N = 4: lower triangular system Lx=b, ill-conditioned. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2854 ## N = 5: HILB(6)(1:5,2:6)*1.8144. Symmetric positive definite. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2855 ## N = 21: W21+, tridiagonal. Eigenvalue problem. |
16634 | 2856 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2857 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2858 ## J.H. Wilkinson, Error analysis of direct methods of matrix inversion, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2859 ## J. Assoc. Comput. Mach., 8 (1961), pp. 281-330. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2860 ## J.H. Wilkinson, Rounding Errors in Algebraic Processes, Notes on Applied |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2861 ## Science No. 32, Her Majesty's Stationery Office, London, 1963. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2862 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2863 ## Press, 1965. |
16634 | 2864 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2865 if (nargin < 1) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2866 error ("gallery: 1 argument is required for wilk matrix"); |
16634 | 2867 elseif (! isnumeric (n) || ! isscalar (n)) |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2868 error ("gallery: N must be a numeric scalar for wilk matrix"); |
16634 | 2869 endif |
2870 | |
2871 if (n == 3) | |
2872 ## Wilkinson (1961) p.323. | |
2873 A = [ 1e-10 0.9 -0.4 | |
2874 0 0.9 -0.4 | |
2875 0 0 1e-10 ]; | |
2876 | |
2877 b = [ 0 | |
2878 0 | |
2879 1]; | |
2880 | |
2881 elseif (n == 4) | |
2882 ## Wilkinson (1963) p.105. | |
2883 A = [0.9143e-4 0 0 0 | |
2884 0.8762 0.7156e-4 0 0 | |
2885 0.7943 0.8143 0.9504e-4 0 | |
2886 0.8017 0.6123 0.7165 0.7123e-4]; | |
2887 | |
2888 b = [0.6524 | |
2889 0.3127 | |
2890 0.4186 | |
2891 0.7853]; | |
2892 | |
2893 elseif (n == 5) | |
2894 ## Wilkinson (1965), p.234. | |
2895 A = hilb (6); | |
2896 A = A(1:5, 2:6) * 1.8144; | |
2897 | |
2898 elseif (n == 21) | |
2899 ## Wilkinson (1965), p.308. | |
2900 E = diag (ones (n-1, 1), 1); | |
2901 m = (n-1)/2; | |
2902 A = diag (abs (-m:m)) + E + E'; | |
2903 | |
2904 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2905 error ("gallery: unknown N '%d' for wilk matrix", n); |
16634 | 2906 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2907 |
16634 | 2908 endfunction |
2909 | |
2910 ## NOTE: bandred is part of the Test Matrix Toolbox and is used by randsvd() | |
2911 function A = bandred (A, kl, ku) | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2912 |
16634 | 2913 ## BANDRED Band reduction by two-sided unitary transformations. |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2914 ## B = BANDRED(A, KL, KU) is a matrix unitarily equivalent to A |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2915 ## with lower bandwidth KL and upper bandwidth KU |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2916 ## (i.e. B(i,j) = 0 if i > j+KL or j > i+KU). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2917 ## The reduction is performed using Householder transformations. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2918 ## If KU is omitted it defaults to KL. |
16634 | 2919 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2920 ## Called by RANDSVD. |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2921 ## This is a 'standard' reduction. Cf. reduction to bidiagonal form |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2922 ## prior to computing the SVD. This code is a little wasteful in that |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2923 ## it computes certain elements which are immediately set to zero! |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2924 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2925 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2926 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2927 ## Johns Hopkins University Press, Baltimore, Maryland, 1989. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2928 ## Section 5.4.3. |
16634 | 2929 |
2930 ## Check for special case where order of left/right transformations matters. | |
2931 ## Easiest approach is to work on the transpose, flipping back at the end. | |
2932 flip = false; | |
2933 if (ku == 0) | |
2934 flip = true; | |
2935 A = A'; | |
2936 [ku, kl] = deal (kl, ku); | |
2937 endif | |
2938 | |
2939 [m, n] = size (A); | |
2940 | |
2941 for j = 1:min (min (m, n), max (m-kl-1, n-ku-1)) | |
2942 if (j+kl+1 <= m) | |
2943 [v, beta] = house (A(j+kl:m,j)); | |
2944 temp = A(j+kl:m,j:n); | |
2945 A(j+kl:m,j:n) = temp - beta*v*(v'*temp); | |
2946 A(j+kl+1:m,j) = zeros (m-j-kl, 1); | |
2947 endif | |
2948 | |
2949 if (j+ku+1 <= n) | |
2950 [v, beta] = house (A(j,j+ku:n)'); | |
2951 temp = A(j:m,j+ku:n); | |
2952 A(j:m,j+ku:n) = temp - beta*(temp*v)*v'; | |
2953 A(j,j+ku+1:n) = zeros (1, n-j-ku); | |
2954 endif | |
2955 endfor | |
2956 | |
2957 if (flip) | |
2958 A = A'; | |
2959 endif | |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2960 |
16634 | 2961 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
2962 |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2963 ## NOTE: qmult is part of the Test Matrix Toolbox and is used by randsvd() |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2964 function B = qmult (A) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
2965 |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2966 ## QMULT Pre-multiply by random orthogonal matrix. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2967 ## QMULT(A) is Q*A where Q is a random real orthogonal matrix from |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2968 ## the Haar distribution, of dimension the number of rows in A. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2969 ## Special case: if A is a scalar then QMULT(A) is the same as |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2970 ## QMULT(EYE(A)). |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2971 ## |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2972 ## Called by RANDSVD. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2973 ## |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2974 ## Reference: |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2975 ## G.W. Stewart, The efficient generation of random |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2976 ## orthogonal matrices with an application to condition estimators, |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2977 ## SIAM J. Numer. Anal., 17 (1980), 403-409. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2978 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2979 [n, m] = size (A); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2980 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2981 ## Handle scalar A |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2982 if (isscalar (A)) |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2983 n = A; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2984 A = eye (n); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2985 endif |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2986 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2987 d = zeros (n); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2988 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2989 for k = n-1:-1:1 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2990 ## Generate random Householder transformation. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2991 x = randn (n-k+1, 1); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2992 s = norm (x); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2993 sgn = sign (x(1)) + (x(1) == 0); # Modification for sign(1)=1. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2994 s = sgn*s; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2995 d(k) = -sgn; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2996 x(1) = x(1) + s; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2997 beta = s*x(1); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2998 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2999 ## Apply the transformation to A. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3000 y = x'*A(k:n,:); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3001 A(k:n,:) = A(k:n,:) - x*(y/beta); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3002 endfor |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3003 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3004 ## Tidy up signs |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3005 for i = 1:n-1 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3006 A(i,:) = d(i)*A(i,:); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3007 endfor |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3008 A(n,:) = A(n,:) * sign (randn); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3009 B = A; |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
3010 |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
3011 endfunction |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3012 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
3013 |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3014 ## BIST testing for just a few functions to verify that the main gallery |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3015 ## dispatch function works. |
20929
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
3016 %!assert (gallery ("clement", 3), [0 1 0; 2 0 2; 0 1 0]) |
45a64a6c7273
fix comment character style in most .m files to be consistent
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
3017 %!assert (gallery ("invhess", 2), [1 -1; 1 2]) |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3018 |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3019 ## Test input validation of main dispatch function only |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28891
diff
changeset
|
3020 %!error <Invalid call> gallery () |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3021 %!error <NAME must be a string> gallery (123) |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3022 %!error <matrix binomial not implemented> gallery ("binomial") |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3023 %!error <unknown matrix with NAME foobar> gallery ("foobar") |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
3024 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
3025 ## BIST testing for individual gallery functions |
19944
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
3026 %!assert (gallery ("minij", 4), [1 1 1 1; 1 2 2 2; 1 2 3 3; 1 2 3 4]) |
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
3027 %!assert (gallery ("minij", 1), 1) |
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
3028 %!assert (gallery ("minij", 0), []) |
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
3029 %!assert (gallery ("minij", -1), []) |
20299
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3030 |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3031 %!test |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3032 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3033 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3034 %! 3 4 5 6 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3035 %! 4 5 6 7 8 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3036 %! 5 6 7 8 9 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3037 %! 6 7 8 9 10]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3038 %! assert (gallery ("cauchy", 5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3039 %! assert (gallery ("cauchy", 1:5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3040 %! assert (gallery ("cauchy", 1:5, 1:5), exp); |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3041 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3042 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3043 %! 1 2 3 4 5 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3044 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3045 %! 3 4 5 6 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3046 %! 4 5 6 7 8 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3047 %! 5 6 7 8 9]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3048 %! assert (gallery ("cauchy", 0:4, 1:5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3049 %! assert (gallery ("cauchy", 1:5, 0:4), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3050 %! assert (gallery ("cauchy", 1:5, 4:-1:0), fliplr (exp)); |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3051 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3052 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3053 %! -1 0 1 2 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3054 %! 0 1 2 3 4 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3055 %! 1 2 3 4 5 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3056 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3057 %! 3 4 5 6 7]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3058 %! assert (gallery ("cauchy", 1:5, -2:2), exp); |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3059 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3060 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3061 %! 8 18 -4 2 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3062 %! 13 23 1 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3063 %! 9 19 -3 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3064 %! 15 25 3 9]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3065 %! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3066 %! assert (gallery ("cauchy", [-2 3 -1 5], [10 20 -2 4]'), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3067 %! assert (gallery ("cauchy", [-2 3 -1 5]', [10 20 -2 4]), exp); |
20299
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3068 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3069 %!assert (size (gallery ("chebspec", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3070 %!assert (size (gallery ("chebspec", 5, 1)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3071 %!assert (size (gallery ("chebspec", 5, 0)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3072 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3073 %!assert (size (gallery ("chebvand", 7)), [7 7]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3074 %!assert (size (gallery ("chebvand", 1:7)), [7 7]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3075 %!assert (size (gallery ("chebvand", 5, 7)), [5 7]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3076 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3077 %!assert (size (gallery ("chow", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3078 %!assert (size (gallery ("chow", 5, 6)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3079 %!assert (size (gallery ("chow", 5, 6, 7)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3080 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3081 %!assert (gallery ("circul", 3), [1 2 3; 3 1 2; 2 3 1]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3082 %!assert (gallery ("circul", [1 3 6]), [1 3 6; 6 1 3; 3 6 1]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3083 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3084 %!assert (size (gallery ("clement", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3085 %!assert (size (gallery ("clement", 5, 1)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3086 %!assert (size (gallery ("clement", 5, 0)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3087 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3088 %!assert (size (gallery ("compar", ones (5))), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3089 %!assert (size (gallery ("compar", ones (5), 0)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3090 %!assert (size (gallery ("compar", ones (5), 1)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3091 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3092 %!assert (size (gallery ("condex", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3093 %!assert (size (gallery ("condex", 4, 1)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3094 %!assert (size (gallery ("condex", 4, 1, 50)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3095 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3096 %!assert (size (gallery ("cycol", [4 5])), [4 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3097 %!assert (size (gallery ("cycol", [4 5], 1)), [4 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3098 %!assert (size (gallery ("cycol", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3099 %!assert (size (gallery ("cycol", 4, 1)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3100 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3101 %!assert (size (gallery ("dorr", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3102 %!assert (cellfun (@rows, nthargout (1:3, @gallery, "dorr", 4)), [3 4 3]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3103 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3104 %!assert (size (gallery ("dramadah", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3105 %!assert (size (gallery ("dramadah", 5, 2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3106 |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3107 %!test |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3108 %! exp = [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3109 %! 0 1 2 3 4 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3110 %! 1 0 1 2 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3111 %! 2 1 0 1 2 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3112 %! 3 2 1 0 1 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3113 %! 4 3 2 1 0]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3114 %! assert (gallery ("fiedler", 5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3115 %! assert (gallery ("fiedler", 1:5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3116 %! assert (gallery ("fiedler", -2:2), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3117 %! assert (gallery ("fiedler", 2:5), exp(1:4,1:4)); |
20299
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3118 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3119 %!assert (size (gallery ("forsythe", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3120 %!assert (size (gallery ("forsythe", 5, 1, 0.5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3121 %!assert (size (gallery ("forsythe", 5, 4, 7)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3122 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3123 %!assert (size (gallery ("frank", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3124 %!assert (size (gallery ("frank", 5, 1)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3125 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3126 %!assert (size (gallery ("gcdmat", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3127 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3128 %!assert (size (gallery ("gearmat", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3129 %!assert (size (gallery ("gearmat", 5, 4)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3130 %!assert (size (gallery ("gearmat", 5, 4, 3)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3131 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3132 %!assert (size (gallery ("grcar", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3133 %!assert (size (gallery ("grcar", 5, 2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3134 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3135 %!error <N must be even> gallery ("hanowa", 5) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3136 %!assert (size (gallery ("hanowa", 6, 5)), [6 6]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3137 %!assert (size (gallery ("hanowa", 6, 5)), [6 6]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3138 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3139 %!assert (size (gallery ("house", [1:5]')), [5 1]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3140 %!assert (cellfun (@rows, nthargout (1:2, @gallery, "house", [1:5]')), [5 1]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3141 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3142 %!assert (size (gallery ("integerdata", 5, [3 2], 5)), [3 2]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3143 %!assert (size (gallery ("integerdata", 5, [3 2 6], 5)), [3 2 6]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3144 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3145 %!assert (size (gallery ("invhess", 1:4, 1:3)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3146 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3147 %!assert (size (gallery ("invol", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3148 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3149 %!assert (size (gallery ("ipjfact", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3150 %!assert (size (gallery ("ipjfact", 4, 0)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3151 %!assert (size (gallery ("ipjfact", 4, 1)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3152 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3153 %!assert (size (gallery ("jordbloc", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3154 %!assert (size (gallery ("jordbloc", 4, 1)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3155 %!assert (size (gallery ("jordbloc", 4, 3)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3156 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3157 %!assert (size (gallery ("kahan", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3158 %!assert (size (gallery ("kahan", [4 5])), [4 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3159 %!assert (size (gallery ("kahan", [4 5], 1)), [4 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3160 %!assert (size (gallery ("kahan", [4 5], 1, 30)), [4 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3161 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3162 %!assert (size (gallery ("kms", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3163 %!assert (size (gallery ("kms", 5, 0.2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3164 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3165 %!assert (size (gallery ("krylov", 4)), [4 4]) |
22021
e67ff2b11147
Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21759
diff
changeset
|
3166 %!assert (size (gallery ("krylov", ones (4))), [4 4]) |
e67ff2b11147
Check that second argument to size () is a scalar (bug #48368).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21759
diff
changeset
|
3167 %!assert (size (gallery ("krylov", ones (4), [.2 .3 .4 .5], 3)), [4 3]) |
20299
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3168 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3169 %!assert (size (gallery ("lauchli", 5)), [6 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3170 %!assert (size (gallery ("lauchli", 5, 3)), [6 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3171 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3172 %!assert (size (gallery ("lehmer", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3173 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3174 %!assert (size (gallery ("lesp", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3175 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3176 %!assert (size (gallery ("lotkin", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3177 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3178 %!assert (size (gallery ("minij", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3179 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3180 %!assert (size (gallery ("moler", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3181 %!assert (size (gallery ("moler", 5, 0.2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3182 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3183 %!assert (size (gallery ("neumann", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3184 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3185 %!assert (size (gallery ("normaldata", [5 4 6], 3)), [5 4 6]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3186 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3187 %!assert (size (gallery ("orthog", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3188 %!assert (size (gallery ("orthog", 5, 2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3189 %!assert (size (gallery ("orthog", 5, -2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3190 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3191 %!assert (size (gallery ("parter", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3192 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3193 %!assert (size (gallery ("pei", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3194 %!assert (size (gallery ("pei", 5, 4)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3195 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3196 %!assert (size (gallery ("poisson", 1)), [1 1]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3197 %!assert (size (gallery ("poisson", 4)), [16 16]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3198 %!assert (size (gallery ("poisson", 5)), [25 25]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3199 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3200 %!assert (size (gallery ("prolate", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3201 %!assert (size (gallery ("prolate", 5, 0.5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3202 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3203 %!assert (size (gallery ("randhess", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3204 %!assert (size (gallery ("randhess", 2:5)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3205 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3206 %!assert (size (gallery ("rando", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3207 %!assert (size (gallery ("rando", 5, 2)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3208 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3209 %!assert (size (gallery ("randsvd", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3210 %!assert (size (gallery ("randsvd", [5 3])), [5 3]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3211 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3212 %!assert (size (gallery ("redheff", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3213 %!assert (size (gallery ("riemann", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3214 %!assert (size (gallery ("ris", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3215 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3216 %!assert (size (gallery ("smoke", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3217 %!assert (size (gallery ("smoke", 5, 1)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3218 %!assert (gallery ("smoke", 5, 1)(5, 1), 0) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3219 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3220 %!assert (size (gallery ("toeppd", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3221 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3222 %!assert (size (gallery ("toeppen", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3223 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3224 %!assert (size (gallery ("tridiag", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3225 %!assert (size (gallery ("tridiag", 1:4, 1:5, 1:4)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3226 %!assert (gallery ("tridiag", 5), gallery ("tridiag", 5, -1, 2, -1)) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3227 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3228 %!assert (size (gallery ("triw", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3229 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3230 %!assert (size (gallery ("uniformdata", [5 3 4], 3)), [5 3 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3231 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3232 %!assert (size (gallery ("wathen", 2, 3)), [29 29]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3233 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3234 %!assert (cellfun (@rows, nthargout (1:2, @gallery, "wilk", 3)), [3 3]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3235 %!assert (cellfun (@rows, nthargout (1:2, @gallery, "wilk", 4)), [4 4]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3236 %!assert (size (gallery ("wilk", 5)), [5 5]) |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3237 %!assert (size (gallery ("wilk", 21)), [21 21]) |