annotate scripts/linear-algebra/condest.m @ 22183:bfb1b089c230

New function normest1 as replacement for onenormest (patch #8837) * scripts/linear-algebra/normest1.m: new function to replace onenormest so it's Matlab compatible. It works as a drop-in replacement when input is a matrix. Usage with functions as input is no longer supported as it is only a little useful. * scripts/linear-algebra/onenormest.m: moved to deprecated/. * scripts/linear-algebra/module.mk: add normest1, remove onenormest. * scripts/linear-algebra/condest.m: add normest1 syntax. It still accepts onenormest syntax but marked as deprecated. * scripts/deprecated/onenormest.m: moved from linear-algebra/, added deprecation warning. * scripts/deprecated/module.mk: add onenormest. * NEWS: Added normest1 to the list of new functions, made onenormest deprecated. * doc/interpreter/sparse.txi: replace onenormest with normest1.
author Marco Caliari <marco.caliari@univr.it>
date Mon, 25 Jul 2016 14:50:29 +0100
parents 516bb87ea72e
children 9fc91bb2aec3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19670
diff changeset
1 ## Copyright (C) 2007-2015 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
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
3 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
4 ## This file is part of Octave.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
5 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
9 ## your option) any later version.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
10 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
14 ## General Public License for more details.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
15 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
18 ## <http://www.gnu.org/licenses/>.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
19
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
30 ## If @var{t} exceeds 5, then only 5 test vectors are used.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
34 ## following functions:
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
38 ## @itemize @bullet
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
39 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
40 ## the dimension @var{n} of @var{a}, if @var{flag} is "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
41 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
42 ## true if @var{a} is a real operator, if @var{flag} is "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
43 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
44 ## the result @code{@var{a} * @var{x}}, if @var{flag} is "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
45 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
46 ## 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
47 ## @end itemize
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
48 ## @item @var{solvefun} which should returns
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
49 ## @itemize @bullet
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
50 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
51 ## the dimension @var{n} of @var{a}, if @var{flag} is "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
52 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
53 ## true if @var{a} is a real operator, if @var{flag} is "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
54 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
55 ## the result @code{@var{a} \ @var{x}}, if @var{flag} is "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
56 ## @item
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
57 ## 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
58 ## @end itemize
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
59 ## @end itemize
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
60 ##
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
61 ## 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
62 ## @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
63 ## 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
64 ## @dots{})}.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
65 ##
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
66 ## @code{condest} uses a randomized algorithm to approximate the
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
67 ## 1-norms. Therefore, if consistent results are required, the "state" of the
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
68 ## random generator should be fixed before invoking @code{normest1}.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
69 ##
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19700
diff changeset
70 ## @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
71 ## @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
72 ## (@var{v}, 1) / @var{est}}. When @var{est} is large, @var{v} is an
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
73 ## approximate null vector.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
74 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
75 ## References:
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 14522
diff changeset
76 ##
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
77 ## @itemize
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
78 ## @item
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
79 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
80 ## 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
81 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185-1201.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
82 ## @url{http://dx.doi.org/10.1137/S0895479899356080}
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
83 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
84 ## @item
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
85 ## @nospell{N.J. Higham and F. Tisseur}, @cite{A Block Algorithm
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
86 ## 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
87 ## Pseudospectra}. @url{http://citeseer.ist.psu.edu/223007.html}
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
88 ## @end itemize
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
89 ##
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
90 ## @seealso{cond, norm, normest1}
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
91 ## @end deftypefn
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
92
20194
b0f7ee81d974 doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents: 20160
diff changeset
93 ## Code originally licensed under:
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
94 ##
20194
b0f7ee81d974 doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents: 20160
diff changeset
95 ## 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
96 ## All rights reserved.
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
97 ##
20194
b0f7ee81d974 doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents: 20160
diff changeset
98 ## 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
99 ## 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
100 ## are met:
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
101 ##
20194
b0f7ee81d974 doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents: 20160
diff changeset
102 ## * 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
103 ## notice, this list of conditions and the following disclaimer.
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
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 ## * 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
106 ## 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
107 ## 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
108 ## with the distribution.
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
109 ##
20194
b0f7ee81d974 doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents: 20160
diff changeset
110 ## * 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
111 ## 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
112 ## 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
113 ## written permission.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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 ## 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
116 ## 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
117 ## 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
118 ## 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
119 ## 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
120 ## 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
121 ## 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
122 ## 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
123 ## 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
124 ## 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
125 ## 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
126 ## SUCH DAMAGE.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
127
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
128 ## Author: Jason Riedy <ejr@cs.berkeley.edu>
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
129 ## Keywords: linear-algebra norm estimation
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
130 ## Version: 0.2
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
131
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
132 function [est, v] = condest (varargin)
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
133
7309
26f42a14d4f6 [project @ 2007-12-12 22:05:38 by jwe]
jwe
parents: 7239
diff changeset
134 if (nargin < 1 || nargin > 6)
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
135 print_usage ();
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
136 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
137
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
138 default_t = 5;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
139
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
140 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
141 || (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
142 && isnumeric (varargin{4})))
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
143 ## 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
144 [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
145 return
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
146 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
147 ## 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
148 [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
149 return
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
150 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
151
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
152 have_A = false;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
153 have_t = false;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
154 have_apply_normest1 = false;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
155 have_solve_normest1 = false;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
156
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
157 if (isnumeric (varargin{1}))
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
158 A = varargin{1};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
159 if (! issquare (A))
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
160 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
161 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
162 n = rows (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
163 have_A = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
164 if (nargin > 1)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
165 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
166 solve = varargin{2};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
167 have_solve_normest1 = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
168 if (nargin > 2)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
169 t = varargin{3};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
170 have_t = true;
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 else
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
173 t = varargin{2};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
174 have_t = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
175 real_op = isreal (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
176 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
177 else
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
178 real_op = isreal (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
179 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
180 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
181 apply = varargin{1};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
182 if (nargin > 1)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
183 solve = varargin{2};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
184 have_apply_normest1 = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
185 have_solve_normest1 = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
186 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
187 if (nargin > 2)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
188 t = varargin{3};
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
189 have_t = true;
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
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
192 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
193 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
194 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
195
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
196 if (! have_t)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
197 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
198 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
199
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
200 if (! have_solve_normest1)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
201 ## 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
202 if (issparse (A))
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
203 [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
204 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
205 else
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
206 [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
207 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
208 endif
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_A)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
212 Anorm = norm (A, 1);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
213 else
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
214 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
215 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
216 [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
217
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
218 est = Anorm * Ainv_norm;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
219 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
220
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
221 endfunction
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
222
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
223 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
224 switch flag
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
225 case "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
226 value = n;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
227 case "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
228 value = real_op;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
229 case "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
230 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
231 case "transp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
232 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
233 endswitch
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
234 endfunction
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
235
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
236 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
237 switch flag
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
238 case "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
239 value = n;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
240 case "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
241 value = real_op;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
242 case "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
243 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
244 case "transp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
245 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
246 endswitch
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
247 endfunction
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
248
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
249 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
250
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
251 persistent warned = false;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
252 if (! warned)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
253 warned = true;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
254 warning ("Octave:deprecated-function",
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
255 "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
256 endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
257
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
258 default_t = 5;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
259
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
260 have_A = false;
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
261 have_t = false;
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
262 have_solve = false;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
263 if (isnumeric (varargin{1}))
7310
dc9b00ab5aac [project @ 2007-12-12 22:08:58 by jwe]
jwe
parents: 7309
diff changeset
264 A = varargin{1};
9872
72d6e0de76c7 fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
265 if (! issquare (A))
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8347
diff changeset
266 error ("condest: matrix must be square");
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
267 endif
9872
72d6e0de76c7 fix qp, condest and krylov
Jaroslav Hajek <highegg@gmail.com>
parents: 9307
diff changeset
268 n = rows (A);
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
269 have_A = true;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
270
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
271 if (nargin > 1)
14522
f739e30494c8 condest.m: Fix failing %!test.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
272 if (! is_function_handle (varargin{2}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
273 t = varargin{2};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
274 have_t = true;
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
275 elseif (nargin > 2)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
276 solve = varargin{2};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
277 solve_t = varargin{3};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
278 have_solve = true;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
279 if (nargin > 3)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
280 t = varargin{4};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
281 have_t = true;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9872
diff changeset
282 endif
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
283 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
284 error ("condest: must supply both SOLVE and SOLVE_T");
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
285 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
286 endif
7311
1b535aed87e2 [project @ 2007-12-12 22:13:43 by jwe]
jwe
parents: 7310
diff changeset
287 elseif (nargin > 4)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
288 apply = varargin{1};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
289 apply_t = varargin{2};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
290 solve = varargin{3};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
291 solve_t = varargin{4};
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
292 have_solve = true;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
293 n = varargin{5};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
294 if (! isscalar (n))
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8347
diff changeset
295 error ("condest: dimension argument of implicit form must be scalar");
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
296 endif
7309
26f42a14d4f6 [project @ 2007-12-12 22:05:38 by jwe]
jwe
parents: 7239
diff changeset
297 if (nargin > 5)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
298 t = varargin{6};
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
299 have_t = true;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
300 endif
7311
1b535aed87e2 [project @ 2007-12-12 22:13:43 by jwe]
jwe
parents: 7310
diff changeset
301 else
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8347
diff changeset
302 error ("condest: implicit form of condest requires at least 5 arguments");
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
303 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
304
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
305 if (! have_t)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
306 t = min (n, default_t);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
307 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
308
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
309 if (! have_solve)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
310 if (issparse (A))
8912
57c3155754d6 fix condest
Jaroslav Hajek <highegg@gmail.com>
parents: 8664
diff changeset
311 [L, U, P, Pc] = lu (A);
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
312 solve = @(x) Pc' * (U \ (L \ (P * x)));
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
313 solve_t = @(x) P' * (L' \ (U' \ (Pc * x)));
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
314 else
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
315 [L, U, P] = lu (A);
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
316 solve = @(x) U \ (L \ (P*x));
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
317 solve_t = @(x) P' * (L' \ (U' \ x));
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
318 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
319 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
320
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
321 ## 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
322 ## warn again about onenormest.
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
323 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
324
7312
1ebbf0924217 [project @ 2007-12-12 22:19:54 by jwe]
jwe
parents: 7311
diff changeset
325 if (have_A)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
326 Anorm = norm (A, 1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
327 else
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
328 Anorm = onenormest (apply, apply_t, n, t);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
329 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
330
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
331 [Ainv_norm, v, w] = onenormest (solve, solve_t, n, t);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
332
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
333 est = Anorm * Ainv_norm;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
334 v = w / norm (w, 1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
335
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
336 endfunction
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
337
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
338 ## Yes, these test bounds are really loose. There's
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
339 ## enough randomization to trigger odd cases with hilb().
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
340
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
341 %!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
342 %! if (nargin == 3)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
343 %! m = 1;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
344 %! endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
345 %! switch flag
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
346 %! case "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
347 %! value = length (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
348 %! case "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
349 %! value = isreal (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
350 %! case "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
351 %! 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
352 %! case "transp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
353 %! 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
354 %! endswitch
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
355 %!endfunction
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
356 %!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
357 %! if (nargin == 3)
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
358 %! m = 1;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
359 %! endif
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
360 %! switch flag
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
361 %! case "dim"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
362 %! value = length (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
363 %! case "real"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
364 %! value = isreal (A);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
365 %! case "notransp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
366 %! 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
367 %! case "transp"
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
368 %! 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
369 %! endswitch
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
370 %!endfunction
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
371
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
372 %!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
373 %! 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
374 %! 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
375 %! 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
376 %! 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
377 %! assert (cA, cA_test, -2^-8);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
378
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
379 %!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
380 %! 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
381 %! 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
382 %! 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
383 %! 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
384 %! 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
385 %! 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
386 %! assert (cA, cA_test, -2^-8);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
387
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
388 %!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
389 %! 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
390 %! 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
391 %! 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
392 %! 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
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 (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
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^-6);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
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");
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
400 %! N = 6;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
401 %! A = hilb (N);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
402 %! 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
403 %! 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
404 %! 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
405 %! 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
406 %! 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
407
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
408 %!test
19670
e5facc6eec13 Silence warning messages in %!test code.
Rik <rik@octave.org>
parents: 19040
diff changeset
409 %! 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
410 %! 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
411 %! 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
412 %! [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
413 %! x = A*v;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
414 %! 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
415
22183
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
416 %!test
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
417 %! N = 6;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
418 %! A = hilb (N);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
419 %! 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
420 %! cA = condest (A, solve);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
421 %! 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
422 %! 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
423 %!test
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
424 %! N = 6;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
425 %! A = hilb (N);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
426 %! 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
427 %! 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
428 %! cA = condest (apply, solve);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
429 %! 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
430 %! 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
431
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
432 %!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
433 %! N = 6;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
434 %! A = hilb (N);
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
435 %! m = 2;
bfb1b089c230 New function normest1 as replacement for onenormest (patch #8837)
Marco Caliari <marco.caliari@univr.it>
parents: 20852
diff changeset
436 %! 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
437 %! 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
438 %! assert (cA, cA_test, -2^-6);