Mercurial > octave
annotate scripts/linear-algebra/condest.m @ 22824:fb913df7babb stable
doc: Update docstring for condest.
* condest.m: Update docstring.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 24 Nov 2016 07:11:23 -0800 |
parents | bac0d6f07a3e |
children | c5f496b8352c c3d3a81ad986 |
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 | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
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 | |
143 function [est, v] = condest (varargin) | |
7191 | 144 |
7309 | 145 if (nargin < 1 || nargin > 6) |
7191 | 146 print_usage (); |
7189 | 147 endif |
148 | |
149 default_t = 5; | |
150 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
151 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
|
152 || (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
|
153 && isnumeric (varargin{4}))) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
154 ## onenormest syntax, deprecated in 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
155 [est, v] = condest_legacy (varargin{:}); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
156 return |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
157 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
|
158 ## onenormest syntax, deprecated in 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
159 [est, v] = condest_legacy (varargin{:}); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
160 return |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
161 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
162 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
163 have_A = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
164 have_t = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
165 have_apply_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
166 have_solve_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
167 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
168 if (isnumeric (varargin{1})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
169 A = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
170 if (! issquare (A)) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
171 error ("condest: matrix must be square"); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
172 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
173 n = rows (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
174 have_A = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
175 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
176 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
|
177 solve = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
178 have_solve_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
179 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
180 t = varargin{3}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
181 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
182 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
183 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
184 t = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
185 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
186 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
187 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
188 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
189 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
190 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
191 else # varargin{1} is function handle |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
192 apply = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
193 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
194 solve = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
195 have_apply_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
196 have_solve_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
197 n = apply ("dim", [], varargin{4:end}); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
198 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
199 t = varargin{3}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
200 have_t = true; |
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 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
203 error("condest: wrong number of input parameters"); |
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 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
206 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
207 if (! have_t) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
208 t = min (n, default_t); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
209 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
210 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
211 if (! have_solve_normest1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
212 ## 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
|
213 if (issparse (A)) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
214 [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
|
215 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
|
216 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
217 [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
|
218 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
|
219 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
220 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
221 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
222 if (have_A) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
223 Anorm = norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
224 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
225 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
|
226 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
227 [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
|
228 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
229 est = Anorm * Ainv_norm; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
230 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
|
231 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
232 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
233 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
234 function value = 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
|
235 switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
236 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
237 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
238 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
239 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
240 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
241 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
|
242 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
243 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
|
244 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
245 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
246 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
247 function value = 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
|
248 switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
249 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
250 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
251 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
252 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
253 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
254 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
|
255 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
256 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
|
257 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
258 endfunction |
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 function [est, v] = condest_legacy (varargin) # to be removed after 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
261 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
262 persistent warned = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
263 if (! warned) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
264 warned = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
265 warning ("Octave:deprecated-function", |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
266 "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
|
267 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
268 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
269 default_t = 5; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
270 |
7312 | 271 have_A = false; |
272 have_t = false; | |
273 have_solve = false; | |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
274 if (isnumeric (varargin{1})) |
7310 | 275 A = varargin{1}; |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
276 if (! issquare (A)) |
8664 | 277 error ("condest: matrix must be square"); |
7189 | 278 endif |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
279 n = rows (A); |
7312 | 280 have_A = true; |
7189 | 281 |
7312 | 282 if (nargin > 1) |
14522
f739e30494c8
condest.m: Fix failing %!test.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
283 if (! is_function_handle (varargin{2})) |
10549 | 284 t = varargin{2}; |
285 have_t = true; | |
7312 | 286 elseif (nargin > 2) |
10549 | 287 solve = varargin{2}; |
288 solve_t = varargin{3}; | |
289 have_solve = true; | |
290 if (nargin > 3) | |
291 t = varargin{4}; | |
292 have_t = true; | |
293 endif | |
7312 | 294 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
|
295 error ("condest: must supply both SOLVE and SOLVE_T"); |
7189 | 296 endif |
297 endif | |
7311 | 298 elseif (nargin > 4) |
7189 | 299 apply = varargin{1}; |
300 apply_t = varargin{2}; | |
301 solve = varargin{3}; | |
302 solve_t = varargin{4}; | |
7312 | 303 have_solve = true; |
7189 | 304 n = varargin{5}; |
305 if (! isscalar (n)) | |
8664 | 306 error ("condest: dimension argument of implicit form must be scalar"); |
7189 | 307 endif |
7309 | 308 if (nargin > 5) |
7189 | 309 t = varargin{6}; |
7312 | 310 have_t = true; |
7189 | 311 endif |
7311 | 312 else |
8664 | 313 error ("condest: implicit form of condest requires at least 5 arguments"); |
7189 | 314 endif |
315 | |
7312 | 316 if (! have_t) |
7189 | 317 t = min (n, default_t); |
318 endif | |
319 | |
7312 | 320 if (! have_solve) |
7189 | 321 if (issparse (A)) |
8912 | 322 [L, U, P, Pc] = lu (A); |
7312 | 323 solve = @(x) Pc' * (U \ (L \ (P * x))); |
324 solve_t = @(x) P' * (L' \ (U' \ (Pc * x))); | |
7189 | 325 else |
326 [L, U, P] = lu (A); | |
7312 | 327 solve = @(x) U \ (L \ (P*x)); |
328 solve_t = @(x) P' * (L' \ (U' \ x)); | |
7189 | 329 endif |
330 endif | |
331 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
332 ## We already warned about this usage being deprecated. Don't |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
333 ## warn again about onenormest. |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
334 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
|
335 |
7312 | 336 if (have_A) |
7189 | 337 Anorm = norm (A, 1); |
338 else | |
339 Anorm = onenormest (apply, apply_t, n, t); | |
340 endif | |
341 | |
342 [Ainv_norm, v, w] = onenormest (solve, solve_t, n, t); | |
343 | |
344 est = Anorm * Ainv_norm; | |
345 v = w / norm (w, 1); | |
346 | |
347 endfunction | |
348 | |
349 ## Yes, these test bounds are really loose. There's | |
350 ## enough randomization to trigger odd cases with hilb(). | |
351 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
352 %!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
|
353 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
354 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
355 %! endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
356 %! switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
357 %! case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
358 %! value = length (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
359 %! case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
360 %! value = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
361 %! case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
362 %! 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
|
363 %! case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
364 %! 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
|
365 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
366 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
367 %!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
|
368 %! if (nargin == 3) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
369 %! m = 1; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
370 %! endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
371 %! switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
372 %! case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
373 %! value = length (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
374 %! case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
375 %! value = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
376 %! case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
377 %! 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
|
378 %! case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
379 %! 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
|
380 %! endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
381 %!endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
382 |
7189 | 383 %!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
|
384 %! 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
|
385 %! 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
|
386 %! 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
|
387 %! 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
|
388 %! assert (cA, cA_test, -2^-8); |
7189 | 389 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
390 %!test # to be removed after 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
391 %! 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
|
392 %! 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
|
393 %! 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
|
394 %! 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
|
395 %! 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
|
396 %! 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
|
397 %! assert (cA, cA_test, -2^-8); |
7189 | 398 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
399 %!test # to be removed after 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
400 %! 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
|
401 %! 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
|
402 %! 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
|
403 %! 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
|
404 %! 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
|
405 %! 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
|
406 %! 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
|
407 %! assert (cA, cA_test, -2^-6); |
7189 | 408 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
409 %!test # to be removed after 4.2 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
410 %! 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
|
411 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
412 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
413 %! 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
|
414 %! 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
|
415 %! 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
|
416 %! 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
|
417 %! 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
|
418 |
7189 | 419 %!test |
19670
e5facc6eec13
Silence warning messages in %!test code.
Rik <rik@octave.org>
parents:
19040
diff
changeset
|
420 %! 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
|
421 %! 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
|
422 %! 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
|
423 %! [rcondA, v] = 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
|
424 %! x = A*v; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
425 %! 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
|
426 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
427 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
428 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
429 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
430 %! 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
|
431 %! cA = condest (A, solve); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
432 %! 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
|
433 %! 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
|
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); |