Mercurial > octave
annotate scripts/linear-algebra/condest.m @ 28693:2bb050267d74
maint: Remove trailing spaces from code base.
* NEWS, __ftp__.cc, graphics.in.h, rng.m, importdata.m, condest.m,
fieldnames.m, uninstall.m, polyfit.m, dec2bin.m, dec2hex.m:
Remove trailing spaces from code base.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 08 Sep 2020 08:34:28 -0700 |
parents | a01ad9893641 |
children | 0de38a6ef693 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2007-2020 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) |
28158 | 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})) |
28158 | 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; |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
240 if (isargout (2)) |
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) |
251 ## FIXME: Sparse algorithm is less accurate than full matrix version. | |
252 ## 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
|
253 ## of 1e-12 is used for sparse, but 4e-16 for full matrix. |
28158 | 254 ## BUT, does it really matter for an "estimate"? |
255 persistent Ainv Ainvt n isreal_op; | |
256 | |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
257 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
258 case "dim" |
28158 | 259 retval = n; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
260 case "real" |
28158 | 261 retval = isreal_op; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
262 case "notransp" |
28158 | 263 retval = Ainv * x; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
264 case "transp" |
28158 | 265 retval = Ainvt * x; |
266 case "init" | |
28693
2bb050267d74
maint: Remove trailing spaces from code base.
Rik <rik@octave.org>
parents:
28295
diff
changeset
|
267 n = rows (x); |
28158 | 268 isreal_op = isreal (x); |
269 [L, U, P, Q] = deal (varargin{1:4}); | |
270 Ainv = Q * (U \ (L \ P)); | |
271 Ainvt = P' * (L' \ (U' \ Q')); | |
272 case "clear" # called to free memory at end of condest function | |
273 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
|
274 endswitch |
28158 | 275 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
276 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
277 |
28158 | 278 function retval = inv_full_fcn (flag, x, varargin) |
279 persistent Ainv Ainvt n isreal_op; | |
280 | |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
281 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
282 case "dim" |
28158 | 283 retval = n; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
284 case "real" |
28158 | 285 retval = isreal_op; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
286 case "notransp" |
28158 | 287 retval = Ainv * x; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
288 case "transp" |
28158 | 289 retval = Ainvt \ x; |
290 case "init" | |
28693
2bb050267d74
maint: Remove trailing spaces from code base.
Rik <rik@octave.org>
parents:
28295
diff
changeset
|
291 n = rows (x); |
28158 | 292 isreal_op = isreal (x); |
293 [L, U, P] = deal (varargin{1:3}); | |
294 Ainv = U \ (L \ P); | |
295 Ainvt = P' * (L' \ U'); | |
296 case "clear" # called to free memory at end of condest function | |
297 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
|
298 endswitch |
28158 | 299 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
300 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
301 |
25798
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
302 |
22826 | 303 ## Note: These test bounds are very loose. There is enough randomization to |
304 ## trigger odd cases with hilb(). | |
7189 | 305 |
28158 | 306 %!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
|
307 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
308 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
309 %! endif |
22826 | 310 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
311 %! case "dim" |
28158 | 312 %! retval = length (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
313 %! case "real" |
28158 | 314 %! retval = isreal (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
315 %! case "notransp" |
28158 | 316 %! 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
|
317 %! case "transp" |
28158 | 318 %! 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
|
319 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
320 %!endfunction |
28158 | 321 %!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
|
322 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
323 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
324 %! endif |
22826 | 325 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
326 %! case "dim" |
28158 | 327 %! retval = length (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
328 %! case "real" |
28158 | 329 %! retval = isreal (A); |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
330 %! case "notransp" |
28158 | 331 %! 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
|
332 %! case "transp" |
28158 | 333 %! 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
|
334 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
335 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
336 |
7189 | 337 %!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
|
338 %! 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
|
339 %! 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
|
340 %! 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
|
341 %! 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
|
342 %! assert (cA, cA_test, -2^-8); |
7189 | 343 |
344 %!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
|
345 %! 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
|
346 %! A = hilb (N); |
22826 | 347 %! [~, 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
|
348 %! x = A*v; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
349 %! 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
|
350 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
351 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
352 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
353 %! A = hilb (N); |
28158 | 354 %! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); |
355 %! 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
|
356 %! 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
|
357 %! assert (cA, cA_test, -2^-6); |
22826 | 358 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
359 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
360 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
361 %! A = hilb (N); |
28158 | 362 %! Afcn = @(flag, x) __Afcn__ (flag, x, A); |
363 %! Ainvfcn = @(flag, x) __Ainvfcn__ (flag, x, A); | |
364 %! 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
|
365 %! 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
|
366 %! 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
|
367 |
28158 | 368 %!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
|
369 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
370 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
371 %! m = 2; |
28158 | 372 %! 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
|
373 %! 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
|
374 %! assert (cA, cA_test, -2^-6); |
22826 | 375 |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
376 ## 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
|
377 %!test <*46737> |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
378 %! 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
|
379 %! 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
|
380 %! 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
|
381 %! [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
|
382 %! assert (cest, Inf); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
383 %! assert (v, []); |
4e4ffcca8b5d
condest.m: Overhaul function to return Inf for singular matrices (bug #46737).
Rik <rik@octave.org>
parents:
25146
diff
changeset
|
384 |
28158 | 385 ## Test asymmetric matrices |
28152
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
386 %!test <*57968> |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
387 %! 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
|
388 %! 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
|
389 %! cest = condest (A); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
390 %! 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
|
391 |
28294
7096f672f611
condest.m: Make test with sparse matrix conditional on UMFPACK.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28152
diff
changeset
|
392 %!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
|
393 %! 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
|
394 %! 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
|
395 %! cest = condest (As); |
4609d001daee
condest.m: Fix estimate when matrix is not symmetric (bug #57968).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
396 %! 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
|
397 |
22826 | 398 ## Test input validation |
28158 | 399 %!error <Invalid call> condest () |
400 %!error <Invalid call> condest (1,2,3,4,5,6,7) | |
401 %!error <A must be square> condest ([1, 2]) | |
402 %!error <must provide AINVFCN when using AFCN> condest (@sin) | |
403 %!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
|
404 %!error <argument must be a square matrix or function handle> condest ({1}) |