Mercurial > octave
annotate scripts/linear-algebra/condest.m @ 22826:b7bf2d6d8e55
condest.m: Overhaul function.
* condest.m: Rename output 'est' to 'cest' to match documentation.
Eliminate unnecessary default_t variable. Use names of bad inuts in error()
messages. Reorder code to have input validation first. Add FIXME notes.
Add parentheses around conditions in switch statements. Add BIST tests
for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 24 Nov 2016 07:16:17 -0800 |
parents | c5f496b8352c |
children | 41a751b19fd2 |
rev | line source |
---|---|
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
1 ## Copyright (C) 2007-2016 Regents of the University of California |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
2 ## Copyright (C) 2016 Marco Caliari |
7189 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
9 ## (at your option) any later version. |
7189 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
14 ## GNU General Public License for more details. |
7189 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
17 ## along with Octave; see the file COPYING. If not, see | |
18 ## <http://www.gnu.org/licenses/>. | |
19 | |
20 ## -*- texinfo -*- | |
22824 | 21 ## @deftypefn {} {@var{cest} =} condest (@var{A}) |
22 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{t}) | |
23 ## @deftypefnx {} {@var{cest} =} condest (@var{A}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) | |
24 ## @deftypefnx {} {@var{cest} =} condest (@var{Afcn}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) | |
25 ## @deftypefnx {} {[@var{cest}, @var{v}] =} condest (@dots{}) | |
7189 | 26 ## |
22824 | 27 ## Estimate the 1-norm condition number of a square matrix @var{A} using |
28 ## @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
|
29 ## |
22824 | 30 ## The optional input @var{t} specifies the number of test vectors (default 5). |
7189 | 31 ## |
22824 | 32 ## If the matrix is not explicit, e.g., when estimating the condition number of |
33 ## @var{A} given an LU@tie{}factorization, @code{condest} uses the following | |
34 ## functions: | |
7189 | 35 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
36 ## @itemize @minus |
22824 | 37 ## @item @var{Afcn} which must return |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
38 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
39 ## @itemize @bullet |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
40 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
41 ## the dimension @var{n} of @var{a}, if @var{flag} is @qcode{"dim"} |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
42 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
43 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
44 ## true if @var{a} is a real operator, if @var{flag} is @qcode{"real"} |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
45 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
46 ## @item |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
47 ## 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
|
48 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
49 ## @item |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
50 ## the result @code{@var{a}' * @var{x}}, if @var{flag} is "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
51 ## @end itemize |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
52 ## |
22824 | 53 ## @item @var{solvefun} which must return |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
54 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
55 ## @itemize @bullet |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
56 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
57 ## the dimension @var{n} of @var{a}, if @var{flag} is @qcode{"dim"} |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
58 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
59 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
60 ## true if @var{a} is a real operator, if @var{flag} is @qcode{"real"} |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
61 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
62 ## @item |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
63 ## 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
|
64 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
65 ## @item |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
66 ## the result @code{@var{a}' \ @var{x}}, if @var{flag} is "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
67 ## @end itemize |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
68 ## @end itemize |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
69 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
70 ## The parameters @var{p1}, @var{p2}, @dots{} are arguments of |
22824 | 71 ## @code{@var{Afcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})} |
72 ## and @code{@var{solvefcn} (@var{flag}, @var{x}, @var{p1}, @var{p2}, | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
73 ## @dots{})}. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
74 ## |
22824 | 75 ## The principal output is the 1-norm condition number estimate @var{cest}. |
7189 | 76 ## |
22824 | 77 ## The optional second output is an approximate null vector when @var{cest} is |
78 ## large; it satisfies the equation | |
79 ## @code{norm (A*v, 1) == norm (A, 1) * norm (@var{v}, 1) / @var{est}}. | |
80 ## | |
81 ## Algorithm Note: @code{condest} uses a randomized algorithm to approximate | |
82 ## the 1-norms. Therefore, if consistent results are required, the | |
83 ## @qcode{"state"} of the random generator should be fixed before invoking | |
84 ## @code{condest}. | |
7189 | 85 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
86 ## References: |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
14522
diff
changeset
|
87 ## |
7189 | 88 ## @itemize |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
90 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 91 ## for Matrix 1-Norm Estimation, with an Application to 1-Norm |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
92 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185-1201. |
7189 | 93 ## @url{http://dx.doi.org/10.1137/S0895479899356080} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
94 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 97 ## for Matrix 1-Norm Estimation, with an Application to 1-Norm |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
98 ## Pseudospectra}. @url{http://citeseer.ist.psu.edu/223007.html} |
7189 | 99 ## @end itemize |
100 ## | |
22824 | 101 ## @seealso{cond, norm, normest1, normest} |
7189 | 102 ## @end deftypefn |
103 | |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
104 ## Code originally licensed under: |
7189 | 105 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
106 ## 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
|
107 ## All rights reserved. |
7191 | 108 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
109 ## 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
|
110 ## 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
|
111 ## are met: |
7189 | 112 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
113 ## * 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
|
114 ## notice, this list of conditions and the following disclaimer. |
7191 | 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 ## * 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
|
117 ## 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
|
118 ## 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
|
119 ## with the distribution. |
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 ## * 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
|
122 ## 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
|
123 ## 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
|
124 ## written permission. |
7189 | 125 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
126 ## 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
|
127 ## 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
|
128 ## 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
|
129 ## 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
|
130 ## 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
|
131 ## 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
|
132 ## 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
|
133 ## 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
|
134 ## 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
|
135 ## 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
|
136 ## 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
|
137 ## SUCH DAMAGE. |
7189 | 138 |
139 ## Author: Jason Riedy <ejr@cs.berkeley.edu> | |
140 ## Keywords: linear-algebra norm estimation | |
141 ## Version: 0.2 | |
142 | |
22826 | 143 function [cest, v] = condest (varargin) |
7191 | 144 |
7309 | 145 if (nargin < 1 || nargin > 6) |
7191 | 146 print_usage (); |
7189 | 147 endif |
148 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
149 if ((nargin == 3 && is_function_handle (varargin{3})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
150 || (nargin == 4 && is_function_handle (varargin{3}) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
151 && isnumeric (varargin{4}))) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
152 ## onenormest syntax, deprecated in 4.2 |
22826 | 153 [cest, v] = condest_legacy (varargin{:}); |
154 return; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
155 elseif ((nargin >= 5) && is_function_handle (varargin{4})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
156 ## onenormest syntax, deprecated in 4.2 |
22826 | 157 [cest, v] = condest_legacy (varargin{:}); |
158 return; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
159 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
160 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
161 have_A = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
162 have_t = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
163 have_apply_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
164 have_solve_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
165 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
166 if (isnumeric (varargin{1})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
167 A = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
168 if (! issquare (A)) |
22826 | 169 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
|
170 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
171 n = rows (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
172 have_A = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
173 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
174 if (is_function_handle (varargin{2})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
175 solve = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
176 have_solve_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
177 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
178 t = varargin{3}; |
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 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
182 t = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
183 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
184 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
185 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
186 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
187 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
188 endif |
22826 | 189 else # varargin{1} is a function handle |
190 if (nargin == 1) | |
191 error("condest: must provide SOLVEFCN when using AFCN"); | |
192 endif | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
193 apply = varargin{1}; |
22826 | 194 have_apply_normest1 = true; |
195 solve = varargin{2}; | |
196 have_solve_normest1 = true; | |
197 n = apply ("dim", [], varargin{4:end}); | |
198 if (nargin > 2) | |
199 t = varargin{3}; | |
200 have_t = true; | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
201 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
202 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
203 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
204 if (! have_t) |
22826 | 205 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
|
206 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
207 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
208 if (! have_solve_normest1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
209 ## prepare solve in normest1 form |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
210 if (issparse (A)) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
211 [L, U, P, Pc] = lu (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
212 solve = @(flag, x) solve_sparse (flag, x, n, real_op, L, U, P, Pc); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
213 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
214 [L, U, P] = lu (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
215 solve = @(flag, x) solve_not_sparse (flag, x, n, real_op, L, U, P); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
216 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
217 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
218 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
219 if (have_A) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
220 Anorm = norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
221 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
222 Anorm = normest1 (apply, t, [], varargin{4:end}); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
223 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
224 [Ainv_norm, v, w] = normest1 (solve, t, [], varargin{4:end}); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
225 |
22826 | 226 cest = Anorm * Ainv_norm; |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
227 v = w / norm (w, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
228 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
229 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
230 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
231 function value = solve_sparse (flag, x, n, real_op, L , U , P , Pc) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
232 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
233 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
234 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
235 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
236 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
237 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
238 value = P' * (L' \ (U' \ (Pc * x))); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
239 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
240 value = Pc' * (U \ (L \ (P * x))); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
241 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
242 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
243 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
244 function value = solve_not_sparse (flag, x, n, real_op, L, U, P) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
245 switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
246 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
247 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
248 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
249 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
250 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
251 value = P' * (L' \ (U' \ x)); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
252 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
253 value = U \ (L \ (P * x)); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
254 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
255 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
256 |
22826 | 257 ## FIXME: remove after 4.4 |
258 function [cest, v] = condest_legacy (varargin) | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
259 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
260 persistent warned = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
261 if (! warned) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
262 warned = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
263 warning ("Octave:deprecated-function", |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
264 "condest: this syntax is deprecated, call condest (A, SOLVEFUN, T, P1, P2, ...) instead."); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
265 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
266 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
267 default_t = 5; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
268 |
7312 | 269 have_A = false; |
270 have_t = false; | |
271 have_solve = false; | |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
272 if (isnumeric (varargin{1})) |
7310 | 273 A = varargin{1}; |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
274 if (! issquare (A)) |
8664 | 275 error ("condest: matrix must be square"); |
7189 | 276 endif |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
277 n = rows (A); |
7312 | 278 have_A = true; |
7189 | 279 |
7312 | 280 if (nargin > 1) |
14522
f739e30494c8
condest.m: Fix failing %!test.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
281 if (! is_function_handle (varargin{2})) |
10549 | 282 t = varargin{2}; |
283 have_t = true; | |
7312 | 284 elseif (nargin > 2) |
10549 | 285 solve = varargin{2}; |
286 solve_t = varargin{3}; | |
287 have_solve = true; | |
288 if (nargin > 3) | |
289 t = varargin{4}; | |
290 have_t = true; | |
291 endif | |
7312 | 292 else |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11471
diff
changeset
|
293 error ("condest: must supply both SOLVE and SOLVE_T"); |
7189 | 294 endif |
295 endif | |
7311 | 296 elseif (nargin > 4) |
7189 | 297 apply = varargin{1}; |
298 apply_t = varargin{2}; | |
299 solve = varargin{3}; | |
300 solve_t = varargin{4}; | |
7312 | 301 have_solve = true; |
7189 | 302 n = varargin{5}; |
303 if (! isscalar (n)) | |
8664 | 304 error ("condest: dimension argument of implicit form must be scalar"); |
7189 | 305 endif |
7309 | 306 if (nargin > 5) |
7189 | 307 t = varargin{6}; |
7312 | 308 have_t = true; |
7189 | 309 endif |
7311 | 310 else |
8664 | 311 error ("condest: implicit form of condest requires at least 5 arguments"); |
7189 | 312 endif |
313 | |
7312 | 314 if (! have_t) |
7189 | 315 t = min (n, default_t); |
316 endif | |
317 | |
7312 | 318 if (! have_solve) |
7189 | 319 if (issparse (A)) |
8912 | 320 [L, U, P, Pc] = lu (A); |
7312 | 321 solve = @(x) Pc' * (U \ (L \ (P * x))); |
322 solve_t = @(x) P' * (L' \ (U' \ (Pc * x))); | |
7189 | 323 else |
324 [L, U, P] = lu (A); | |
7312 | 325 solve = @(x) U \ (L \ (P*x)); |
326 solve_t = @(x) P' * (L' \ (U' \ x)); | |
7189 | 327 endif |
328 endif | |
329 | |
22826 | 330 ## We already warned about this usage being deprecated. |
331 ## Don't warn again about onenormest. | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
332 warning ("off", "Octave:deprecated-function", "local"); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
333 |
7312 | 334 if (have_A) |
7189 | 335 Anorm = norm (A, 1); |
336 else | |
337 Anorm = onenormest (apply, apply_t, n, t); | |
338 endif | |
339 | |
340 [Ainv_norm, v, w] = onenormest (solve, solve_t, n, t); | |
341 | |
22826 | 342 cest = Anorm * Ainv_norm; |
7189 | 343 v = w / norm (w, 1); |
344 | |
345 endfunction | |
346 | |
22826 | 347 |
348 ## Note: These test bounds are very loose. There is enough randomization to | |
349 ## trigger odd cases with hilb(). | |
7189 | 350 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
351 %!function value = apply_fun (flag, x, A, m) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
352 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
353 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
354 %! endif |
22826 | 355 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
356 %! case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
357 %! value = length (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
358 %! case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
359 %! value = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
360 %! case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
361 %! value = x; for i = 1:m, value = A * value;, endfor |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
362 %! case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
363 %! value = x; for i = 1:m, value = A' * value;, endfor |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
364 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
365 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
366 %!function value = solve_fun (flag, x, A, m) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
367 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
368 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
369 %! endif |
22826 | 370 %! switch (flag) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
371 %! case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
372 %! value = length (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
373 %! case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
374 %! value = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
375 %! case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
376 %! value = x; for i = 1:m, value = A \ value;, endfor; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
377 %! case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
378 %! value = x; for i = 1:m, value = A' \ value;, endfor; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
379 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
380 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
381 |
7189 | 382 %!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
|
383 %! 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
|
384 %! 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
|
385 %! 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
|
386 %! 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
|
387 %! assert (cA, cA_test, -2^-8); |
7189 | 388 |
22826 | 389 %!test # to be removed after 4.4 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
390 %! warning ("off", "Octave:deprecated-function", "local"); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
391 %! 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
|
392 %! 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
|
393 %! solve = @(x) A\x; solve_t = @(x) A'\x; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
394 %! cA = condest (A, solve, solve_t); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
395 %! 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
|
396 %! assert (cA, cA_test, -2^-8); |
7189 | 397 |
22826 | 398 %!test # to be removed after 4.4 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
399 %! warning ("off", "Octave:deprecated-function", "local"); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
400 %! 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
|
401 %! 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
|
402 %! apply = @(x) A*x; apply_t = @(x) A'*x; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
403 %! solve = @(x) A\x; solve_t = @(x) A'\x; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
404 %! cA = condest (apply, apply_t, solve, solve_t, N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
405 %! 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
|
406 %! assert (cA, cA_test, -2^-6); |
7189 | 407 |
22826 | 408 %!test # to be removed after 4.4 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
409 %! warning ("off", "Octave:deprecated-function", "local"); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
410 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
411 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
412 %! apply = @(x) A*x; apply_t = @(x) A'*x; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
413 %! solve = @(x) A\x; solve_t = @(x) A'\x; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
414 %! cA = condest (apply, apply_t, solve, solve_t, N, 2); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
415 %! 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
|
416 %! 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
|
417 |
7189 | 418 %!test |
19670
e5facc6eec13
Silence warning messages in %!test code.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
419 %! warning ("off", "Octave:nearly-singular-matrix", "local"); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
420 %! 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
|
421 %! A = hilb (N); |
22826 | 422 %! [~, 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
|
423 %! x = A*v; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
424 %! 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
|
425 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
426 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
427 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
428 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
429 %! solve = @(flag, x) solve_fun (flag, x, A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
430 %! cA = condest (A, solve); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
431 %! 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
|
432 %! assert (cA, cA_test, -2^-6); |
22826 | 433 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
434 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
435 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
436 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
437 %! apply = @(flag, x) apply_fun (flag, x, A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
438 %! solve = @(flag, x) solve_fun (flag, x, A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
439 %! cA = condest (apply, solve); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
440 %! 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
|
441 %! 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
|
442 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
443 %!test # parameters for apply and solve functions |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
444 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
445 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
446 %! m = 2; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
447 %! cA = condest (@apply_fun, @solve_fun, [], A, m); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
448 %! 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
|
449 %! assert (cA, cA_test, -2^-6); |
22826 | 450 |
451 ## Test input validation | |
452 %!error condest () | |
453 %!error condest (1,2,3,4,5,6,7) | |
454 %!error <A must be square> condest ([1 2]) | |
455 %!error <must provide SOLVEFCN when using AFCN> condest (@sin) | |
456 |