Mercurial > hg > octave-lyh
annotate scripts/linear-algebra/onenormest.m @ 17526:05bed3576091
Fix int16 type comments
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 04:18:59 +0800 |
parents | 12005245b645 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13747
diff
changeset
|
1 ## Copyright (C) 2007-2012 Regents of the University of California |
7189 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{est}, @var{v}, @var{w}, @var{iter}] =} onenormest (@var{A}, @var{t}) |
7189 | 21 ## @deftypefnx {Function File} {[@var{est}, @var{v}, @var{w}, @var{iter}] =} onenormest (@var{apply}, @var{apply_t}, @var{n}, @var{t}) |
22 ## | |
23 ## Apply Higham and Tisseur's randomized block 1-norm estimator to | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
24 ## matrix @var{A} using @var{t} test vectors. If @var{t} exceeds 5, then |
7189 | 25 ## only 5 test vectors are used. |
26 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## If the matrix is not explicit, e.g., when estimating the norm of |
12344
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11593
diff
changeset
|
28 ## @code{inv (@var{A})} given an LU@tie{}factorization, @code{onenormest} |
68ac95d2460c
Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11593
diff
changeset
|
29 ## applies @var{A} and its conjugate transpose through a pair of functions |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## @var{apply} and @var{apply_t}, respectively, to a dense matrix of size |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## @var{n} by @var{t}. The implicit version requires an explicit dimension |
7189 | 32 ## @var{n}. |
33 ## | |
34 ## Returns the norm estimate @var{est}, two vectors @var{v} and | |
35 ## @var{w} related by norm | |
36 ## @code{(@var{w}, 1) = @var{est} * norm (@var{v}, 1)}, | |
37 ## and the number of iterations @var{iter}. The number of | |
38 ## iterations is limited to 10 and is at least 2. | |
39 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
40 ## References: |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
14502
diff
changeset
|
41 ## |
7189 | 42 ## @itemize |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 ## @item |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
44 ## N.J. Higham and F. Tisseur, @cite{A Block Algorithm |
7189 | 45 ## 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:
10549
diff
changeset
|
46 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185-1201. |
7189 | 47 ## @url{http://dx.doi.org/10.1137/S0895479899356080} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
48 ## |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
49 ## @item |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
50 ## N.J. Higham and F. Tisseur, @cite{A Block Algorithm |
7189 | 51 ## 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:
10549
diff
changeset
|
52 ## Pseudospectra}. @url{http://citeseer.ist.psu.edu/223007.html} |
7189 | 53 ## @end itemize |
54 ## | |
55 ## @seealso{condest, norm, cond} | |
56 ## @end deftypefn | |
57 | |
58 ## Code originally licensed under | |
59 ## | |
60 ## Copyright (c) 2007, Regents of the University of California | |
61 ## All rights reserved. | |
7191 | 62 ## |
7189 | 63 ## Redistribution and use in source and binary forms, with or without |
7191 | 64 ## modification, are permitted provided that the following conditions |
65 ## are met: | |
7189 | 66 ## |
67 ## * Redistributions of source code must retain the above copyright | |
68 ## notice, this list of conditions and the following disclaimer. | |
7191 | 69 ## |
70 ## * Redistributions in binary form must reproduce the above | |
71 ## copyright notice, this list of conditions and the following | |
72 ## disclaimer in the documentation and/or other materials provided | |
73 ## with the distribution. | |
74 ## | |
75 ## * Neither the name of the University of California, Berkeley nor | |
76 ## the names of its contributors may be used to endorse or promote | |
77 ## products derived from this software without specific prior | |
78 ## written permission. | |
7189 | 79 ## |
7191 | 80 ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' |
81 ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
82 ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
83 ## PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND | |
84 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
85 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
86 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
87 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
88 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
89 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
90 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
7189 | 91 ## SUCH DAMAGE. |
92 | |
93 ## Author: Jason Riedy <ejr@cs.berkeley.edu> | |
94 ## Keywords: linear-algebra norm estimation | |
95 ## Version: 0.2 | |
96 | |
97 function [est, v, w, iter] = onenormest (varargin) | |
98 | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
99 if (nargin < 1 || nargin > 4) |
7189 | 100 print_usage (); |
101 endif | |
102 | |
103 default_t = 5; | |
104 itmax = 10; | |
105 | |
106 if (ismatrix (varargin{1})) | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
107 [n, nc] = size (varargin{1}); |
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
108 if (n != nc) |
8664 | 109 error ("onenormest: matrix must be square"); |
7189 | 110 endif |
111 apply = @(x) varargin{1} * x; | |
112 apply_t = @(x) varargin{1}' * x; | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
113 if (nargin > 1) |
7189 | 114 t = varargin{2}; |
115 else | |
116 t = min (n, default_t); | |
117 endif | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
118 issing = isa (varargin{1}, "single"); |
7189 | 119 else |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
120 if (nargin < 3) |
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
121 print_usage (); |
7189 | 122 endif |
123 apply = varargin{1}; | |
124 apply_t = varargin{2}; | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
125 n = varargin{3}; |
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
126 if (nargin > 3) |
7189 | 127 t = varargin{4}; |
128 else | |
129 t = default_t; | |
130 endif | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
131 issing = isa (n, "single"); |
7189 | 132 endif |
133 | |
134 ## Initial test vectors X. | |
135 X = rand (n, t); | |
136 X = X ./ (ones (n,1) * sum (abs (X), 1)); | |
137 | |
8506 | 138 ## Track if a vertex has been visited. |
139 been_there = zeros (n, 1); | |
140 | |
141 ## To check if the estimate has increased. | |
142 est_old = 0; | |
143 | |
144 ## Normalized vector of signs. | |
145 S = zeros (n, t); | |
7189 | 146 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
147 if (issing) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
148 myeps = eps ("single"); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
149 X = single (X); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
150 else |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
151 myeps = eps; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
152 endif |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
153 |
7189 | 154 for iter = 1 : itmax + 1 |
155 Y = feval (apply, X); | |
156 | |
157 ## Find the initial estimate as the largest A*x. | |
158 [est, ind_best] = max (sum (abs (Y), 1)); | |
159 if (est > est_old || iter == 2) | |
160 w = Y(:,ind_best); | |
161 endif | |
162 if (iter >= 2 && est < est_old) | |
163 ## No improvement, so stop. | |
164 est = est_old; | |
165 break; | |
166 endif | |
167 | |
168 est_old = est; | |
169 S_old = S; | |
170 if (iter > itmax), | |
171 ## Gone too far. Stop. | |
172 break; | |
173 endif | |
174 | |
175 S = sign (Y); | |
176 | |
177 ## Test if any of S are approximately parallel to previous S | |
178 ## vectors or current S vectors. If everything is parallel, | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
179 ## stop. Otherwise, replace any parallel vectors with |
7189 | 180 ## rand{-1,+1}. |
181 partest = any (abs (S_old' * S - n) < 4*eps*n); | |
182 if (all (partest)) | |
183 ## All the current vectors are parallel to old vectors. | |
184 ## We've hit a cycle, so stop. | |
185 break; | |
186 endif | |
187 if (any (partest)) | |
188 ## Some vectors are parallel to old ones and are cycling, | |
189 ## but not all of them. Replace the parallel vectors with | |
190 ## rand{-1,+1}. | |
191 numpar = sum (partest); | |
192 replacements = 2*(rand (n,numpar) < 0.5) - 1; | |
193 S(:,partest) = replacements; | |
194 endif | |
195 ## Now test for parallel vectors within S. | |
8507 | 196 partest = any ((S' * S - eye (t)) == n); |
7189 | 197 if (any (partest)) |
198 numpar = sum (partest); | |
199 replacements = 2*(rand (n,numpar) < 0.5) - 1; | |
200 S(:,partest) = replacements; | |
201 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
202 |
7189 | 203 Z = feval (apply_t, S); |
204 | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
205 ## Now find the largest non-previously-visted index per vector. |
7189 | 206 h = max (abs (Z),2); |
207 [mh, mhi] = max (h); | |
208 if (iter >= 2 && mhi == ind_best) | |
209 ## Hit a cycle, stop. | |
210 break; | |
211 endif | |
212 [h, ind] = sort (h, 'descend'); | |
213 if (t > 1) | |
214 firstind = ind(1:t); | |
215 if (all (been_there(firstind))) | |
10549 | 216 ## Visited all these before, so stop. |
217 break; | |
7189 | 218 endif |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
219 ind = ind(! been_there(ind)); |
7189 | 220 if (length (ind) < t) |
10549 | 221 ## There aren't enough new vectors, so we're practically |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
222 ## in a cycle. Stop. |
10549 | 223 break; |
7189 | 224 endif |
225 endif | |
226 | |
227 ## Visit the new indices. | |
228 X = zeros (n, t); | |
229 for zz = 1 : t | |
230 X(ind(zz),zz) = 1; | |
231 endfor | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
232 been_there(ind(1 : t)) = 1; |
7189 | 233 endfor |
234 | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
235 ## The estimate est and vector w are set in the loop above. |
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
236 ## The vector v selects the ind_best column of A. |
7189 | 237 v = zeros (n, 1); |
238 v(ind_best) = 1; | |
14502
30597f98f80a
onenormest.m: Update to modern coding standards to fix input processing (bug #36016)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
239 |
7189 | 240 endfunction |
241 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
242 |
7189 | 243 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
244 %! N = 100; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
245 %! A = randn (N) + eye (N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
246 %! [L,U,P] = lu (A); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
247 %! nm1inv = onenormest (@(x) U\(L\(P*x)), @(x) P'*(L'\(U'\x)), N, 30) |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
248 %! norm (inv (A), 1) |
7189 | 249 |
250 %!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
|
251 %! N = 10; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
252 %! A = ones (N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
253 %! [nm1, v1, w1] = onenormest (A); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
254 %! [nminf, vinf, winf] = onenormest (A', 6); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
255 %! assert (nm1, N, -2*eps); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
256 %! assert (nminf, N, -2*eps); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
257 %! assert (norm (w1, 1), nm1 * norm (v1, 1), -2*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
258 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 259 |
260 %!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
|
261 %! N = 10; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
262 %! A = ones (N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
263 %! [nm1, v1, w1] = onenormest (@(x) A*x, @(x) A'*x, N, 3); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
264 %! [nminf, vinf, winf] = onenormest (@(x) A'*x, @(x) A*x, N, 3); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
265 %! assert (nm1, N, -2*eps); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
266 %! assert (nminf, N, -2*eps); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
267 %! assert (norm (w1, 1), nm1 * norm (v1, 1), -2*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
268 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 269 |
270 %!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
|
271 %! N = 5; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
272 %! 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
|
273 %! [nm1, v1, w1] = onenormest (A); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
274 %! [nminf, vinf, winf] = onenormest (A', 6); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
275 %! assert (nm1, norm (A, 1), -2*eps); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
276 %! assert (nminf, norm (A, inf), -2*eps); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
277 %! assert (norm (w1, 1), nm1 * norm (v1, 1), -2*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
278 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 279 |
280 ## Only likely to be within a factor of 10. | |
281 %!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
|
282 %! old_state = rand ("state"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
283 %! restore_state = onCleanup (@() rand ("state", old_state)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
284 %! rand ('state', 42); % Initialize to guarantee reproducible results |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
285 %! N = 100; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
286 %! A = rand (N); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
287 %! [nm1, v1, w1] = onenormest (A); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
288 %! [nminf, vinf, winf] = onenormest (A', 6); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
289 %! assert (nm1, norm (A, 1), -.1); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
290 %! assert (nminf, norm (A, inf), -.1); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
291 %! assert (norm (w1, 1), nm1 * norm (v1, 1), -2*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
292 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
293 |