Mercurial > octave
annotate scripts/linear-algebra/condest.m @ 33625:d213a148b3f1 default tip @
ensure exp. terminal widget has focus at startup
* main-window.cc (main_window): call focus_command_window only if
event loop is idle by using a single shot timer
* main-window.h: make focus_command_window a public slot
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 26 May 2024 02:29:44 +0200 |
parents | c6ef7981b6f1 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 2007-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
7189 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
7189 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
7189 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
7189 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
21 ## along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
7189 | 25 |
26 ## -*- texinfo -*- | |
22824 | 27 ## @deftypefn {} {@var{cest} =} condest (@var{A}) |
28 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{t}) | |
28158 | 29 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}) |
30 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}, @var{t}) | |
31 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{Ainvfcn}, @var{t}, @var{p1}, @var{p2}, @dots{}) | |
32 ## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}) | |
33 ## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}, @var{t}) | |
34 ## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{Ainvfcn}, @var{t}, @var{p1}, @var{p2}, @dots{}) | |
22824 | 35 ## @deftypefnx {} {[@var{cest}, @var{v}] =} condest (@dots{}) |
7189 | 36 ## |
22824 | 37 ## Estimate the 1-norm condition number of a square matrix @var{A} using |
38 ## @var{t} test vectors and a randomized 1-norm estimator. | |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
39 ## |
22824 | 40 ## The optional input @var{t} specifies the number of test vectors (default 5). |
7189 | 41 ## |
28158 | 42 ## The input may be a matrix @var{A} (the algorithm is particularly |
43 ## appropriate for large, sparse matrices). Alternatively, the behavior of | |
44 ## the matrix can be defined implicitly by functions. When using an implicit | |
45 ## definition, @code{condest} requires the following functions: | |
7189 | 46 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
47 ## @itemize @minus |
28158 | 48 ## @item @code{@var{Afcn} (@var{flag}, @var{x})} which must return |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
49 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
50 ## @itemize @bullet |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
51 ## @item |
28158 | 52 ## the dimension @var{n} of @var{A}, if @var{flag} is @qcode{"dim"} |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
53 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
54 ## @item |
28158 | 55 ## true if @var{A} is a real operator, if @var{flag} is @qcode{"real"} |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
56 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
57 ## @item |
28158 | 58 ## the result @code{@var{A} * @var{x}}, if @var{flag} is "notransp" |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
59 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
60 ## @item |
28158 | 61 ## the result @code{@var{A}' * @var{x}}, if @var{flag} is "transp" |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
62 ## @end itemize |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
63 ## |
28158 | 64 ## @item @code{@var{Ainvfcn} (@var{flag}, @var{x})} which must return |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
65 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
66 ## @itemize @bullet |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
67 ## @item |
28158 | 68 ## the dimension @var{n} of @code{inv (@var{A})}, if @var{flag} is |
69 ## @qcode{"dim"} | |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
70 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
71 ## @item |
28158 | 72 ## true if @code{inv (@var{A})} is a real operator, if @var{flag} is |
73 ## @qcode{"real"} | |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
74 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
75 ## @item |
28158 | 76 ## the result @code{inv (@var{A}) * @var{x}}, if @var{flag} is "notransp" |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
77 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
78 ## @item |
28158 | 79 ## the result @code{inv (@var{A})' * @var{x}}, if @var{flag} is "transp" |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
80 ## @end itemize |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
81 ## @end itemize |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
82 ## |
28158 | 83 ## Any parameters @var{p1}, @var{p2}, @dots{} are additional arguments of |
22824 | 84 ## @code{@var{Afcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})} |
28158 | 85 ## and @code{@var{Ainvfcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})}. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
86 ## |
22824 | 87 ## The principal output is the 1-norm condition number estimate @var{cest}. |
7189 | 88 ## |
28158 | 89 ## The optional second output @var{v} is an approximate null vector; it |
90 ## satisfies the equation @code{norm (@var{A}*@var{v}, 1) == | |
91 ## norm (@var{A}, 1) * norm (@var{v}, 1) / @var{cest}}. | |
22824 | 92 ## |
22827
c3d3a81ad986
doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents:
22824
diff
changeset
|
93 ## Algorithm Note: @code{condest} uses a randomized algorithm to approximate |
22824 | 94 ## the 1-norms. Therefore, if consistent results are required, the |
95 ## @qcode{"state"} of the random generator should be fixed before invoking | |
96 ## @code{condest}. | |
7189 | 97 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 ## References: |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
14522
diff
changeset
|
99 ## |
7189 | 100 ## @itemize |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 103 ## for Matrix 1-Norm Estimation, with an Application to 1-Norm |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
27585
diff
changeset
|
104 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185--1201. |
25143
13fd0610480f
doc: Use https whenever possible in @url entries.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
105 ## @url{https://dx.doi.org/10.1137/S0895479899356080} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
106 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
107 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 109 ## for Matrix 1-Norm Estimation, with an Application to 1-Norm |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
27585
diff
changeset
|
110 ## Pseudospectra}. @url{https://citeseer.ist.psu.edu/223007.html} |
7189 | 111 ## @end itemize |
112 ## | |
28158 | 113 ## @seealso{cond, rcond, norm, normest1, normest} |
7189 | 114 ## @end deftypefn |
115 | |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
116 ## Code originally licensed under: |
7189 | 117 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
118 ## Copyright (c) 2007, Regents of the University of California |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
119 ## All rights reserved. |
7191 | 120 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
121 ## Redistribution and use in source and binary forms, with or without |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
122 ## modification, are permitted provided that the following conditions |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
123 ## are met: |
7189 | 124 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
125 ## * Redistributions of source code must retain the above copyright |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
126 ## notice, this list of conditions and the following disclaimer. |
7191 | 127 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
128 ## * Redistributions in binary form must reproduce the above |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
129 ## copyright notice, this list of conditions and the following |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
130 ## disclaimer in the documentation and/or other materials provided |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
131 ## with the distribution. |
7191 | 132 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
133 ## * Neither the name of the University of California, Berkeley nor |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
134 ## the names of its contributors may be used to endorse or promote |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
135 ## products derived from this software without specific prior |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
136 ## written permission. |
7189 | 137 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
138 ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
139 ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
140 ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
141 ## PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
142 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
143 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
144 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
145 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
146 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
147 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
148 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
149 ## SUCH DAMAGE. |
7189 | 150 |
22826 | 151 function [cest, v] = condest (varargin) |
7191 | 152 |
7309 | 153 if (nargin < 1 || nargin > 6) |
7191 | 154 print_usage (); |
7189 | 155 endif |
156 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
157 have_A = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
158 have_t = false; |
28158 | 159 have_Afcn = false; |
160 have_Ainvfcn = false; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
161 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
162 if (isnumeric (varargin{1})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
163 A = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
164 if (! issquare (A)) |
22826 | 165 error ("condest: A must be square"); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
166 endif |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
167 have_A = true; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
168 n = rows (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
169 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
170 if (is_function_handle (varargin{2})) |
28158 | 171 Ainvfcn = varargin{2}; |
172 have_Ainvfcn = true; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
173 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
174 t = varargin{3}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
175 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
176 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
177 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
178 t = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
179 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
180 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
181 endif |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
182 elseif (is_function_handle (varargin{1})) |
22826 | 183 if (nargin == 1) |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28693
diff
changeset
|
184 error ("condest: must provide AINVFCN when using AFCN"); |
22826 | 185 endif |
28158 | 186 Afcn = varargin{1}; |
187 have_Afcn = true; | |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
188 if (! is_function_handle (varargin{2})) |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28693
diff
changeset
|
189 error ("condest: AINVFCN must be a function handle"); |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
190 endif |
28158 | 191 Ainvfcn = varargin{2}; |
192 have_Ainvfcn = true; | |
193 n = Afcn ("dim", [], varargin{4:end}); | |
22826 | 194 if (nargin > 2) |
195 t = varargin{3}; | |
196 have_t = true; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
197 endif |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
198 else |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
199 error ("condest: first argument must be a square matrix or function handle"); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
200 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
201 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
202 if (! have_t) |
22826 | 203 t = min (n, 5); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
204 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
205 |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
206 ## Disable warnings which may be emitted during calculation process. |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
207 warning ("off", "Octave:nearly-singular-matrix", "local"); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
208 |
28158 | 209 if (! have_Ainvfcn) |
210 ## Prepare Ainvfcn in normest1 form | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
211 if (issparse (A)) |
28158 | 212 [L, U, P, Q] = lu (A); |
213 Ainvfcn = @inv_sparse_fcn; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
214 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
215 [L, U, P] = lu (A); |
28158 | 216 Q = []; |
217 Ainvfcn = @inv_full_fcn; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
218 endif |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
219 |
28158 | 220 ## Check for singular matrices before continuing (bug #46737) |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
221 if (any (diag (U) == 0)) |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
222 cest = Inf; |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
223 v = []; |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
224 return; |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
225 endif |
28158 | 226 |
227 ## Initialize solver | |
228 Ainvfcn ("init", A, L, U, P, Q); | |
229 clear L U P Q; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
230 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
231 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
232 if (have_A) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
233 Anorm = norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
234 else |
28158 | 235 Anorm = normest1 (Afcn, t, [], varargin{4:end}); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
236 endif |
28158 | 237 [Ainv_norm, v, w] = normest1 (Ainvfcn, t, [], varargin{4:end}); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
238 |
22826 | 239 cest = Anorm * Ainv_norm; |
32786
c6ef7981b6f1
replace uses of isargout with checks for nargout
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
240 if (nargout > 1) |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
241 v = w / norm (w, 1); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
242 endif |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
243 |
28158 | 244 if (! have_Ainvfcn) |
245 Ainvfcn ("clear"); # clear persistent memory in subfunction | |
246 endif | |
247 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
248 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
249 |
28158 | 250 function retval = inv_sparse_fcn (flag, x, varargin) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
251 |
28158 | 252 ## FIXME: Sparse algorithm is less accurate than full matrix version. |
253 ## See BIST test for asymmetric matrix where relative tolerance | |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
254 ## of 1e-12 is used for sparse, but 4e-16 for full matrix. |
28158 | 255 ## BUT, does it really matter for an "estimate"? |
256 persistent Ainv Ainvt n isreal_op; | |
257 | |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
258 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
259 case "dim" |
28158 | 260 retval = n; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
261 case "real" |
28158 | 262 retval = isreal_op; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
263 case "notransp" |
28158 | 264 retval = Ainv * x; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
265 case "transp" |
28158 | 266 retval = Ainvt * x; |
267 case "init" | |
28693
2bb050267d74
maint: Remove trailing spaces from code base.
Rik <rik@octave.org>
parents:
28295
diff
changeset
|
268 n = rows (x); |
28158 | 269 isreal_op = isreal (x); |
270 [L, U, P, Q] = deal (varargin{1:4}); | |
271 Ainv = Q * (U \ (L \ P)); | |
272 Ainvt = P' * (L' \ (U' \ Q')); | |
273 case "clear" # called to free memory at end of condest function | |
274 clear Ainv Ainvt n isreal_op; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
275 endswitch |
28158 | 276 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
277 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
278 |
28158 | 279 function retval = inv_full_fcn (flag, x, varargin) |
280 persistent Ainv Ainvt n isreal_op; | |
281 | |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
282 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
283 case "dim" |
28158 | 284 retval = n; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
285 case "real" |
28158 | 286 retval = isreal_op; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
287 case "notransp" |
28158 | 288 retval = Ainv * x; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
289 case "transp" |
28158 | 290 retval = Ainvt \ x; |
291 case "init" | |
28693
2bb050267d74
maint: Remove trailing spaces from code base.
Rik <rik@octave.org>
parents:
28295
diff
changeset
|
292 n = rows (x); |
28158 | 293 isreal_op = isreal (x); |
294 [L, U, P] = deal (varargin{1:3}); | |
295 Ainv = U \ (L \ P); | |
296 Ainvt = P' * (L' \ U'); | |
297 case "clear" # called to free memory at end of condest function | |
298 clear Ainv Ainvt n isreal_op; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
299 endswitch |
28158 | 300 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
301 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
302 |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
303 |
22826 | 304 ## Note: These test bounds are very loose. There is enough randomization to |
305 ## trigger odd cases with hilb(). | |
7189 | 306 |
28158 | 307 %!function retval = __Afcn__ (flag, x, A, m) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
308 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
309 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
310 %! endif |
22826 | 311 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
312 %! case "dim" |
28158 | 313 %! retval = length (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
314 %! case "real" |
28158 | 315 %! retval = isreal (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
316 %! case "notransp" |
28158 | 317 %! retval = x; for i = 1:m, retval = A * retval;, endfor |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
318 %! case "transp" |
28158 | 319 %! retval = x; for i = 1:m, retval = A' * retval;, endfor |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
320 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
321 %!endfunction |
28158 | 322 %!function retval = __Ainvfcn__ (flag, x, A, m) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
323 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
324 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
325 %! endif |
22826 | 326 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
327 %! case "dim" |
28158 | 328 %! retval = length (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
329 %! case "real" |
28158 | 330 %! retval = isreal (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
331 %! case "notransp" |
28158 | 332 %! retval = x; for i = 1:m, retval = A \ retval;, endfor |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
333 %! case "transp" |
28158 | 334 %! retval = x; for i = 1:m, retval = A' \ retval;, endfor |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
335 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
336 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
337 |
7189 | 338 %!test |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
339 %! N = 6; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
340 %! A = hilb (N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
341 %! cA = condest (A); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
342 %! cA_test = norm (inv (A), 1) * norm (A, 1); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
343 %! assert (cA, cA_test, -2^-8); |
7189 | 344 |
345 %!test | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
346 %! N = 12; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
347 %! A = hilb (N); |
22826 | 348 %! [~, v] = condest (A); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
349 %! x = A*v; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
350 %! assert (norm (x, inf), 0, eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
351 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
352 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
353 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
354 %! A = hilb (N); |
28158 | 355 %! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); |
356 %! cA = condest (A, Ainvfcn); | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
357 %! cA_test = norm (inv (A), 1) * norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
358 %! assert (cA, cA_test, -2^-6); |
22826 | 359 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
360 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
361 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
362 %! A = hilb (N); |
28158 | 363 %! Afcn = @(flag, x) __Afcn__ (flag, x, A); |
364 %! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); | |
365 %! cA = condest (Afcn, Ainvfcn); | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
366 %! cA_test = norm (inv (A), 1) * norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
367 %! assert (cA, cA_test, -2^-6); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
368 |
28158 | 369 %!test # parameters for apply and Ainvfcn functions |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
370 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
371 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
372 %! m = 2; |
28158 | 373 %! cA = condest (@__Afcn__, @__Ainvfcn__, [], A, m); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
374 %! cA_test = norm (inv (A^2), 1) * norm (A^2, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
375 %! assert (cA, cA_test, -2^-6); |
22826 | 376 |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
377 ## Test singular matrices |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
378 %!test <*46737> |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
379 %! A = [ 0 0 0 |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
380 %! 0 3.33333 0.0833333 |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
381 %! 0 0.0833333 1.66667]; |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
382 %! [cest, v] = condest (A); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
383 %! assert (cest, Inf); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
384 %! assert (v, []); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
385 |
28158 | 386 ## Test asymmetric matrices |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
387 %!test <*57968> |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
388 %! A = reshape (sqrt (0:15), 4, 4); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
389 %! cexp = norm (A, 1) * norm (inv (A), 1); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
390 %! cest = condest (A); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
391 %! assert (cest, cexp, -2*eps); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
392 |
28294
7096f672f611
condest.m: Make test with sparse matrix conditional on UMFPACK.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28152
diff
changeset
|
393 %!testif HAVE_UMFPACK <*57968> |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
394 %! As = sparse (reshape (sqrt (0:15), 4, 4)); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
395 %! cexp = norm (As, 1) * norm (inv (As), 1); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
396 %! cest = condest (As); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
397 %! assert (cest, cexp, -1e-12); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
398 |
22826 | 399 ## Test input validation |
28158 | 400 %!error <Invalid call> condest () |
401 %!error <Invalid call> condest (1,2,3,4,5,6,7) | |
402 %!error <A must be square> condest ([1, 2]) | |
403 %!error <must provide AINVFCN when using AFCN> condest (@sin) | |
404 %!error <AINVFCN must be a function handle> condest (@sin, 1) | |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
405 %!error <argument must be a square matrix or function handle> condest ({1}) |