Mercurial > octave
annotate scripts/linear-algebra/condest.m @ 22323:bac0d6f07a3e
maint: Update copyright notices for 2016.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 01:05:19 -0400 |
parents | 9fc91bb2aec3 |
children | 3a2b891d0b33 fb913df7babb |
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 -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
21 ## @deftypefn {} {} condest (@var{A}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
22 ## @deftypefnx {} {} condest (@var{A}, @var{t}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
23 ## @deftypefnx {} {[@var{est}, @var{v}] =} condest (@dots{}) |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
24 ## @deftypefnx {} {[@var{est}, @var{v}] =} condest (@var{A}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
25 ## @deftypefnx {} {[@var{est}, @var{v}] =} condest (@var{afun}, @var{solvefun}, @var{t}, @var{p1}, @var{p2}, @dots{}) |
7189 | 26 ## |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
27 ## Estimate the 1-norm condition number of a matrix @var{A} using @var{t} test |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
28 ## vectors using a randomized 1-norm estimator. |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
29 ## |
7189 | 30 ## If @var{t} exceeds 5, then only 5 test vectors are used. |
31 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
32 ## If the matrix is not explicit, e.g., when estimating the condition |
11593
1577c6f80926
Use non-breaking spaces between certain adjectives and their nouns in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
33 ## number of @var{A} given an LU@tie{}factorization, @code{condest} uses the |
7189 | 34 ## following functions: |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
37 ## @item @var{afun} which should returns |
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 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
53 ## @item @var{solvefun} which should returns |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
71 ## @code{@var{afun} (@var{flag}, @var{x}, @var{p1}, @var{p2}, @dots{})} |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
72 ## and @code{@var{solvefun} (@var{flag}, @var{x}, @var{p1}, @var{p2}, |
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 ## |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
75 ## @code{condest} uses a randomized algorithm to approximate the |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
76 ## 1-norms. Therefore, if consistent results are required, the |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
77 ## @qcode{"state"} of the random generator should be fixed before invoking |
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22183
diff
changeset
|
78 ## @code{normest1}. |
7189 | 79 ## |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
80 ## @code{condest} returns the 1-norm condition estimate @var{est} and a vector |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
81 ## @var{v} satisfying @code{norm (A*v, 1) == norm (A, 1) * norm |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
82 ## (@var{v}, 1) / @var{est}}. When @var{est} is large, @var{v} is an |
7191 | 83 ## approximate null vector. |
7189 | 84 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 ## References: |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
14522
diff
changeset
|
86 ## |
7189 | 87 ## @itemize |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 90 ## 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
|
91 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185-1201. |
7189 | 92 ## @url{http://dx.doi.org/10.1137/S0895479899356080} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
93 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 ## @item |
19040
0850b5212619
doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
95 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm |
7189 | 96 ## 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
|
97 ## Pseudospectra}. @url{http://citeseer.ist.psu.edu/223007.html} |
7189 | 98 ## @end itemize |
99 ## | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
100 ## @seealso{cond, norm, normest1} |
7189 | 101 ## @end deftypefn |
102 | |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
103 ## Code originally licensed under: |
7189 | 104 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
105 ## 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
|
106 ## All rights reserved. |
7191 | 107 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
108 ## 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
|
109 ## 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
|
110 ## are met: |
7189 | 111 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
112 ## * 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
|
113 ## notice, this list of conditions and the following disclaimer. |
7191 | 114 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
115 ## * 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
|
116 ## 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
|
117 ## 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
|
118 ## with the distribution. |
7191 | 119 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
120 ## * 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
|
121 ## 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
|
122 ## 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
|
123 ## written permission. |
7189 | 124 ## |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
125 ## 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
|
126 ## 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
|
127 ## 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
|
128 ## 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
|
129 ## 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
|
130 ## 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
|
131 ## 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
|
132 ## 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
|
133 ## 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
|
134 ## 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
|
135 ## 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
|
136 ## SUCH DAMAGE. |
7189 | 137 |
138 ## Author: Jason Riedy <ejr@cs.berkeley.edu> | |
139 ## Keywords: linear-algebra norm estimation | |
140 ## Version: 0.2 | |
141 | |
142 function [est, v] = condest (varargin) | |
7191 | 143 |
7309 | 144 if (nargin < 1 || nargin > 6) |
7191 | 145 print_usage (); |
7189 | 146 endif |
147 | |
148 default_t = 5; | |
149 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
150 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
|
151 || (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
|
152 && isnumeric (varargin{4}))) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
153 ## 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
|
154 [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
|
155 return |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
156 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
|
157 ## 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
|
158 [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
|
159 return |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
160 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
161 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
162 have_A = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
163 have_t = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
164 have_apply_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
165 have_solve_normest1 = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
166 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
167 if (isnumeric (varargin{1})) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
168 A = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
169 if (! issquare (A)) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
170 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
|
171 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
172 n = rows (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
173 have_A = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
174 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
175 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
|
176 solve = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
177 have_solve_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
178 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
179 t = varargin{3}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
180 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
181 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
182 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
183 t = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
184 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
185 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
186 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
187 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
188 real_op = isreal (A); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
189 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
190 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
|
191 apply = varargin{1}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
192 if (nargin > 1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
193 solve = varargin{2}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
194 have_apply_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
195 have_solve_normest1 = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
196 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
|
197 if (nargin > 2) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
198 t = varargin{3}; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
199 have_t = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
200 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
201 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
202 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
|
203 endif |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
206 if (! have_t) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
207 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
|
208 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
209 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
210 if (! have_solve_normest1) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
211 ## 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
|
212 if (issparse (A)) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
213 [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
|
214 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
|
215 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
216 [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
|
217 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
|
218 endif |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
221 if (have_A) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
222 Anorm = norm (A, 1); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
223 else |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
224 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
|
225 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
226 [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
|
227 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
228 est = Anorm * Ainv_norm; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
229 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
|
230 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
231 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
232 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
233 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
|
234 switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
235 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
236 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
237 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
238 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
239 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
240 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
|
241 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
242 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
|
243 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
244 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
245 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
246 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
|
247 switch flag |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
248 case "dim" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
249 value = n; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
250 case "real" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
251 value = real_op; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
252 case "notransp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
253 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
|
254 case "transp" |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
255 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
|
256 endswitch |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
257 endfunction |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
258 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
259 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
|
260 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
261 persistent warned = false; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
262 if (! warned) |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
263 warned = true; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
264 warning ("Octave:deprecated-function", |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
265 "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
|
266 endif |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
267 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
268 default_t = 5; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
269 |
7312 | 270 have_A = false; |
271 have_t = false; | |
272 have_solve = false; | |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
273 if (isnumeric (varargin{1})) |
7310 | 274 A = varargin{1}; |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
275 if (! issquare (A)) |
8664 | 276 error ("condest: matrix must be square"); |
7189 | 277 endif |
9872
72d6e0de76c7
fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents:
9307
diff
changeset
|
278 n = rows (A); |
7312 | 279 have_A = true; |
7189 | 280 |
7312 | 281 if (nargin > 1) |
14522
f739e30494c8
condest.m: Fix failing %!test.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
282 if (! is_function_handle (varargin{2})) |
10549 | 283 t = varargin{2}; |
284 have_t = true; | |
7312 | 285 elseif (nargin > 2) |
10549 | 286 solve = varargin{2}; |
287 solve_t = varargin{3}; | |
288 have_solve = true; | |
289 if (nargin > 3) | |
290 t = varargin{4}; | |
291 have_t = true; | |
292 endif | |
7312 | 293 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
|
294 error ("condest: must supply both SOLVE and SOLVE_T"); |
7189 | 295 endif |
296 endif | |
7311 | 297 elseif (nargin > 4) |
7189 | 298 apply = varargin{1}; |
299 apply_t = varargin{2}; | |
300 solve = varargin{3}; | |
301 solve_t = varargin{4}; | |
7312 | 302 have_solve = true; |
7189 | 303 n = varargin{5}; |
304 if (! isscalar (n)) | |
8664 | 305 error ("condest: dimension argument of implicit form must be scalar"); |
7189 | 306 endif |
7309 | 307 if (nargin > 5) |
7189 | 308 t = varargin{6}; |
7312 | 309 have_t = true; |
7189 | 310 endif |
7311 | 311 else |
8664 | 312 error ("condest: implicit form of condest requires at least 5 arguments"); |
7189 | 313 endif |
314 | |
7312 | 315 if (! have_t) |
7189 | 316 t = min (n, default_t); |
317 endif | |
318 | |
7312 | 319 if (! have_solve) |
7189 | 320 if (issparse (A)) |
8912 | 321 [L, U, P, Pc] = lu (A); |
7312 | 322 solve = @(x) Pc' * (U \ (L \ (P * x))); |
323 solve_t = @(x) P' * (L' \ (U' \ (Pc * x))); | |
7189 | 324 else |
325 [L, U, P] = lu (A); | |
7312 | 326 solve = @(x) U \ (L \ (P*x)); |
327 solve_t = @(x) P' * (L' \ (U' \ x)); | |
7189 | 328 endif |
329 endif | |
330 | |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
331 ## 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
|
332 ## warn again about onenormest. |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
333 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
|
334 |
7312 | 335 if (have_A) |
7189 | 336 Anorm = norm (A, 1); |
337 else | |
338 Anorm = onenormest (apply, apply_t, n, t); | |
339 endif | |
340 | |
341 [Ainv_norm, v, w] = onenormest (solve, solve_t, n, t); | |
342 | |
343 est = Anorm * Ainv_norm; | |
344 v = w / norm (w, 1); | |
345 | |
346 endfunction | |
347 | |
348 ## Yes, these test bounds are really loose. There's | |
349 ## enough randomization to trigger odd cases with hilb(). | |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
355 %! switch flag |
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 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
370 %! switch flag |
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 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
389 %!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
|
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 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
398 %!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
|
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 |
22183
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
408 %!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
|
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); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
422 %! [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
|
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); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
433 %!test |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
434 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
435 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
436 %! 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
|
437 %! 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
|
438 %! cA = condest (apply, solve); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
439 %! 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
|
440 %! 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
|
441 |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
442 %!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
|
443 %! N = 6; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
444 %! A = hilb (N); |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
445 %! m = 2; |
bfb1b089c230
New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents:
20852
diff
changeset
|
446 %! 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
|
447 %! 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
|
448 %! assert (cA, cA_test, -2^-6); |