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