Mercurial > octave
annotate scripts/special-matrix/gallery.m @ 28929:9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
* interpft.m, ind2rgb.m, null.m, inputParser.m, inputname.m, ode15i.m,
ode15s.m, ode23.m, ode23s.m, ode45.m, pathdef.m, camlookat.m, camzoom.m,
material.m, deconv.m, ismember.m, eigs.m, gmres.m, ilu.m, tfqmr.m, perms.m,
sinint.m, gallery.m, mean.m:
maint: Use semicolon after assert statement inside %!test blocks.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 14 Oct 2020 11:46:55 -0700 |
parents | 89a425f2c202 |
children | 7854d5752dd2 |
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 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 1989-2020 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); |
16634 | 443 case "cauchy" , [varargout{1:n_out}] = cauchy (varargin{:}); |
444 case "chebspec" , [varargout{1:n_out}] = chebspec (varargin{:}); | |
445 case "chebvand" , [varargout{1:n_out}] = chebvand (varargin{:}); | |
446 case "chow" , [varargout{1:n_out}] = chow (varargin{:}); | |
447 case "circul" , [varargout{1:n_out}] = circul (varargin{:}); | |
448 case "clement" , [varargout{1:n_out}] = clement (varargin{:}); | |
449 case "compar" , [varargout{1:n_out}] = compar (varargin{:}); | |
450 case "condex" , [varargout{1:n_out}] = condex (varargin{:}); | |
451 case "cycol" , [varargout{1:n_out}] = cycol (varargin{:}); | |
452 case "dorr" , [varargout{1:n_out}] = dorr (varargin{:}); | |
453 case "dramadah" , [varargout{1:n_out}] = dramadah (varargin{:}); | |
454 case "fiedler" , [varargout{1:n_out}] = fiedler (varargin{:}); | |
455 case "forsythe" , [varargout{1:n_out}] = forsythe (varargin{:}); | |
456 case "frank" , [varargout{1:n_out}] = frank (varargin{:}); | |
457 case "gearmat" , [varargout{1:n_out}] = gearmat (varargin{:}); | |
458 case "gcdmat" , [varargout{1:n_out}] = gcdmat (varargin{:}); | |
459 case "grcar" , [varargout{1:n_out}] = grcar (varargin{:}); | |
460 case "hanowa" , [varargout{1:n_out}] = hanowa (varargin{:}); | |
461 case "house" , [varargout{1:n_out}] = house (varargin{:}); | |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
462 case "integerdata", [varargout{1:n_out}] = integerdata (varargin{:}); |
16634 | 463 case "invhess" , [varargout{1:n_out}] = invhess (varargin{:}); |
464 case "invol" , [varargout{1:n_out}] = invol (varargin{:}); | |
465 case "ipjfact" , [varargout{1:n_out}] = ipjfact (varargin{:}); | |
466 case "jordbloc" , [varargout{1:n_out}] = jordbloc (varargin{:}); | |
467 case "kahan" , [varargout{1:n_out}] = kahan (varargin{:}); | |
468 case "kms" , [varargout{1:n_out}] = kms (varargin{:}); | |
469 case "krylov" , [varargout{1:n_out}] = krylov (varargin{:}); | |
470 case "lauchli" , [varargout{1:n_out}] = lauchli (varargin{:}); | |
471 case "lehmer" , [varargout{1:n_out}] = lehmer (varargin{:}); | |
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); |
16634 | 474 case "lesp" , [varargout{1:n_out}] = lesp (varargin{:}); |
475 case "lotkin" , [varargout{1:n_out}] = lotkin (varargin{:}); | |
476 case "minij" , [varargout{1:n_out}] = minij (varargin{:}); | |
477 case "moler" , [varargout{1:n_out}] = moler (varargin{:}); | |
478 case "neumann" , [varargout{1:n_out}] = neumann (varargin{:}); | |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
479 case "normaldata" , [varargout{1:n_out}] = normaldata (varargin{:}); |
16634 | 480 case "orthog" , [varargout{1:n_out}] = orthog (varargin{:}); |
481 case "parter" , [varargout{1:n_out}] = parter (varargin{:}); | |
482 case "pei" , [varargout{1:n_out}] = pei (varargin{:}); | |
483 case "poisson" , [varargout{1:n_out}] = poisson (varargin{:}); | |
484 case "prolate" , [varargout{1:n_out}] = prolate (varargin{:}); | |
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) | |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
514 ## CAUCHY Cauchy matrix. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
515 ## 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
|
516 ## 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
|
517 ## 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
|
518 ## 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
|
519 ## 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
|
520 ## 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
|
521 ## 0 < Y(1) < ... < Y(N). |
16634 | 522 ## |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
523 ## References: |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
524 ## 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
|
525 ## Society for Industrial and Applied Mathematics, Philadelphia, PA, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
526 ## USA, 1996; sec. 26.1. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
527 ## 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
|
528 ## Fundamental Algorithms, second edition, Addison-Wesley, Reading, |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
529 ## Massachusetts, 1973, p. 36. |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
530 ## 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
|
531 ## 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
|
532 ## 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
|
533 ## 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
|
534 ## pp. 279-313, 1962. (States the totally positive property on p. 295.) |
16634 | 535 |
536 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
|
537 error ("gallery: 1 or 2 arguments are required for cauchy matrix"); |
16634 | 538 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
|
539 error ("gallery: X must be numeric for cauchy matrix"); |
16634 | 540 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
|
541 error ("gallery: Y must be numeric for cauchy matrix"); |
16634 | 542 endif |
543 | |
544 n = numel (x); | |
545 if (isscalar (x) && fix (x) == x) | |
546 n = x; | |
547 x = 1:n; | |
548 elseif (n > 1 && isvector (x)) | |
549 ## do nothing | |
550 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
551 error ("gallery: X be an integer or a vector for cauchy matrix"); |
16634 | 552 endif |
553 | |
554 if (nargin == 1) | |
555 y = x; | |
556 endif | |
557 | |
558 ## Ensure x and y are column vectors | |
559 x = x(:); | |
560 y = y(:); | |
561 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
|
562 error ("gallery: X and Y must be vectors of same length for cauchy matrix"); |
16634 | 563 endif |
564 | |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
565 C = 1 ./ (x .+ y.'); |
16634 | 566 endfunction |
567 | |
568 function C = chebspec (n, k = 0) | |
569 ## 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
|
570 ## 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
|
571 ## 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
|
572 ## 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
|
573 ## 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
|
574 ## 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
|
575 ## 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
|
576 ## have negative real parts. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
577 ## 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
|
578 ## ill-conditioned (MESH(REAL(X)) is interesting). |
16634 | 579 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
580 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
581 ## 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
|
582 ## 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
|
583 ## 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
|
584 ## 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
|
585 ## 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
|
586 ## derivative, SIAM J. Sci. Stat. Comput., 9 (1988), pp. 1050-1057. |
16634 | 587 |
588 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
|
589 error ("gallery: 1 to 2 arguments are required for chebspec matrix"); |
16634 | 590 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
|
591 error ("gallery: N must be an integer for chebspec matrix"); |
16634 | 592 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
|
593 error ("gallery: K must be a scalar for chebspec matrix"); |
16634 | 594 endif |
595 | |
596 ## k = 1 case obtained from k = 0 case with one bigger n. | |
597 switch (k) | |
598 case (0), # do nothing | |
599 case (1), n = n + 1; | |
600 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
601 error ("gallery: K should be either 0 or 1 for chebspec matrix"); |
16634 | 602 endswitch |
603 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
604 n -= 1; |
16634 | 605 C = zeros (n+1); |
606 | |
607 one = ones (n+1, 1); | |
608 x = cos ((0:n)' * (pi/n)); | |
609 d = ones (n+1, 1); | |
610 d(1) = 2; | |
611 d(n+1) = 2; | |
612 | |
613 ## eye(size(C)) on next line avoids div by zero. | |
614 C = (d * (one./d)') ./ (x*one'-one*x' + eye (size (C))); | |
615 | |
616 ## Now fix diagonal and signs. | |
617 C(1,1) = (2*n^2+1)/6; | |
618 for i = 2:n+1 | |
619 if (rem (i, 2) == 0) | |
620 C(:,i) = -C(:,i); | |
621 C(i,:) = -C(i,:); | |
622 endif | |
623 if (i < n+1) | |
624 C(i,i) = -x(i)/(2*(1-x(i)^2)); | |
625 else | |
626 C(n+1,n+1) = -C(1,1); | |
627 endif | |
628 endfor | |
629 | |
630 if (k == 1) | |
631 C = C(2:n+1,2:n+1); | |
632 endif | |
633 endfunction | |
634 | |
635 function C = chebvand (m, p) | |
636 ## 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
|
637 ## 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
|
638 ## 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
|
639 ## 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
|
640 ## polynomial of degree i-1. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
641 ## 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
|
642 ## 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
|
643 ## [0,1] are used. |
16634 | 644 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
645 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
646 ## 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
|
647 ## 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
|
648 ## pp. 23-41. |
16634 | 649 |
650 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
|
651 error ("gallery: 1 or 2 arguments are required for chebvand matrix"); |
16634 | 652 endif |
653 | |
654 ## because the order of the arguments changes if nargin is 1 or 2 ... | |
655 | |
656 if (nargin == 1) | |
657 p = m; | |
658 endif | |
659 | |
660 n = numel (p); | |
661 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
|
662 error ("gallery: P must be numeric for chebvand matrix"); |
16634 | 663 elseif (isscalar (p) && fix (p) == p) |
664 n = p; | |
665 p = linspace (0, 1, n); | |
666 elseif (n > 1 && isvector (p)) | |
667 ## do nothing | |
668 endif | |
669 p = p(:).'; # Ensure p is a row vector. | |
670 | |
671 if (nargin == 1) | |
672 m = n; | |
673 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
|
674 error ("gallery: M must be a scalar for chebvand matrix"); |
16634 | 675 endif |
676 | |
677 C = ones (m, n); | |
678 if (m != 1) | |
679 C(2,:) = p; | |
680 ## Use Chebyshev polynomial recurrence. | |
681 for i = 3:m | |
682 C(i,:) = 2.*p.*C(i-1,:) - C(i-2,:); | |
683 endfor | |
684 endif | |
685 endfunction | |
686 | |
687 function A = chow (n, alpha = 1, delta = 0) | |
688 ## 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
|
689 ## 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
|
690 ## 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
|
691 ## 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
|
692 ## 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
|
693 ## Defaults: ALPHA = 1, DELTA = 0. |
16634 | 694 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
695 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
696 ## 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
|
697 ## 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
|
698 ## 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
|
699 ## Hessenberg matrices, SIAM Review, 13 (1971), pp. 220-221. |
16634 | 700 |
701 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
|
702 error ("gallery: 1 to 3 arguments are required for chow matrix"); |
16634 | 703 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
|
704 error ("gallery: N must be an integer for chow matrix"); |
16634 | 705 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
|
706 error ("gallery: ALPHA must be a scalar for chow matrix"); |
16634 | 707 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
|
708 error ("gallery: DELTA must be a scalar for chow matrix"); |
16634 | 709 endif |
710 | |
711 A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n); | |
712 endfunction | |
713 | |
714 function C = circul (v) | |
715 ## CIRCUL Circulant matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
716 ## 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
|
717 ## (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
|
718 ## 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
|
719 ## 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
|
720 ## 'wrap round'.) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
721 ## 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
|
722 ## 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
|
723 ## 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
|
724 ## is an eigenvalue of C, and W(N:-1:1) is an eigenvector of C. |
16634 | 725 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
726 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
727 ## P.J. Davis, Circulant Matrices, John Wiley, 1977. |
16634 | 728 |
729 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
|
730 error ("gallery: 1 argument is required for circul matrix"); |
16634 | 731 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
|
732 error ("gallery: V must be numeric for circul matrix"); |
16634 | 733 endif |
734 | |
16734
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
735 n = numel (v); |
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
736 if (isscalar (v) && fix (v) == v) |
16634 | 737 n = v; |
738 v = 1:n; | |
16734
67b67fc0969a
gallery: fix bug from typo in variable name
Carnë Draug <carandraug@octave.org>
parents:
16634
diff
changeset
|
739 elseif (n > 1 && isvector (v)) |
16634 | 740 ## do nothing |
741 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
742 error ("gallery: X must be a scalar or a vector for circul matrix"); |
16634 | 743 endif |
744 | |
745 v = v(:).'; # Make sure v is a row vector | |
746 C = toeplitz ([v(1) v(n:-1:2)], v); | |
747 endfunction | |
748 | |
749 function A = clement (n, k = 0) | |
750 ## 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
|
751 ## 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
|
752 ## 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
|
753 ## 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
|
754 ## 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
|
755 ## 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
|
756 ## K = 1 it is symmetric. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
757 ## CLEMENT(N, 1) is diagonally similar to CLEMENT(N). |
16634 | 758 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
759 ## 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
|
760 ## 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
|
761 ## known explicitly. |
16634 | 762 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
763 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
764 ## 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
|
765 ## 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
|
766 ## 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
|
767 ## 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
|
768 ## 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
|
769 ## 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
|
770 ## pp. 503-507. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
771 ## 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
|
772 ## Linear Algebra and Appl., 150 (1991), pp. 341-360. |
16634 | 773 |
774 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
|
775 error ("gallery: 1 or 2 arguments are required for clement matrix"); |
16634 | 776 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
|
777 error ("gallery: N must be an integer for clement matrix"); |
16634 | 778 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
|
779 error ("gallery: K must be a numeric scalar for clement matrix"); |
16634 | 780 endif |
781 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
782 n -= 1; |
16634 | 783 x = n:-1:1; |
784 z = 1:n; | |
785 | |
786 if (k == 0) | |
787 A = diag (x, -1) + diag (z, 1); | |
788 elseif (k == 1) | |
789 y = sqrt (x.*z); | |
790 A = diag (y, -1) + diag (y, 1); | |
791 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
792 error ("gallery: K must have a value of 0 or 1 for clement matrix"); |
16634 | 793 endif |
794 endfunction | |
795 | |
796 function C = compar (A, k = 0) | |
797 ## COMP Comparison matrices. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
798 ## 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
|
799 ## 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
|
800 ## 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
|
801 ## 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
|
802 ## 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
|
803 ## 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
|
804 ## COMP(A) is often denoted by M(A) in the literature. |
16634 | 805 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
806 ## Reference (e.g.): |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
807 ## 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
|
808 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. |
16634 | 809 |
810 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
|
811 error ("gallery: 1 or 2 arguments are required for compar matrix"); |
16634 | 812 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
|
813 error ("gallery: A must be a 2-D matrix for compar matrix"); |
16634 | 814 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
|
815 error ("gallery: K must be a numeric scalar for compar matrix"); |
16634 | 816 endif |
817 | |
818 [m, n] = size (A); | |
819 p = min (m, n); | |
820 | |
821 if (k == 0) | |
822 ## 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
|
823 ## the 'high level' definition above. |
16634 | 824 C = -abs (A); |
825 for j = 1:p | |
826 C(j,j) = abs (A(j,j)); | |
827 endfor | |
828 | |
829 elseif (k == 1) | |
830 C = A'; | |
831 for j = 1:p | |
832 C(k,k) = 0; | |
833 endfor | |
834 mx = max (abs (C)); | |
835 C = -mx'*ones (1, n); | |
836 for j = 1:p | |
837 C(j,j) = abs (A(j,j)); | |
838 endfor | |
839 if (all (A == tril (A))), C = tril (C); endif | |
840 if (all (A == triu (A))), C = triu (C); endif | |
841 | |
842 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
843 error ("gallery: K must have a value of 0 or 1 for compar matrix"); |
16634 | 844 endif |
845 | |
846 endfunction | |
847 | |
848 function A = condex (n, k = 4, theta = 100) | |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
849 ## 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
|
850 ## 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
|
851 ## 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
|
852 ## 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
|
853 ## 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
|
854 ## 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
|
855 ## 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
|
856 ## 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
|
857 ## 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
|
858 ## 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
|
859 ## 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
|
860 ## (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
|
861 ## counterexample because of the rounding errors in forming it.) |
16634 | 862 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
863 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
864 ## 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
|
865 ## 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
|
866 ## 4 (1983), pp. 602-611. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
867 ## 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
|
868 ## 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
|
869 ## (Algorithm 674), ACM Trans. Math. Soft., 14 (1988), pp. 381-396. |
16634 | 870 |
871 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
|
872 error ("gallery: 1 to 3 arguments are required for condex matrix"); |
16634 | 873 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
|
874 error ("gallery: N must be an integer for condex matrix"); |
16634 | 875 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
|
876 error ("gallery: K must be a numeric scalar for condex matrix"); |
16634 | 877 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
|
878 error ("gallery: THETA must be a numeric scalar for condex matrix"); |
16634 | 879 endif |
880 | |
881 if (k == 1) # Cline and Rew (1983), Example B. | |
882 A = [1 -1 -2*theta 0 | |
883 0 1 theta -theta | |
884 0 1 1+theta -(theta+1) | |
885 0 0 0 theta]; | |
886 | |
887 elseif (k == 2) # Cline and Rew (1983), Example C. | |
888 A = [1 1-2/theta^2 -2 | |
889 0 1/theta -1/theta | |
890 0 0 1]; | |
891 | |
892 elseif (k == 3) # Cline and Rew (1983), Example D. | |
893 A = gallery ("triw", n, -1)'; | |
894 A(n,n) = -1; | |
895 | |
896 elseif (k == 4) # Higham (1988), p. 390. | |
897 x = ones (n, 3); # First col is e | |
898 x(2:n,2) = zeros (n-1, 1); # Second col is e(1) | |
899 | |
900 ## Third col is special vector b in SONEST | |
901 x(:, 3) = (-1).^[0:n-1]' .* ( 1 + [0:n-1]'/(n-1) ); | |
902 | |
903 Q = orth (x); # Q*Q' is now the orthogonal projector onto span(e(1),e,b)). | |
904 P = eye (n) - Q*Q'; | |
905 A = eye (n) + theta*P; | |
906 | |
907 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
908 error ("gallery: unknown estimator K '%d' for condex matrix", k); |
16634 | 909 endif |
910 | |
911 ## Pad out with identity as necessary. | |
912 m = columns (A); | |
913 if (m < n) | |
914 for i = n:-1:m+1 | |
915 A(i,i) = 1; | |
916 endfor | |
917 endif | |
918 endfunction | |
919 | |
20298
ababbe103048
gallery: allow N to be a 2 element vectors for cycol matrices.
Carnë Draug <carandraug@octave.org>
parents:
20297
diff
changeset
|
920 function A = cycol (n, k = max (round (n(end)/4), 1)) |
16634 | 921 ## 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
|
922 ## 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
|
923 ## 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
|
924 ## 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
|
925 ## 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
|
926 ## CYCOL(N, K), where N is a scalar, is the same as CYCOL([N N], K). |
16634 | 927 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
928 ## 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
|
929 ## elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989). |
16634 | 930 |
931 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
|
932 error ("gallery: 1 or 2 arguments are required for cycol matrix"); |
16634 | 933 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
|
934 error ("gallery: N must be a 1 or 2 element integer for cycol matrix"); |
16634 | 935 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
|
936 error ("gallery: K must be a scalar for cycol matrix"); |
16634 | 937 endif |
938 | |
939 ## Parameter n specifies dimension: m-by-n | |
940 m = n(1); | |
941 n = n(end); | |
942 | |
943 A = randn (m, k); | |
944 for i = 2:ceil (n/k) | |
945 A = [A A(:,1:k)]; | |
946 endfor | |
947 A = A(:,1:n); | |
948 endfunction | |
949 | |
950 function [c, d, e] = dorr (n, theta = 0.01) | |
951 ## 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
|
952 ## [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
|
953 ## 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
|
954 ## 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
|
955 ## 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
|
956 ## 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
|
957 ## 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
|
958 ## 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
|
959 ## COMP(C)*ONES(N,1) = THETA*(N+1)^2 * [1 0 0 ... 0 1]'. |
16634 | 960 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
961 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
962 ## 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
|
963 ## 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
|
964 ## pp. 271-283. |
16634 | 965 |
966 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
|
967 error ("gallery: 1 or 2 arguments are required for dorr matrix"); |
16634 | 968 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
|
969 error ("gallery: N must be an integer for dorr matrix"); |
16634 | 970 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
|
971 error ("gallery: THETA must be a numeric scalar for dorr matrix"); |
16634 | 972 endif |
973 | |
974 c = zeros (n, 1); | |
975 e = c; | |
976 d = c; | |
977 ## All length n for convenience. Make c, e of length n-1 later. | |
978 | |
979 h = 1/(n+1); | |
980 m = floor ((n+1)/2); | |
981 term = theta/h^2; | |
982 | |
983 i = (1:m)'; | |
984 c(i) = -term * ones (m, 1); | |
985 e(i) = c(i) - (0.5-i*h)/h; | |
986 d(i) = -(c(i) + e(i)); | |
987 | |
988 i = (m+1:n)'; | |
989 e(i) = -term * ones (n-m, 1); | |
990 c(i) = e(i) + (0.5-i*h)/h; | |
991 d(i) = -(c(i) + e(i)); | |
992 | |
993 c = c(2:n); | |
994 e = e(1:n-1); | |
995 | |
996 if (nargout <= 1) | |
997 c = tridiag (c, d, e); | |
998 endif | |
999 endfunction | |
1000 | |
1001 function A = dramadah (n, k = 1) | |
1002 ## 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
|
1003 ## 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
|
1004 ## 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
|
1005 ## 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
|
1006 ## 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
|
1007 ## 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
|
1008 ## 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
|
1009 ## where c is a constant. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1010 ## 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
|
1011 ## The inverses of both types have integer entries. |
16634 | 1012 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1013 ## Another interesting (0,1) matrix: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1014 ## 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
|
1015 ## 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
|
1016 ## 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
|
1017 ## plane. |
16634 | 1018 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1019 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1020 ## 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
|
1021 ## 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
|
1022 ## 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
|
1023 ## (0,1) matrix, Linear Algebra and Appl., 183 (1993), pp. 147-153. |
16634 | 1024 |
1025 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
|
1026 error ("gallery: 1 to 2 arguments are required for dramadah matrix"); |
16634 | 1027 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
|
1028 error ("gallery: N must be an integer for dramadah matrix"); |
16634 | 1029 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
|
1030 error ("gallery: K must be a numeric scalar for dramadah matrix"); |
16634 | 1031 endif |
1032 | |
1033 switch (k) | |
1034 case (1) # Toeplitz | |
1035 c = ones (n, 1); | |
1036 for i = 2:4:n | |
1037 m = min (1, n-i); | |
1038 c(i:i+m) = zeros (m+1, 1); | |
1039 endfor | |
1040 r = zeros (n, 1); | |
1041 r(1:4) = [1 1 0 1]; | |
1042 if (n < 4) | |
1043 r = r(1:n); | |
1044 endif | |
1045 A = toeplitz (c, r); | |
1046 | |
1047 case (2) # Upper triangular and Toeplitz | |
1048 c = zeros (n, 1); | |
1049 c(1) = 1; | |
1050 r = ones (n, 1); | |
1051 for i= 3:2:n | |
1052 r(i) = 0; | |
1053 endfor | |
1054 A = toeplitz (c, r); | |
1055 | |
1056 case (3) # Lower Hessenberg | |
1057 c = ones (n, 1); | |
1058 for i= 2:2:n | |
1059 c(i) = 0; | |
1060 endfor | |
1061 A = toeplitz (c, [1 1 zeros(1,n-2)]); | |
1062 | |
1063 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1064 error ("gallery: unknown K '%d' for dramadah matrix", k); |
16634 | 1065 endswitch |
1066 endfunction | |
1067 | |
1068 function A = fiedler (c) | |
1069 ## FIEDLER Fiedler matrix - symmetric. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1070 ## 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
|
1071 ## 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
|
1072 ## 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
|
1073 ## (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
|
1074 ## Properties: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1075 ## 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
|
1076 ## eigenvalues are negative (Szego, 1936). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1077 ## 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
|
1078 ## 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
|
1079 ## 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
|
1080 ## [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
|
1081 ## C are in increasing or decreasing order---NJH.] |
16634 | 1082 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1083 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1084 ## 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
|
1085 ## 43 (1936), pp. 246-259. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1086 ## 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
|
1087 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 159. |
16634 | 1088 |
1089 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
|
1090 error ("gallery: 1 argument is required for fiedler matrix"); |
16634 | 1091 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
|
1092 error ("gallery: C must be numeric for fiedler matrix"); |
16634 | 1093 endif |
1094 | |
1095 n = numel (c); | |
1096 if (isscalar (c) && fix (c) == c) | |
1097 n = c; | |
1098 c = 1:n; | |
1099 elseif (n > 1 && isvector (c)) | |
1100 ## do nothing | |
1101 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1102 error ("gallery: C must be an integer or a vector for fiedler matrix"); |
16634 | 1103 endif |
1104 c = c(:).'; # Ensure c is a row vector. | |
1105 | |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
1106 A = abs (c - c.'); |
16634 | 1107 endfunction |
1108 | |
1109 function A = forsythe (n, alpha = sqrt (eps), lambda = 0) | |
1110 ## 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
|
1111 ## 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
|
1112 ## 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
|
1113 ## It has the characteristic polynomial |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1114 ## 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
|
1115 ## ALPHA defaults to SQRT(EPS) and LAMBDA to 0. |
16634 | 1116 |
1117 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
|
1118 error ("gallery: 1 to 3 arguments are required for forsythe matrix"); |
16634 | 1119 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
|
1120 error ("gallery: N must be an integer for forsythe matrix"); |
16634 | 1121 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
|
1122 error ("gallery: ALPHA must be a numeric scalar for forsythe matrix"); |
16634 | 1123 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
|
1124 error ("gallery: LAMBDA must be a numeric scalar for forsythe matrix"); |
16634 | 1125 endif |
1126 | |
1127 A = jordbloc (n, lambda); | |
1128 A(n,1) = alpha; | |
1129 endfunction | |
1130 | |
1131 function F = frank (n, k = 0) | |
1132 ## 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
|
1133 ## 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
|
1134 ## 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
|
1135 ## 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
|
1136 ## 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
|
1137 ## (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
|
1138 ## 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
|
1139 ## Hermite polynomials. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1140 ## 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
|
1141 ## the more so for bigger N. |
16634 | 1142 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1143 ## 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
|
1144 ## and Wilkinson (1960) for discussions. |
16634 | 1145 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1146 ## This version incorporates improvements suggested by W. Kahan. |
16634 | 1147 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1148 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1149 ## 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
|
1150 ## 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
|
1151 ## 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
|
1152 ## 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
|
1153 ## 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
|
1154 ## pp. 578-619 (Section 13). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1155 ## 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
|
1156 ## 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
|
1157 ## 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
|
1158 ## 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
|
1159 ## 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
|
1160 ## 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
|
1161 ## Press, 1965 (pp. 92-93). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1162 ## 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
|
1163 ## Rutishauser (see above). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1164 ## 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
|
1165 ## 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
|
1166 ## 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
|
1167 ## Comput., 7 (1986), pp. 835-839. |
16634 | 1168 |
1169 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
|
1170 error ("gallery: 1 to 2 arguments are required for frank matrix"); |
16634 | 1171 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
|
1172 error ("gallery: N must be an integer for frank matrix"); |
16634 | 1173 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
|
1174 error ("gallery: K must be a numeric scalar for frank matrix"); |
16634 | 1175 endif |
1176 | |
1177 p = n:-1:1; | |
1178 F = triu (p(ones (n, 1), :) - diag (ones (n-1, 1), -1), -1); | |
1179 | |
1180 switch (k) | |
1181 case (0), # do nothing | |
1182 case (1), F = F(p,p)'; | |
1183 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1184 error ("gallery: K must have a value of 0 or 1 for frank matrix"); |
16634 | 1185 endswitch |
1186 endfunction | |
1187 | |
1188 function c = gcdmat (n) | |
1189 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
|
1190 error ("gallery: 1 argument is required for gcdmat matrix"); |
16634 | 1191 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
|
1192 error ("gallery: N must be an integer for gcdmat matrix"); |
16634 | 1193 endif |
1194 c = gcd (repmat ((1:n)', [1 n]), repmat (1:n, [n 1])); | |
1195 endfunction | |
1196 | |
1197 function A = gearmat (n, i = n, j = -n) | |
1198 ## NOTE: this function was named gearm in the original Test Matrix Toolbox | |
1199 ## GEARMAT Gear matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1200 ## 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
|
1201 ## 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
|
1202 ## 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
|
1203 ## Defaults: I = N, j = -N. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1204 ## 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
|
1205 ## 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
|
1206 ## 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
|
1207 ## 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
|
1208 ## GEARMAT(N) is singular. |
16634 | 1209 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1210 ## (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
|
1211 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1212 ## 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
|
1213 ## Math. Comp., 23 (1969), pp. 119-125. |
16634 | 1214 |
1215 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
|
1216 error ("gallery: 1 to 3 arguments are required for gearmat matrix"); |
16634 | 1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 error ("gallery: J must be a nonzero scalar, and abs (J) <= N for gearmat matrix"); |
16634 | 1223 endif |
1224 | |
1225 A = diag (ones (n-1, 1), -1) + diag (ones (n-1, 1), 1); | |
1226 A(1, abs (i)) = sign (i); | |
1227 A(n, n+1 - abs (j)) = sign (j); | |
1228 endfunction | |
1229 | |
1230 function G = grcar (n, k = 3) | |
1231 ## 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
|
1232 ## 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
|
1233 ## 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
|
1234 ## 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
|
1235 ## interesting pattern in the complex plane (try PS(GRCAR(32))). |
16634 | 1236 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1237 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1238 ## 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
|
1239 ## 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
|
1240 ## New Mexico, 1989 (Appendix 2). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1241 ## 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
|
1242 ## 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
|
1243 ## Appl., 13 (1992), pp. 796-825. |
16634 | 1244 |
1245 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
|
1246 error ("gallery: 1 to 2 arguments are required for grcar 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 grcar matrix"); |
16634 | 1249 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
|
1250 error ("gallery: K must be a numeric scalar for grcar matrix"); |
16634 | 1251 endif |
1252 | |
1253 G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1); | |
1254 endfunction | |
1255 | |
1256 function A = hanowa (n, d = -1) | |
1257 ## 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
|
1258 ## 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
|
1259 ## [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
|
1260 ## 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
|
1261 ## 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
|
1262 ## Parameter d defaults to -1. |
16634 | 1263 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1264 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1265 ## 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
|
1266 ## 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
|
1267 ## Berlin, 1987. (pp. 86-87) |
16634 | 1268 |
1269 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
|
1270 error ("gallery: 1 to 2 arguments are required for hanowa matrix"); |
16634 | 1271 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
|
1272 error ("gallery: N must be an integer for hanowa matrix"); |
16634 | 1273 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
|
1274 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
|
1275 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
|
1276 error ("gallery: D must be a numeric scalar for hanowa matrix"); |
16634 | 1277 endif |
1278 | |
1279 m = n/2; | |
1280 A = [ d*eye(m) -diag(1:m) | |
1281 diag(1:m) d*eye(m) ]; | |
1282 endfunction | |
1283 | |
1284 function [v, beta] = house (x) | |
1285 ## HOUSE Householder matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1286 ## 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
|
1287 ## 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
|
1288 ## 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
|
1289 ## 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
|
1290 ## sign(x) := exp(i*arg(x)) ( = x./abs(x) when x ~= 0). |
16634 | 1291 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1292 ## 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
|
1293 ## 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
|
1294 ## 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
|
1295 ## 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
|
1296 ## 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
|
1297 ## 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
|
1298 ## 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
|
1299 ## = 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
|
1300 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1301 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1302 ## 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
|
1303 ## 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
|
1304 ## 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
|
1305 ## New York, 1973, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1306 ## 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
|
1307 ## Press, 1965. |
16634 | 1308 |
1309 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
|
1310 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
|
1311 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
|
1312 error ("gallery: X must be a vector for house matrix"); |
16634 | 1313 endif |
1314 | |
1315 ## must be a column vector | |
1316 x = x(:); | |
1317 | |
1318 s = norm (x) * (sign (x(1)) + (x(1) == 0)); # Modification for sign (0) == 1. | |
1319 v = x; | |
1320 if (s == 0) | |
1321 ## Quit if x is the zero vector. | |
1322 beta = 1; | |
1323 else | |
1324 v(1) = v(1) + s; | |
1325 beta = 1/(s'*v(1)); # NB the conjugated s. | |
1326 ## beta = 1/(abs (s) * (abs (s) +abs(x(1)) would guarantee beta real. | |
1327 ## But beta as above can be non-real (due to rounding) only when x is complex. | |
1328 endif | |
1329 endfunction | |
1330 | |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1331 function A = integerdata (varargin) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1332 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1333 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
|
1334 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
|
1335 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1336 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1337 if (isnumeric (varargin{end})) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1338 jidx = varargin{end}; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1339 svec = [varargin{:}]; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1340 varargin(end) = []; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1341 elseif (ischar (varargin{end})) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1342 if (nargin < 4) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1343 error (["gallery: CLASS argument requires 4 inputs " ... |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1344 "for integerdata matrix."]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1345 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1346 jidx = varargin{end-1}; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1347 svec = [varargin{1:end-1}]; |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1348 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1349 else |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1350 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
|
1351 "for integerdata matrix"]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1352 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1353 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1354 if (! (isnumeric (jidx) && isscalar (jidx) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1355 && jidx == fix (jidx) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1356 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1357 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
|
1358 "for integerdata matrix"]); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1359 endif |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1360 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1361 ## 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
|
1362 ## 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
|
1363 randstate = rand ("state"); |
16980
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1364 unwind_protect |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1365 rand ("state", svec); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1366 A = randi (varargin{:}); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1367 unwind_protect_cleanup |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1368 rand ("state", randstate); |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1369 end_unwind_protect |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1370 |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1371 endfunction |
1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
Rik <rik@octave.org>
parents:
16979
diff
changeset
|
1372 |
16634 | 1373 function A = invhess (x, y) |
1374 ## 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
|
1375 ## 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
|
1376 ## 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
|
1377 ## 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
|
1378 ## 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
|
1379 ## 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
|
1380 ## 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
|
1381 ## 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
|
1382 ## 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
|
1383 ## INVHESS(1:X). |
16634 | 1384 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1385 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1386 ## 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
|
1387 ## 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
|
1388 ## 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
|
1389 ## 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
|
1390 ## 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
|
1391 ## 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
|
1392 ## 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
|
1393 ## 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
|
1394 ## Operator Theory, 10 (1987), pp. 82-95. |
16634 | 1395 |
1396 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
|
1397 error ("gallery: 1 to 2 arguments are required for invhess matrix"); |
16634 | 1398 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
|
1399 error ("gallery: X must be numeric for invhess matrix"); |
16634 | 1400 endif |
1401 | |
1402 if (isscalar (x) && fix (x) == x) | |
1403 n = x; | |
1404 x = 1:n; | |
1405 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
|
1406 n = numel (x); |
16634 | 1407 else |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1408 error ("gallery: X must be an integer scalar, or a vector for invhess matrix"); |
16634 | 1409 endif |
1410 | |
1411 if (nargin < 2) | |
1412 y = -x(1:end-1); | |
1413 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
|
1414 error ("gallery: Y must be a vector of length -1 than X for invhess matrix"); |
16634 | 1415 endif |
1416 | |
1417 x = x(:); | |
1418 y = y(:); | |
1419 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1420 ## FIXME: On next line, z = x'; A = z(ones(n,1),:) would be more efficient. |
16634 | 1421 A = ones (n, 1) * x'; |
1422 for j = 2:n | |
1423 A(1:j-1,j) = y(1:j-1); | |
1424 endfor | |
1425 endfunction | |
1426 | |
1427 function A = invol (n) | |
1428 ## INVOL An involutory matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1429 ## 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
|
1430 ## ill-conditioned matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1431 ## 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
|
1432 ## NB: B = (EYE(N)-A)/2 and B = (EYE(N)+A)/2 are idempotent (B*B = B). |
16634 | 1433 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1434 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1435 ## 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
|
1436 ## 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
|
1437 ## pp. 234-237. |
16634 | 1438 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1439 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
|
1440 error ("gallery: 1 argument is required for invol matrix"); |
16634 | 1441 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
|
1442 error ("gallery: N must be an integer for invol matrix"); |
16634 | 1443 endif |
1444 | |
1445 A = hilb (n); | |
1446 | |
1447 d = -n; | |
1448 A(:, 1) = d * A(:, 1); | |
1449 | |
1450 for i = 1:n-1 | |
1451 d = -(n+i)*(n-i)*d/(i*i); | |
1452 A(i+1,:) = d * A(i+1,:); | |
1453 endfor | |
1454 endfunction | |
1455 | |
1456 function [A, detA] = ipjfact (n, k = 0) | |
1457 ## 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
|
1458 ## 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
|
1459 ## 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
|
1460 ## 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
|
1461 ## Both are Hankel matrices. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1462 ## 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
|
1463 ## 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
|
1464 ## [A, d] = IPJFACT(N, K); |
16634 | 1465 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1466 ## 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
|
1467 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1468 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1469 ## 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
|
1470 ## Dept. of Mathematics, University of Bradford, 1993. |
16634 | 1471 |
1472 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
|
1473 error ("gallery: 1 to 2 arguments are required for ipjfact matrix"); |
16634 | 1474 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
|
1475 error ("gallery: N must be an integer for ipjfact matrix"); |
16634 | 1476 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
|
1477 error ("gallery: K must be a numeric scalar for ipjfact matrix"); |
16634 | 1478 endif |
1479 | |
1480 c = cumprod (2:n+1); | |
1481 d = cumprod (n+1:2*n) * c(n-1); | |
1482 | |
1483 A = hankel (c, d); | |
1484 | |
1485 switch (k) | |
1486 case (0), # do nothing | |
1487 case (1), A = ones (n) ./ A; | |
1488 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1489 error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); |
16634 | 1490 endswitch |
1491 | |
1492 if (nargout == 2) | |
1493 d = 1; | |
1494 | |
1495 if (k == 0) | |
1496 for i = 1:n-1 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1497 d *= prod (1:i+1) * prod (1:n-i); |
16634 | 1498 endfor |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1499 d *= prod (1:n+1); |
16634 | 1500 |
1501 elseif (k == 1) | |
1502 for i = 0:n-1 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
1503 d *= prod (1:i) / prod (1:n+1+i); |
16634 | 1504 endfor |
1505 if (rem (n*(n-1)/2, 2)) | |
1506 d = -d; | |
1507 endif | |
1508 | |
1509 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1510 error ("gallery: K must have a value of 0 or 1 for ipjfact matrix"); |
16634 | 1511 endif |
1512 | |
1513 detA = d; | |
1514 endif | |
1515 endfunction | |
1516 | |
1517 function J = jordbloc (n, lambda = 1) | |
1518 ## JORDBLOC Jordan block. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1519 ## 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
|
1520 ## LAMBDA. LAMBDA = 1 is the default. |
16634 | 1521 |
1522 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
|
1523 error ("gallery: 1 to 2 arguments are required for jordbloc matrix"); |
16634 | 1524 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
|
1525 error ("gallery: N must be an integer for jordbloc matrix"); |
16634 | 1526 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
|
1527 error ("gallery: LAMBDA must be a numeric scalar for jordbloc matrix"); |
16634 | 1528 endif |
1529 | |
1530 J = lambda * eye (n) + diag (ones (n-1, 1), 1); | |
1531 endfunction | |
1532 | |
1533 function U = kahan (n, theta = 1.2, pert = 25) | |
1534 ## 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
|
1535 ## 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
|
1536 ## 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
|
1537 ## condition and rank. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1538 ## 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
|
1539 ## 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
|
1540 ## 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
|
1541 ## The useful range of THETA is 0 < THETA < PI. |
16634 | 1542 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1543 ## 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
|
1544 ## 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
|
1545 ## 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
|
1546 ## 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
|
1547 ## 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
|
1548 ## KAHAN(N, THETA, PERT) uses the given value of PERT. |
16634 | 1549 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1550 ## 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
|
1551 ## 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
|
1552 ## The diagonal perturbation was suggested by Christian Bischof. |
16634 | 1553 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1554 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1555 ## 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
|
1556 ## 9 (1966), pp. 757-801. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1557 ## 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
|
1558 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. |
16634 | 1559 |
1560 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
|
1561 error ("gallery: 1 to 3 arguments are required for kahan matrix"); |
16634 | 1562 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
|
1563 error ("gallery: N must be a 1 or 2 element integer for kahan matrix"); |
16634 | 1564 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
|
1565 error ("gallery: THETA must be a numeric scalar for kahan matrix"); |
16634 | 1566 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
|
1567 error ("gallery: PERT must be a numeric scalar for kahan matrix"); |
16634 | 1568 endif |
1569 | |
1570 ## Parameter n specifies dimension: r-by-n | |
1571 r = n(1); | |
1572 n = n(end); | |
1573 | |
1574 s = sin (theta); | |
1575 c = cos (theta); | |
1576 | |
1577 U = eye (n) - c * triu (ones (n), 1); | |
1578 U = diag (s.^[0:n-1]) * U + pert*eps* diag ([n:-1:1]); | |
1579 if (r > n) | |
1580 U(r,n) = 0; # Extend to an r-by-n matrix | |
1581 else | |
1582 U = U(1:r,:); # Reduce to an r-by-n matrix | |
1583 endif | |
1584 endfunction | |
1585 | |
1586 function A = kms (n, rho = 0.5) | |
1587 ## 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
|
1588 ## 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
|
1589 ## 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
|
1590 ## 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
|
1591 ## below the diagonal are conjugated. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1592 ## RHO defaults to 0.5. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1593 ## Properties: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1594 ## 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
|
1595 ## 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
|
1596 ## 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
|
1597 ## 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
|
1598 ## INV(A) is tridiagonal. |
16634 | 1599 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1600 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1601 ## 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
|
1602 ## 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
|
1603 ## 10 (1989), pp. 135-146 (and see the references therein). |
16634 | 1604 |
1605 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
|
1606 error ("gallery: 1 to 2 arguments are required for lauchli matrix"); |
16634 | 1607 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
|
1608 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
|
1609 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
|
1610 error ("gallery: RHO must be a scalar for lauchli matrix"); |
16634 | 1611 endif |
1612 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1613 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
|
1614 A = abs (A - A'); |
16634 | 1615 A = rho .^ A; |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1616 if (imag (rho)) |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
1617 A = conj (tril (A,-1)) + triu (A); |
16634 | 1618 endif |
1619 endfunction | |
1620 | |
1621 function B = krylov (A, x, j) | |
1622 ## KRYLOV Krylov matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1623 ## 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
|
1624 ## [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
|
1625 ## 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
|
1626 ## 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
|
1627 ## KRYLOV(n) is the same as KRYLOV(RANDN(n)). |
16634 | 1628 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1629 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1630 ## 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
|
1631 ## Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369. |
16634 | 1632 |
1633 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
|
1634 error ("gallery: 1 to 3 arguments are required for krylov matrix"); |
16634 | 1635 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
|
1636 error ("gallery: A must be a square 2-D matrix for krylov matrix"); |
16634 | 1637 endif |
1638 | |
1639 n = length (A); | |
1640 if (isscalar (A)) | |
1641 n = A; | |
1642 A = randn (n); | |
1643 endif | |
1644 | |
1645 if (nargin < 2) | |
1646 x = ones (n, 1); | |
1647 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
|
1648 error ("gallery: X must be a vector of length equal to A for krylov matrix"); |
16634 | 1649 endif |
1650 | |
1651 if (nargin < 3) | |
1652 j = n; | |
1653 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
|
1654 error ("gallery: J must be an integer for krylov matrix"); |
16634 | 1655 endif |
1656 | |
1657 B = ones (n, j); | |
1658 B(:,1) = x(:); | |
1659 for i = 2:j | |
1660 B(:,i) = A*B(:,i-1); | |
1661 endfor | |
1662 endfunction | |
1663 | |
1664 function A = lauchli (n, mu = sqrt (eps)) | |
1665 ## LAUCHLI Lauchli matrix - rectangular. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1666 ## 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
|
1667 ## 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
|
1668 ## 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
|
1669 ## MU defaults to SQRT(EPS). |
16634 | 1670 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1671 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1672 ## 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
|
1673 ## kleinsten Quadraten, Numer. Math, 3 (1961), pp. 226-240. |
16634 | 1674 |
1675 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
|
1676 error ("gallery: 1 to 2 arguments are required for lauchli matrix"); |
16634 | 1677 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
|
1678 error ("gallery: N must be an integer for lauchli matrix"); |
16634 | 1679 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
|
1680 error ("gallery: MU must be a scalar for lauchli matrix"); |
16634 | 1681 endif |
1682 | |
1683 A = [ones(1, n) | |
1684 mu*eye(n) ]; | |
1685 endfunction | |
1686 | |
1687 function A = lehmer (n) | |
1688 ## 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
|
1689 ## 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
|
1690 ## 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
|
1691 ## 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
|
1692 ## 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
|
1693 ## N <= COND(A) <= 4*N*N. |
16634 | 1694 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1695 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1696 ## 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
|
1697 ## 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
|
1698 ## 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
|
1699 ## 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
|
1700 ## 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
|
1701 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 154. |
16634 | 1702 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1703 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
|
1704 error ("gallery: 1 argument is required for lehmer matrix"); |
16634 | 1705 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
|
1706 error ("gallery: N must be an integer for lehmer matrix"); |
16634 | 1707 endif |
1708 | |
1709 A = ones (n, 1) * (1:n); | |
1710 A = A./A'; | |
1711 A = tril (A) + tril (A, -1)'; | |
1712 endfunction | |
1713 | |
1714 function T = lesp (n) | |
1715 ## 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
|
1716 ## 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
|
1717 ## 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
|
1718 ## 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
|
1719 ## the eigenvalues grow more negative. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1720 ## 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
|
1721 ## 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
|
1722 ## via a similarity transformation with D = diag(1!,2!,...,N!). |
16634 | 1723 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1724 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1725 ## 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
|
1726 ## 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
|
1727 ## 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
|
1728 ## 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
|
1729 ## 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
|
1730 ## 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
|
1731 ## 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
|
1732 ## UK, 1992, pp. 234-266. |
16634 | 1733 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1734 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
|
1735 error ("gallery: 1 argument is required for lesp matrix"); |
16634 | 1736 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
|
1737 error ("gallery: N must be an integer for lesp matrix"); |
16634 | 1738 endif |
1739 | |
1740 x = 2:n; | |
1741 T = full (tridiag (ones (size (x)) ./x, -(2*[x n+1]+1), x)); | |
1742 endfunction | |
1743 | |
1744 function A = lotkin (n) | |
1745 ## LOTKIN Lotkin matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1746 ## 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
|
1747 ## 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
|
1748 ## eigenvalues of small magnitude. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1749 ## The inverse has integer entries and is known explicitly. |
16634 | 1750 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1751 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1752 ## M. Lotkin, A set of test matrices, MTAC, 9 (1955), pp. 153-161. |
16634 | 1753 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1754 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
|
1755 error ("gallery: 1 argument is required for lotkin matrix"); |
16634 | 1756 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
|
1757 error ("gallery: N must be an integer for lotkin matrix"); |
16634 | 1758 endif |
1759 | |
1760 A = hilb (n); | |
1761 A(1,:) = ones (1, n); | |
1762 endfunction | |
1763 | |
1764 function A = minij (n) | |
1765 ## 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
|
1766 ## 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
|
1767 ## 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
|
1768 ## Properties, variations: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1769 ## 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
|
1770 ## 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
|
1771 ## 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
|
1772 ## 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
|
1773 ## (N+1)*ONES(N)-A also has a tridiagonal inverse. |
16634 | 1774 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1775 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1776 ## 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
|
1777 ## 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
|
1778 ## 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
|
1779 ## 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
|
1780 ## (For the eigenvalues of Givens' matrix.) |
16634 | 1781 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1782 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
|
1783 error ("gallery: 1 argument is required for minij matrix"); |
16634 | 1784 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
|
1785 error ("gallery: N must be an integer for minij matrix"); |
16634 | 1786 endif |
1787 | |
19944
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
1788 A = bsxfun (@min, 1:n, (1:n)'); |
16634 | 1789 endfunction |
1790 | |
1791 function A = moler (n, alpha = -1) | |
1792 ## 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
|
1793 ## 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
|
1794 ## 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
|
1795 ## 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
|
1796 ## A has one small eigenvalue. |
16634 | 1797 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1798 ## Nash (1990) attributes the ALPHA = -1 matrix to Moler. |
16634 | 1799 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1800 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1801 ## 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
|
1802 ## 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
|
1803 ## Bristol, 1990 (Appendix 1). |
16634 | 1804 |
1805 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
|
1806 error ("gallery: 1 to 2 arguments are required for moler matrix"); |
16634 | 1807 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
|
1808 error ("gallery: N must be an integer for moler matrix"); |
16634 | 1809 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
|
1810 error ("gallery: ALPHA must be a scalar for moler matrix"); |
16634 | 1811 endif |
1812 | |
1813 A = triw (n, alpha)' * triw (n, alpha); | |
1814 endfunction | |
1815 | |
1816 function [A, T] = neumann (n) | |
1817 ## 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
|
1818 ## 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
|
1819 ## 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
|
1820 ## operator on a regular mesh. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1821 ## 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
|
1822 ## 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
|
1823 ## in which case the dimension of the matrix is N(1)*N(2). |
16634 | 1824 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1825 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1826 ## 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
|
1827 ## problem, Numer. Math., 25 (1976), pp. 153-161. |
16634 | 1828 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1829 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
|
1830 error ("gallery: 1 argument is required for neumann matrix"); |
16634 | 1831 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
|
1832 error ("gallery: N must be a 1 or 2 element integer for neumann matrix"); |
16634 | 1833 endif |
1834 | |
1835 if (isscalar (n)) | |
1836 m = sqrt (n); | |
1837 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
|
1838 error ("gallery: N must be a perfect square for neumann matrix"); |
16634 | 1839 endif |
1840 n(1) = m; | |
1841 n(2) = m; | |
1842 endif | |
1843 | |
1844 T = tridiag (n(1), -1, 2, -1); | |
1845 T(1,2) = -2; | |
1846 T(n(1),n(1)-1) = -2; | |
1847 | |
1848 A = kron (T, eye (n(2))) + kron (eye (n(2)), T); | |
1849 endfunction | |
1850 | |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1851 function A = normaldata (varargin) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1852 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1853 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
|
1854 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
|
1855 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1856 if (isnumeric (varargin{end})) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1857 jidx = varargin{end}; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1858 svec = [varargin{:}]; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1859 varargin(end) = []; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1860 elseif (ischar (varargin{end})) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1861 if (nargin < 3) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1862 error (["gallery: CLASS argument requires 3 inputs " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1863 "for normaldata matrix."]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1864 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1865 jidx = varargin{end-1}; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1866 svec = [varargin{1:end-1}]; |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1867 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
1868 else |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1869 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
|
1870 "for normaldata matrix"]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1871 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1872 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1873 if (! (isnumeric (jidx) && isscalar (jidx) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1874 && jidx == fix (jidx) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1875 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1876 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
|
1877 "for normaldata matrix"]); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1878 endif |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1879 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1880 ## 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
|
1881 ## 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
|
1882 randstate = randn ("state"); |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1883 unwind_protect |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1884 randn ("state", svec); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1885 A = randn (varargin{:}); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1886 unwind_protect_cleanup |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1887 randn ("state", randstate); |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1888 end_unwind_protect |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1889 |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1890 endfunction |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
1891 |
16634 | 1892 function Q = orthog (n, k = 1) |
1893 ## 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
|
1894 ## 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
|
1895 ## 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
|
1896 ## orthogonal matrices. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1897 ## 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
|
1898 ## 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
|
1899 ## 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
|
1900 ## 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
|
1901 ## Symmetric. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1902 ## 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
|
1903 ## 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
|
1904 ## 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
|
1905 ## 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
|
1906 ## 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
|
1907 ## 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
|
1908 ## 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
|
1909 ## 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
|
1910 ## 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
|
1911 ## 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
|
1912 ## Chebyshev Vandermonde-like matrix, based on zeros of T(n). |
16634 | 1913 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1914 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1915 ## 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
|
1916 ## 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
|
1917 ## 10 (1989), pp. 155-164. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1918 ## 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
|
1919 ## 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
|
1920 ## 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
|
1921 ## pp. 4-12. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1922 ## 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
|
1923 ## 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
|
1924 ## pp. 500-507. |
16634 | 1925 |
1926 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
|
1927 error ("gallery: 1 to 2 arguments are required for orthog matrix"); |
16634 | 1928 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
|
1929 error ("gallery: N must be an integer for orthog matrix"); |
16634 | 1930 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
|
1931 error ("gallery: K must be a numeric scalar for orthog matrix"); |
16634 | 1932 endif |
1933 | |
1934 switch (k) | |
1935 case (1) | |
1936 ## E'vectors second difference matrix | |
1937 m = (1:n)'*(1:n) * (pi/(n+1)); | |
1938 Q = sin (m) * sqrt (2/(n+1)); | |
1939 | |
1940 case (2) | |
1941 m = (1:n)'*(1:n) * (2*pi/(2*n+1)); | |
1942 Q = sin (m) * (2/ sqrt (2*n+1)); | |
1943 | |
1944 case (3) | |
1945 ## Vandermonde based on roots of unity | |
1946 m = 0:n-1; | |
1947 Q = exp (m'*m*2*pi* sqrt (-1) / n) / sqrt (n); | |
1948 | |
1949 case (4) | |
1950 ## Helmert matrix | |
1951 Q = tril (ones (n)); | |
1952 Q(1,2:n) = ones (1, n-1); | |
1953 for i = 2:n | |
1954 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
|
1955 endfor |
16634 | 1956 Q = diag (sqrt ([n 1:n-1] .* [1:n])) \ Q; |
1957 | |
1958 case (5) | |
1959 ## Hartley matrix | |
1960 m = (0:n-1)'*(0:n-1) * (2*pi/n); | |
1961 Q = (cos (m) + sin (m)) / sqrt (n); | |
1962 | |
1963 case (-1) | |
1964 ## extrema of T(n-1) | |
1965 m = (0:n-1)'*(0:n-1) * (pi/(n-1)); | |
1966 Q = cos (m); | |
1967 | |
1968 case (-2) | |
1969 ## zeros of T(n) | |
1970 m = (0:n-1)'*(.5:n-.5) * (pi/n); | |
1971 Q = cos (m); | |
1972 | |
1973 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
1974 error ("gallery: unknown K '%d' for orthog matrix", k); |
16634 | 1975 endswitch |
1976 endfunction | |
1977 | |
1978 function A = parter (n) | |
1979 ## 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
|
1980 ## 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
|
1981 ## It is a Cauchy matrix and a Toeplitz matrix. |
16634 | 1982 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1983 ## 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
|
1984 ## 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
|
1985 ## 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
|
1986 ## 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
|
1987 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1988 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1989 ## 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
|
1990 ## 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
|
1991 ## 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
|
1992 ## 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
|
1993 ## Linear Algebra and Appl., 149 (1991), pp. 1-18. |
16634 | 1994 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
1995 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
|
1996 error ("gallery: 1 argument is required for parter matrix"); |
16634 | 1997 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
|
1998 error ("gallery: N must be an integer for parter matrix"); |
16634 | 1999 endif |
2000 | |
2001 A = cauchy ((1:n) + 0.5, -(1:n)); | |
2002 endfunction | |
2003 | |
2004 function P = pei (n, alpha = 1) | |
2005 ## PEI Pei matrix. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2006 ## 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
|
2007 ## ALPHA*EYE(N) + ONES(N). |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2008 ## 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
|
2009 ## The matrix is singular for ALPHA = 0, -N. |
16634 | 2010 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2011 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2012 ## 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
|
2013 ## Comm. ACM, 5 (1962), p. 508. |
16634 | 2014 |
2015 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
|
2016 error ("gallery: 1 to 2 arguments are required for pei matrix"); |
16634 | 2017 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
|
2018 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
|
2019 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
|
2020 error ("gallery: ALPHA must be a scalar for pei matrix"); |
16634 | 2021 endif |
2022 | |
2023 P = alpha * eye (n) + ones (n); | |
2024 endfunction | |
2025 | |
2026 function A = poisson (n) | |
2027 ## 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
|
2028 ## 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
|
2029 ## 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
|
2030 ## 5-point operator on an N-by-N mesh. |
16634 | 2031 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2032 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2033 ## 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
|
2034 ## 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
|
2035 ## (Section 4.5.4). |
16634 | 2036 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2037 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
|
2038 error ("gallery: 1 argument is required for poisson matrix"); |
16634 | 2039 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
|
2040 error ("gallery: N must be an integer for poisson matrix"); |
16634 | 2041 endif |
2042 | |
2043 S = tridiag (n, -1, 2, -1); | |
2044 I = speye (n); | |
2045 A = kron (I, S) + kron (S, I); | |
2046 endfunction | |
2047 | |
2048 function A = prolate (n, w = 0.25) | |
2049 ## 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
|
2050 ## 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
|
2051 ## 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
|
2052 ## 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
|
2053 ## - A is positive definite |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2054 ## - 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
|
2055 ## 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
|
2056 ## W defaults to 0.25. |
16634 | 2057 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2058 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2059 ## 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
|
2060 ## 187:269--278, 1993. |
16634 | 2061 |
2062 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
|
2063 error ("gallery: 1 to 2 arguments are required for prolate matrix"); |
16634 | 2064 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
|
2065 error ("gallery: N must be an integer for prolate matrix"); |
16634 | 2066 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
|
2067 error ("gallery: W must be a scalar for prolate matrix"); |
16634 | 2068 endif |
2069 | |
2070 a = zeros (n, 1); | |
2071 a(1) = 2*w; | |
2072 a(2:n) = sin (2*pi*w*(1:n-1)) ./ (pi*(1:n-1)); | |
2073 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
2074 A = toeplitz (a); |
16634 | 2075 endfunction |
2076 | |
2077 function H = randhess (x) | |
2078 ## NOTE: this function was named ohess in the original Test Matrix Toolbox | |
2079 ## 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
|
2080 ## 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
|
2081 ## upper Hessenberg matrix. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2082 ## 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
|
2083 ## 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
|
2084 ## of X as parameters. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2085 ## In both cases H is constructed via a product of N-1 Givens rotations. |
16634 | 2086 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2087 ## 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
|
2088 ## 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
|
2089 ## 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
|
2090 ## 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
|
2091 ## 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
|
2092 ## matrices. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2093 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2094 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2095 ## 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
|
2096 ## J. Comp. Appl. Math., 16 (1986), pp. 1-8. |
16634 | 2097 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2098 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
|
2099 error ("gallery: 1 argument is required for randhess matrix"); |
16634 | 2100 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
|
2101 error ("gallery: N or X must be numeric real values for randhess matrix"); |
16634 | 2102 endif |
2103 | |
2104 if (isscalar (x)) | |
2105 n = x; | |
2106 x = rand (n-1, 1) * 2*pi; | |
2107 H = eye (n); | |
2108 H(n,n) = sign (randn); | |
2109 elseif (isvector (x)) | |
2110 n = numel (x); | |
2111 H = eye (n); | |
2112 H(n,n) = sign (x(n)) + (x(n) == 0); # Second term ensures H(n,n) nonzero. | |
2113 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2114 error ("gallery: N or X must be a scalar or a vector for randhess matrix"); |
16634 | 2115 endif |
2116 | |
2117 for i = n:-1:2 | |
2118 ## Apply Givens rotation through angle x(i-1). | |
2119 theta = x(i-1); | |
2120 c = cos (theta); | |
2121 s = sin (theta); | |
2122 H([i-1 i], :) = [ c*H(i-1,:)+s*H(i,:) | |
2123 -s*H(i-1,:)+c*H(i,:) ]; | |
2124 endfor | |
2125 endfunction | |
2126 | |
2127 function A = rando (n, k = 1) | |
2128 ## 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
|
2129 ## 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
|
2130 ## 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
|
2131 ## 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
|
2132 ## 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
|
2133 ## 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
|
2134 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). |
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 rando matrix"); |
16634 | 2138 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
|
2139 error ("gallery: N must be an integer for rando matrix"); |
16634 | 2140 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
|
2141 error ("gallery: K must be a numeric scalar for smoke matrix"); |
16634 | 2142 endif |
2143 | |
2144 ## Parameter n specifies dimension: m-by-n. | |
2145 m = n(1); | |
2146 n = n(end); | |
2147 | |
2148 switch (k) | |
2149 case (1), A = floor ( rand(m, n) + 0.5); # {0, 1} | |
2150 case (2), A = 2*floor ( rand(m, n) + 0.5) -1; # {-1, 1} | |
2151 case (3), A = round (3*rand(m, n) - 1.5); # {-1, 0, 1} | |
2152 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2153 error ("gallery: unknown K '%d' for smoke matrix", k); |
16634 | 2154 endswitch |
2155 | |
2156 endfunction | |
2157 | |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2158 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
|
2159 ku = kl) |
16634 | 2160 ## 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
|
2161 ## 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
|
2162 ## 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
|
2163 ## 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
|
2164 ## Available types: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2165 ## 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
|
2166 ## 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
|
2167 ## 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
|
2168 ## 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
|
2169 ## 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
|
2170 ## 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
|
2171 ## 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
|
2172 ## 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
|
2173 ## 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
|
2174 ## 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
|
2175 ## 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
|
2176 ## 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
|
2177 ## 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
|
2178 ## 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
|
2179 ## eigenvalues distributed according to MODE. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2180 ## KL and KU, if present, are ignored. |
16634 | 2181 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2182 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2183 ## 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
|
2184 ## 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
|
2185 ## USA, 1996; sec. 26.3. |
16634 | 2186 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2187 ## 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
|
2188 ## in the following reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2189 ## 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
|
2190 ## 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
|
2191 ## New York, 1989. |
16634 | 2192 |
2193 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
|
2194 error ("gallery: 1 to 5 arguments are required for randsvd matrix"); |
16634 | 2195 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
|
2196 error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix"); |
16634 | 2197 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
|
2198 error ("gallery: KAPPA must be a numeric scalar for randsvd matrix"); |
16634 | 2199 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
|
2200 error ("gallery: KAPPA must larger than or equal to 1 for randsvd matrix"); |
16634 | 2201 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
|
2202 error ("gallery: MODE must be a numeric scalar for randsvd matrix"); |
16634 | 2203 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
|
2204 error ("gallery: KL must be a numeric scalar for randsvd matrix"); |
16634 | 2205 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
|
2206 error ("gallery: KU must be a numeric scalar for randsvd matrix"); |
16634 | 2207 endif |
2208 | |
2209 posdef = 0; | |
2210 if (kappa < 0) | |
2211 posdef = 1; | |
2212 kappa = -kappa; | |
2213 endif | |
2214 | |
2215 ## Parameter n specifies dimension: m-by-n. | |
2216 m = n(1); | |
2217 n = n(end); | |
2218 p = min ([m n]); | |
2219 | |
2220 ## If A will be a vector | |
2221 if (p == 1) | |
2222 A = randn (m, n); | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2223 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
|
2224 return; |
09543e9c8f40
Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
2225 endif |
16634 | 2226 |
2227 ## Set up vector sigma of singular values. | |
2228 switch (abs (mode)) | |
2229 case (1) | |
2230 sigma = ones (p, 1) ./ kappa; | |
2231 sigma(1) = 1; | |
2232 case (2) | |
2233 sigma = ones (p, 1); | |
2234 sigma(p) = 1 / kappa; | |
2235 case (3) | |
2236 factor = kappa^(-1/(p-1)); | |
2237 sigma = factor.^[0:p-1]; | |
2238 case (4) | |
2239 sigma = ones (p, 1) - (0:p-1)'/(p-1)*(1-1/kappa); | |
2240 case (5) | |
2241 ## In this case cond (A) <= kappa. | |
2242 rand ("uniform"); | |
2243 sigma = exp (-rand (p, 1) * log (kappa)); | |
2244 otherwise | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2245 error ("gallery: unknown MODE '%d' for randsvd matrix", mode); |
16634 | 2246 endswitch |
2247 | |
2248 ## Convert to diagonal matrix of singular values. | |
2249 if (mode < 0) | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2250 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
|
2251 endif |
16634 | 2252 sigma = diag (sigma); |
2253 | |
2254 if (posdef) | |
2255 ## handle case where KAPPA was negative | |
2256 Q = qmult (p); | |
2257 A = Q' * sigma * Q; | |
2258 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
|
2259 return; |
16634 | 2260 endif |
2261 | |
2262 if (m != n) | |
2263 ## Expand to m-by-n diagonal matrix | |
2264 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
|
2265 endif |
16634 | 2266 |
2267 if (kl == 0 && ku == 0) | |
2268 ## Diagonal matrix requested - nothing more to do. | |
2269 A = sigma; | |
2270 else | |
2271 ## A = U*sigma*V, where U, V are random orthogonal matrices from the | |
2272 ## Haar distribution. | |
2273 A = qmult (sigma'); | |
2274 A = qmult (A'); | |
2275 | |
2276 if (kl < n-1 || ku < n-1) | |
2277 ## Bandwidth reduction | |
2278 A = bandred (A, kl, ku); | |
2279 endif | |
2280 endif | |
2281 endfunction | |
2282 | |
2283 function A = redheff (n) | |
2284 ## 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
|
2285 ## 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
|
2286 ## 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
|
2287 ## A(i,j) = 0 otherwise. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2288 ## 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
|
2289 ## 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
|
2290 ## 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
|
2291 ## 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
|
2292 ## 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
|
2293 ## ``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
|
2294 ## ABS(Z) = 1'', |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2295 ## 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
|
2296 ## 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
|
2297 ## 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
|
2298 ## 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
|
2299 ## 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
|
2300 ## ('!' denotes factorial). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2301 ## See also RIEMANN. |
16634 | 2302 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2303 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2304 ## 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
|
2305 ## 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
|
2306 ## Linear Algebra and Appl., 162 (1992), pp. 673-683. |
16634 | 2307 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2308 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
|
2309 error ("gallery: 1 argument is required for redheff matrix"); |
16634 | 2310 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
|
2311 error ("gallery: N must be an integer for redheff matrix"); |
16634 | 2312 endif |
2313 | |
2314 i = (1:n)' * ones (1, n); | |
2315 A = ! rem (i', i); | |
2316 A(:,1) = ones (n, 1); | |
2317 endfunction | |
2318 | |
2319 function A = riemann (n) | |
2320 ## 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
|
2321 ## 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
|
2322 ## 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
|
2323 ## 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
|
2324 ## ('!' denotes factorial). |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2325 ## 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
|
2326 ## 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
|
2327 ## 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
|
2328 ## 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
|
2329 ## 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
|
2330 ## All integers in the interval (M/3, M/2] are eigenvalues. |
16634 | 2331 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2332 ## See also REDHEFF. |
16634 | 2333 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2334 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2335 ## 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
|
2336 ## Linear Algebra and Appl., 81 (1986), pp. 153-198. |
16634 | 2337 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2338 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
|
2339 error ("gallery: 1 argument is required for riemann matrix"); |
16634 | 2340 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
|
2341 error ("gallery: N must be an integer for riemann matrix"); |
16634 | 2342 endif |
2343 | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2344 n += 1; |
16634 | 2345 i = (2:n)' * ones (1, n-1); |
2346 j = i'; | |
2347 A = i .* (! rem (j, i)) - ones (n-1); | |
2348 endfunction | |
2349 | |
2350 function A = ris (n) | |
2351 ## NOTE: this function was named dingdong in the original Test Matrix Toolbox | |
2352 ## 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
|
2353 ## 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
|
2354 ## 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
|
2355 ## The eigenvalues of A cluster around PI/2 and -PI/2. |
16634 | 2356 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2357 ## Invented by F.N. Ris. |
16634 | 2358 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2359 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2360 ## 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
|
2361 ## 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
|
2362 ## Bristol, 1990 (Appendix 1). |
16634 | 2363 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2364 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
|
2365 error ("gallery: 1 argument is required for ris matrix"); |
16634 | 2366 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
|
2367 error ("gallery: N must be an integer for ris matrix"); |
16634 | 2368 endif |
2369 | |
2370 p = -2*(1:n) + (n+1.5); | |
2371 A = cauchy (p); | |
2372 endfunction | |
2373 | |
2374 function A = smoke (n, k = 0) | |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2375 ## 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
|
2376 ## 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
|
2377 ## 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
|
2378 ## 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
|
2379 ## 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
|
2380 ## 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
|
2381 ## those of SMOKE(N) are the N'th roots of unity times 2^(1/N). |
16634 | 2382 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2383 ## 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
|
2384 ## 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
|
2385 ## GERSH(SMOKE(N, 1)) is interesting. |
16634 | 2386 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2387 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2388 ## 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
|
2389 ## Toeplitz matrices, Linear Algebra and Appl., 162-164:153-185, 1992. |
16634 | 2390 |
2391 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
|
2392 error ("gallery: 1 to 2 arguments are required for smoke matrix"); |
16634 | 2393 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
|
2394 error ("gallery: N must be an integer for smoke matrix"); |
16634 | 2395 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
|
2396 error ("gallery: K must be a numeric scalar for smoke matrix"); |
16634 | 2397 endif |
2398 | |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
2399 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
|
2400 A = diag ( [w.^(1:n-1) 1] ) + diag (ones (n-1,1), 1); |
16634 | 2401 |
2402 switch (k) | |
2403 case (0), A(n,1) = 1; | |
2404 case (1), # do nothing | |
2405 otherwise, | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2406 error ("gallery: K must have a value of 0 or 1 for smoke matrix"); |
16634 | 2407 endswitch |
2408 endfunction | |
2409 | |
2410 function T = toeppd (n, m = n, w = rand (m,1), theta = rand (m,1)) | |
2411 ## NOTE: this function was named pdtoep in the original Test Matrix Toolbox | |
2412 ## 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
|
2413 ## 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
|
2414 ## 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
|
2415 ## (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
|
2416 ## Specifically, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2417 ## 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
|
2418 ## 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
|
2419 ## Defaults: M = N, W = RAND(M,1), THETA = RAND(M,1). |
16634 | 2420 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2421 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2422 ## 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
|
2423 ## 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
|
2424 ## Comput., 7 (1986), pp. 123-131. |
16634 | 2425 |
2426 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
|
2427 error ("gallery: 1 to 4 arguments are required for toeppd matrix"); |
16634 | 2428 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
|
2429 error ("gallery: N must be a numeric integer for toeppd matrix"); |
16634 | 2430 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
|
2431 error ("gallery: M must be a numeric integer for toeppd matrix"); |
16634 | 2432 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
|
2433 error ("gallery: W and THETA must be vectors of length M for toeppd matrix"); |
16634 | 2434 endif |
2435 | |
2436 T = zeros (n); | |
2437 E = 2*pi * ((1:n)' * ones (1, n) - ones (n, 1) * (1:n)); | |
2438 | |
2439 for i = 1:m | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
2440 T += w(i) * cos (theta(i)*E); |
16634 | 2441 endfor |
2442 endfunction | |
2443 | |
2444 function P = toeppen (n, a = 1, b = -10, c = 0, d = 10, e = 1) | |
2445 ## NOTE: this function was named pentoep in the original Test Matrix Toolbox | |
2446 ## 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
|
2447 ## 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
|
2448 ## 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
|
2449 ## 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
|
2450 ## 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
|
2451 ## 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
|
2452 ## the line segment 2*cos(2*t) + 20*i*sin(t). |
16634 | 2453 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2454 ## Interesting plots are |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2455 ## 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
|
2456 ## 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
|
2457 ## PS(FULL(TOEPPEN(32,0,1/2,1,1,1))) - 'fish' |
16634 | 2458 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2459 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2460 ## 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
|
2461 ## 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
|
2462 ## 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
|
2463 ## 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
|
2464 ## 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
|
2465 ## 1966, pp. 349-365. |
16634 | 2466 |
2467 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
|
2468 error ("gallery: 1 to 6 arguments are required for toeppen matrix"); |
16634 | 2469 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
|
2470 error ("gallery: N must be a numeric integer for toeppen matrix"); |
17386
6dbc866379e2
Replace cellfun() occurrences with faster code where possible.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
2471 elseif (any (! cellfun ("isnumeric", {a b c d e})) || 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
|
2472 error ("gallery: A, B, C, D and E must be numeric scalars for toeppen matrix"); |
16634 | 2473 endif |
2474 | |
2475 P = spdiags ([a*ones(n,1) b*ones(n,1) c*ones(n,1) d*ones(n,1) e*ones(n,1)], | |
2476 -2:2, n, n); | |
2477 endfunction | |
2478 | |
2479 function T = tridiag (n, x = -1, y = 2, z = -1) | |
2480 ## TRIDIAG Tridiagonal matrix (sparse). | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2481 ## 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
|
2482 ## diagonal Y, and superdiagonal Z. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2483 ## 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
|
2484 ## 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
|
2485 ## 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
|
2486 ## 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
|
2487 ## 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
|
2488 ## 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
|
2489 ## 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
|
2490 ## 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
|
2491 ## second difference matrix). |
16634 | 2492 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2493 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2494 ## 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
|
2495 ## 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
|
2496 ## 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
|
2497 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. |
16634 | 2498 |
2499 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
|
2500 error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix"); |
16634 | 2501 elseif (nargin == 3) |
2502 z = y; | |
2503 y = x; | |
2504 x = n; | |
2505 endif | |
2506 | |
2507 ## Force column vectors | |
2508 x = x(:); | |
2509 y = y(:); | |
2510 z = z(:); | |
2511 | |
2512 if (isscalar (x) && isscalar (y) && isscalar (z)) | |
2513 x *= ones (n-1, 1); | |
2514 z *= ones (n-1, 1); | |
2515 y *= ones (n, 1); | |
2516 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
|
2517 error ("gallery: X must have one element less than Y for tridiag matrix"); |
16634 | 2518 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
|
2519 error ("gallery: Z must have one element less than Y for tridiag matrix"); |
16634 | 2520 endif |
2521 | |
2522 ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. | |
2523 n = numel (y); | |
2524 T = spdiags ([[x;0] y [0;z]], -1:1, n, n); | |
2525 endfunction | |
2526 | |
18846
3d33fe79816c
gallery.m: Return correct matrix if 3rd argument is not specified.
Rik <rik@octave.org>
parents:
18812
diff
changeset
|
2527 function t = triw (n, alpha = -1, k = n(end) - 1) |
16634 | 2528 ## 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
|
2529 ## 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
|
2530 ## 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
|
2531 ## 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
|
2532 ## upper trapezoidal. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2533 ## Defaults: ALPHA = -1, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2534 ## 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
|
2535 ## TRIW(N) is a matrix discussed by Kahan, Golub and Wilkinson. |
16634 | 2536 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2537 ## Ostrowski (1954) shows that |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2538 ## 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
|
2539 ## and for large ABS(ALPHA), |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2540 ## COND(TRIW(N,ALPHA)) is approximately ABS(ALPHA)^N*SIN(PI/(4*N-2)). |
16634 | 2541 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2542 ## 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
|
2543 ## as does adding -2^(1-N) to all elements in the first column. |
16634 | 2544 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2545 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2546 ## 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
|
2547 ## 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
|
2548 ## 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
|
2549 ## 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
|
2550 ## 9 (1966), pp. 757-801. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2551 ## 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
|
2552 ## 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
|
2553 ## 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
|
2554 ## 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
|
2555 ## Academic Press, London, 1978, pp. 109-135. |
16634 | 2556 |
2557 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
|
2558 error ("gallery: 1 to 3 arguments are required for triw matrix"); |
16634 | 2559 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
|
2560 error ("gallery: N must be a 1 or 2 elements vector for triw matrix"); |
16634 | 2561 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
|
2562 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
|
2563 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
|
2564 error ("gallery: K must be a numeric integer >= 0 for triw matrix"); |
16634 | 2565 endif |
2566 | |
2567 m = n(1); # Parameter n specifies dimension: m-by-n. | |
2568 n = n(end); | |
2569 | |
2570 t = tril (eye (m, n) + alpha * triu (ones (m, n), 1), k); | |
2571 endfunction | |
2572 | |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2573 function A = uniformdata (varargin) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2574 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2575 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
|
2576 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
|
2577 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2578 if (isnumeric (varargin{end})) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2579 jidx = varargin{end}; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2580 svec = [varargin{:}]; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2581 varargin(end) = []; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2582 elseif (ischar (varargin{end})) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2583 if (nargin < 3) |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2584 error (["gallery: CLASS argument requires 3 inputs " ... |
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2585 "for uniformdata matrix."]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2586 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2587 jidx = varargin{end-1}; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2588 svec = [varargin{1:end-1}]; |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2589 varargin(end-1) = []; |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2590 else |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2591 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
|
2592 "for uniformdata matrix"]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2593 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2594 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2595 if (! (isnumeric (jidx) && isscalar (jidx) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2596 && jidx == fix (jidx) |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2597 && jidx >= 0 && jidx <= 0xFFFFFFFF)) |
16979
9aa293e00475
gallery.m: Add 'normaldata' matrix to function.
Rik <rik@octave.org>
parents:
16978
diff
changeset
|
2598 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
|
2599 "for uniformdata matrix"]); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2600 endif |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2601 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2602 ## 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
|
2603 ## 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
|
2604 randstate = rand ("state"); |
16978
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2605 unwind_protect |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2606 rand ("state", svec); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2607 A = rand (varargin{:}); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2608 unwind_protect_cleanup |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2609 rand ("state", randstate); |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2610 end_unwind_protect |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2611 |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2612 endfunction |
00379f9f8773
gallery.m: Add 'uniformdata' matrix to function.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
2613 |
16634 | 2614 function A = wathen (nx, ny, k = 0) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2615 ## WATHEN returns the Wathen matrix. |
16634 | 2616 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2617 ## Discussion: |
16634 | 2618 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2619 ## The Wathen matrix is a finite element matrix which is sparse. |
16634 | 2620 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2621 ## 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
|
2622 ## 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
|
2623 ## 0 and 100. |
16634 | 2624 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2625 ## 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
|
2626 ## where N = 3*NX*NY + 2*NX + 2*NY + 1. |
16634 | 2627 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2628 ## 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
|
2629 ## grid of 8-node (serendipity) elements in 2 space dimensions. |
16634 | 2630 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2631 ## Here is an illustration for NX = 3, NX = 2: |
16634 | 2632 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2633 ## 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
|
2634 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2635 ## 19 20 21 22 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2636 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2637 ## 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
|
2638 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2639 ## 8 9 10 11 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2640 ## | | | | |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2641 ## 1--2--3--4--5--6--7 |
16634 | 2642 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2643 ## For this example, the total number of nodes is, as expected, |
16634 | 2644 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2645 ## N = 3 * 3 * 2 + 2 * 2 + 2 * 3 + 1 = 29. |
16634 | 2646 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2647 ## 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
|
2648 ## the density, RHO(NX,NY), which is chosen randomly in this routine. |
16634 | 2649 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2650 ## 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
|
2651 ## 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
|
2652 ## for any positive integers NX and NY and any densities RHO(NX,NY). |
16634 | 2653 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2654 ## A = WATHEN ( NX, NY, 1 ) returns the diagonally scaled matrix. |
16634 | 2655 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2656 ## Modified: |
16634 | 2657 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2658 ## 17 September 2007 |
16634 | 2659 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2660 ## Author: |
16634 | 2661 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2662 ## Nicholas Higham |
16634 | 2663 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2664 ## Reference: |
16634 | 2665 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2666 ## Nicholas Higham, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2667 ## 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
|
2668 ## ACM Transactions on Mathematical Software, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2669 ## Volume 17, Number 3, September 1991, pages 289-305. |
16634 | 2670 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2671 ## Andrew Wathen, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2672 ## 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
|
2673 ## IMA Journal of Numerical Analysis, |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2674 ## Volume 7, 1987, pages 449-457. |
16634 | 2675 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2676 ## Parameters: |
16634 | 2677 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2678 ## 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
|
2679 ## of the finite element grid. NX and NY must each be at least 1. |
16634 | 2680 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2681 ## 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
|
2682 ## 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
|
2683 ## the value 1. |
16634 | 2684 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2685 ## 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
|
2686 ## 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
|
2687 ## format. |
16634 | 2688 |
2689 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
|
2690 error ("gallery: 2 or 3 arguments are required for wathen matrix"); |
16634 | 2691 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
|
2692 error ("gallery: NX must be a positive scalar for wathen matrix"); |
16634 | 2693 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
|
2694 error ("gallery: NY must be a positive scalar for wathen matrix"); |
16634 | 2695 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
|
2696 error ("gallery: K must be a scalar for wathen matrix"); |
16634 | 2697 endif |
2698 | |
2699 e1 = [ 6 -6 2 -8 | |
2700 -6 32 -6 20 | |
2701 2 -6 6 -6 | |
2702 -8 20 -6 32 ]; | |
2703 | |
2704 e2 = [ 3 -8 2 -6 | |
2705 -8 16 -8 20 | |
2706 2 -8 3 -8 | |
2707 -6 20 -8 16 ]; | |
2708 | |
2709 e = [ e1 e2 | |
2710 e2' e1] / 45; | |
2711 | |
2712 n = 3*nx*ny + 2*nx + 2*ny + 1; | |
2713 | |
2714 A = sparse (n, n); | |
2715 | |
2716 rho = 100 * rand (nx, ny); | |
2717 | |
2718 for j = 1:ny | |
2719 for i = 1:nx | |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17386
diff
changeset
|
2720 ## |
16634 | 2721 ## 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
|
2722 ## |
16634 | 2723 nn(1) = 3*j*nx + 2*i + 2*j + 1; |
2724 nn(2) = nn(1) - 1; | |
2725 nn(3) = nn(2) - 1; | |
2726 nn(4) = (3*j - 1) * nx + 2*j + i - 1; | |
2727 nn(5) = 3 * (j-1) * nx + 2*i + 2*j - 3; | |
2728 nn(6) = nn(5) + 1; | |
2729 nn(7) = nn(6) + 1; | |
2730 nn(8) = nn(4) + 1; | |
2731 | |
2732 em = e * rho(i,j); | |
2733 | |
2734 for krow = 1:8 | |
2735 for kcol = 1:8 | |
2736 A(nn(krow),nn(kcol)) = A(nn(krow),nn(kcol)) + em(krow,kcol); | |
2737 endfor | |
2738 endfor | |
2739 | |
2740 endfor | |
2741 endfor | |
2742 | |
2743 ## If requested, return A with diagonal scaling. | |
2744 if (k) | |
2745 A = diag (diag (A)) \ A; | |
2746 endif | |
2747 endfunction | |
2748 | |
2749 function [A, b] = wilk (n) | |
2750 ## 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
|
2751 ## [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
|
2752 ## 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
|
2753 ## 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
|
2754 ## 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
|
2755 ## N = 21: W21+, tridiagonal. Eigenvalue problem. |
16634 | 2756 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2757 ## References: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2758 ## 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
|
2759 ## 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
|
2760 ## 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
|
2761 ## 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
|
2762 ## 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
|
2763 ## Press, 1965. |
16634 | 2764 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27931
diff
changeset
|
2765 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
|
2766 error ("gallery: 1 argument is required for wilk matrix"); |
16634 | 2767 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
|
2768 error ("gallery: N must be a numeric scalar for wilk matrix"); |
16634 | 2769 endif |
2770 | |
2771 if (n == 3) | |
2772 ## Wilkinson (1961) p.323. | |
2773 A = [ 1e-10 0.9 -0.4 | |
2774 0 0.9 -0.4 | |
2775 0 0 1e-10 ]; | |
2776 | |
2777 b = [ 0 | |
2778 0 | |
2779 1]; | |
2780 | |
2781 elseif (n == 4) | |
2782 ## Wilkinson (1963) p.105. | |
2783 A = [0.9143e-4 0 0 0 | |
2784 0.8762 0.7156e-4 0 0 | |
2785 0.7943 0.8143 0.9504e-4 0 | |
2786 0.8017 0.6123 0.7165 0.7123e-4]; | |
2787 | |
2788 b = [0.6524 | |
2789 0.3127 | |
2790 0.4186 | |
2791 0.7853]; | |
2792 | |
2793 elseif (n == 5) | |
2794 ## Wilkinson (1965), p.234. | |
2795 A = hilb (6); | |
2796 A = A(1:5, 2:6) * 1.8144; | |
2797 | |
2798 elseif (n == 21) | |
2799 ## Wilkinson (1965), p.308. | |
2800 E = diag (ones (n-1, 1), 1); | |
2801 m = (n-1)/2; | |
2802 A = diag (abs (-m:m)) + E + E'; | |
2803 | |
2804 else | |
28905
89a425f2c202
maint: Use Octave convention that error() messages don't end with a period.
Rik <rik@octave.org>
parents:
28904
diff
changeset
|
2805 error ("gallery: unknown N '%d' for wilk matrix", n); |
16634 | 2806 endif |
2807 endfunction | |
2808 | |
2809 ## NOTE: bandred is part of the Test Matrix Toolbox and is used by randsvd() | |
2810 function A = bandred (A, kl, ku) | |
2811 ## 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
|
2812 ## 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
|
2813 ## 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
|
2814 ## (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
|
2815 ## 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
|
2816 ## If KU is omitted it defaults to KL. |
16634 | 2817 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2818 ## Called by RANDSVD. |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27085
diff
changeset
|
2819 ## 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
|
2820 ## 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
|
2821 ## 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
|
2822 ## |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2823 ## Reference: |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2824 ## 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
|
2825 ## 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
|
2826 ## Section 5.4.3. |
16634 | 2827 |
2828 ## Check for special case where order of left/right transformations matters. | |
2829 ## Easiest approach is to work on the transpose, flipping back at the end. | |
2830 flip = false; | |
2831 if (ku == 0) | |
2832 flip = true; | |
2833 A = A'; | |
2834 [ku, kl] = deal (kl, ku); | |
2835 endif | |
2836 | |
2837 [m, n] = size (A); | |
2838 | |
2839 for j = 1:min (min (m, n), max (m-kl-1, n-ku-1)) | |
2840 if (j+kl+1 <= m) | |
2841 [v, beta] = house (A(j+kl:m,j)); | |
2842 temp = A(j+kl:m,j:n); | |
2843 A(j+kl:m,j:n) = temp - beta*v*(v'*temp); | |
2844 A(j+kl+1:m,j) = zeros (m-j-kl, 1); | |
2845 endif | |
2846 | |
2847 if (j+ku+1 <= n) | |
2848 [v, beta] = house (A(j,j+ku:n)'); | |
2849 temp = A(j:m,j+ku:n); | |
2850 A(j:m,j+ku:n) = temp - beta*(temp*v)*v'; | |
2851 A(j,j+ku+1:n) = zeros (1, n-j-ku); | |
2852 endif | |
2853 endfor | |
2854 | |
2855 if (flip) | |
2856 A = A'; | |
2857 endif | |
2858 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
2859 |
20296
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2860 ## 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
|
2861 function B = qmult (A) |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2862 ## 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
|
2863 ## 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
|
2864 ## 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
|
2865 ## 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
|
2866 ## QMULT(EYE(A)). |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2867 ## |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2868 ## Called by RANDSVD. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2869 ## |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2870 ## Reference: |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2871 ## 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
|
2872 ## 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
|
2873 ## 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
|
2874 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2875 [n, m] = size (A); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2876 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2877 ## Handle scalar A |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2878 if (isscalar (A)) |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2879 n = A; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2880 A = eye (n); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2881 endif |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2882 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2883 d = zeros (n); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2884 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2885 for k = n-1:-1:1 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2886 ## Generate random Householder transformation. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2887 x = randn (n-k+1, 1); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2888 s = norm (x); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2889 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
|
2890 s = sgn*s; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2891 d(k) = -sgn; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2892 x(1) = x(1) + s; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2893 beta = s*x(1); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2894 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2895 ## Apply the transformation to A. |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2896 y = x'*A(k:n,:); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2897 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
|
2898 endfor |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2899 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2900 ## Tidy up signs |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2901 for i = 1:n-1 |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2902 A(i,:) = d(i)*A(i,:); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2903 endfor |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2904 A(n,:) = A(n,:) * sign (randn); |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2905 B = A; |
0b9d23557506
gallery: fix randsvd by adding missing dependency qmult().
Carnë Draug <carandraug@octave.org>
parents:
20295
diff
changeset
|
2906 endfunction |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
2907 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
2908 |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
2909 ## 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
|
2910 ## 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
|
2911 %!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
|
2912 %!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
|
2913 |
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
2914 ## 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
|
2915 %!error <Invalid call> gallery () |
19226
cdfc8bc9ab62
gallery.m: Add BIST tests for central dispatch function.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
2916 %!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
|
2917 %!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
|
2918 %!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
|
2919 |
21759
b002b4331a12
maint: Use two newlines after endfunction and start of BIST tests.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
2920 ## BIST testing for individual gallery functions |
19944
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
2921 %!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
|
2922 %!assert (gallery ("minij", 1), 1) |
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
2923 %!assert (gallery ("minij", 0), []) |
941e782d0429
gallery: performance increase for minij matrix.
Carnë Draug <carandraug@octave.org>
parents:
19833
diff
changeset
|
2924 %!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
|
2925 |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2926 %!test |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2927 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2928 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2929 %! 3 4 5 6 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2930 %! 4 5 6 7 8 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2931 %! 5 6 7 8 9 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2932 %! 6 7 8 9 10]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2933 %! assert (gallery ("cauchy", 5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2934 %! assert (gallery ("cauchy", 1:5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2935 %! 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
|
2936 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2937 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2938 %! 1 2 3 4 5 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2939 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2940 %! 3 4 5 6 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2941 %! 4 5 6 7 8 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2942 %! 5 6 7 8 9]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2943 %! 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
|
2944 %! 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
|
2945 %! 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
|
2946 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2947 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2948 %! -1 0 1 2 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2949 %! 0 1 2 3 4 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2950 %! 1 2 3 4 5 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2951 %! 2 3 4 5 6 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2952 %! 3 4 5 6 7]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2953 %! 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
|
2954 %! |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2955 %! exp = 1 ./ [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2956 %! 8 18 -4 2 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2957 %! 13 23 1 7 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2958 %! 9 19 -3 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
2959 %! 15 25 3 9]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
2960 %! 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
|
2961 %! 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
|
2962 %! 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
|
2963 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2964 %!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
|
2965 %!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
|
2966 %!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
|
2967 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2968 %!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
|
2969 %!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
|
2970 %!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
|
2971 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2972 %!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
|
2973 %!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
|
2974 %!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
|
2975 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2976 %!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
|
2977 %!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
|
2978 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2979 %!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
|
2980 %!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
|
2981 %!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
|
2982 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2983 %!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
|
2984 %!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
|
2985 %!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
|
2986 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2987 %!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
|
2988 %!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
|
2989 %!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
|
2990 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2991 %!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
|
2992 %!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
|
2993 %!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
|
2994 %!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
|
2995 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2996 %!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
|
2997 %!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
|
2998 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
2999 %!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
|
3000 %!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
|
3001 |
23381
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3002 %!test |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3003 %! exp = [ |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3004 %! 0 1 2 3 4 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3005 %! 1 0 1 2 3 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3006 %! 2 1 0 1 2 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3007 %! 3 2 1 0 1 |
e15ffa2b2262
gallery: use broadcasting to generate cauchy and fiedler matrices
Carnë Draug <carandraug@octave.org>
parents:
23084
diff
changeset
|
3008 %! 4 3 2 1 0]; |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3009 %! assert (gallery ("fiedler", 5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3010 %! assert (gallery ("fiedler", 1:5), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3011 %! assert (gallery ("fiedler", -2:2), exp); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28905
diff
changeset
|
3012 %! 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
|
3013 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3014 %!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
|
3015 %!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
|
3016 %!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
|
3017 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3018 %!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
|
3019 %!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
|
3020 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3021 %!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
|
3022 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3023 %!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
|
3024 %!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
|
3025 %!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
|
3026 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3027 %!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
|
3028 %!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
|
3029 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3030 %!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
|
3031 %!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
|
3032 %!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
|
3033 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3034 %!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
|
3035 %!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
|
3036 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3037 %!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
|
3038 %!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
|
3039 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3040 %!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
|
3041 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3042 %!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
|
3043 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3044 %!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
|
3045 %!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
|
3046 %!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
|
3047 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3048 %!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
|
3049 %!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
|
3050 %!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
|
3051 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3052 %!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
|
3053 %!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
|
3054 %!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
|
3055 %!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
|
3056 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3057 %!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
|
3058 %!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
|
3059 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3060 %!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
|
3061 %!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
|
3062 %!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
|
3063 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3064 %!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
|
3065 %!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
|
3066 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3067 %!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
|
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 ("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
|
3070 |
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 ("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
|
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 ("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
|
3074 |
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 ("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
|
3076 %!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
|
3077 |
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 ("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
|
3079 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3080 %!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
|
3081 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3082 %!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
|
3083 %!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
|
3084 %!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
|
3085 |
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 ("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
|
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 ("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
|
3089 %!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
|
3090 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3091 %!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
|
3092 %!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
|
3093 %!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
|
3094 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3095 %!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
|
3096 %!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
|
3097 |
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 ("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
|
3099 %!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
|
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 ("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
|
3102 %!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
|
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 ("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
|
3105 %!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
|
3106 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3107 %!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
|
3108 %!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
|
3109 %!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
|
3110 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3111 %!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
|
3112 %!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
|
3113 %!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
|
3114 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3115 %!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
|
3116 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3117 %!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
|
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 ("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
|
3120 %!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
|
3121 %!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
|
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 ("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
|
3124 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3125 %!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
|
3126 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3127 %!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
|
3128 |
c5a8eff5a05d
gallery: add very basic tests (check output size) for all matrix types.
Carnë Draug <carandraug@octave.org>
parents:
20298
diff
changeset
|
3129 %!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
|
3130 %!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
|
3131 %!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
|
3132 %!assert (size (gallery ("wilk", 21)), [21 21]) |