Mercurial > hg > octave-lyh
annotate scripts/linear-algebra/onenormest.m @ 14363:f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
* wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m,
asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m,
csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m,
accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m,
celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m,
cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m,
flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m,
interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m,
isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m,
narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m,
polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m,
randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m,
structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m,
griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m,
get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m,
imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m,
textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m,
duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m,
issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m,
qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m,
bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m,
fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m,
ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m,
news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m,
setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m,
warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m,
pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m,
__plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m,
colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m,
ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m,
ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m,
legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m,
orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m,
refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m,
stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m,
deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m,
polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m,
ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m,
ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m,
autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m,
fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m,
sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m,
pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m,
sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m,
beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m,
nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m,
realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m,
vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m,
iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m,
median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m,
range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m,
statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m,
betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m,
cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m,
chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m,
empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m,
expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m,
gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m,
hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m,
laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m,
logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m,
lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m,
norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m,
poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m,
tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m,
unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m,
wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m,
bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m,
findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m,
strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m,
substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m,
asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m,
eomday.m, etime.m, is_leap_year.m, now.m:
Use Octave coding conventions in all m-file %!test blocks
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 13 Feb 2012 07:29:44 -0800 |
parents | 11949c9795a0 |
children | 30597f98f80a |
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: |
7189 | 41 ## @itemize |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
42 ## @item |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
43 ## N.J. Higham and F. Tisseur, @cite{A Block Algorithm |
7189 | 44 ## 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
|
45 ## Pseudospectra}. SIMAX vol 21, no 4, pp 1185-1201. |
7189 | 46 ## @url{http://dx.doi.org/10.1137/S0895479899356080} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
47 ## |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
48 ## @item |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10791
diff
changeset
|
49 ## N.J. Higham and F. Tisseur, @cite{A Block Algorithm |
7189 | 50 ## 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
|
51 ## Pseudospectra}. @url{http://citeseer.ist.psu.edu/223007.html} |
7189 | 52 ## @end itemize |
53 ## | |
54 ## @seealso{condest, norm, cond} | |
55 ## @end deftypefn | |
56 | |
57 ## Code originally licensed under | |
58 ## | |
59 ## Copyright (c) 2007, Regents of the University of California | |
60 ## All rights reserved. | |
7191 | 61 ## |
7189 | 62 ## Redistribution and use in source and binary forms, with or without |
7191 | 63 ## modification, are permitted provided that the following conditions |
64 ## are met: | |
7189 | 65 ## |
66 ## * Redistributions of source code must retain the above copyright | |
67 ## notice, this list of conditions and the following disclaimer. | |
7191 | 68 ## |
69 ## * Redistributions in binary form must reproduce the above | |
70 ## copyright notice, this list of conditions and the following | |
71 ## disclaimer in the documentation and/or other materials provided | |
72 ## with the distribution. | |
73 ## | |
74 ## * Neither the name of the University of California, Berkeley nor | |
75 ## the names of its contributors may be used to endorse or promote | |
76 ## products derived from this software without specific prior | |
77 ## written permission. | |
7189 | 78 ## |
7191 | 79 ## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' |
80 ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
81 ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
82 ## PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND | |
83 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
84 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
85 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
86 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
87 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
88 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
89 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
7189 | 90 ## SUCH DAMAGE. |
91 | |
92 ## Author: Jason Riedy <ejr@cs.berkeley.edu> | |
93 ## Keywords: linear-algebra norm estimation | |
94 ## Version: 0.2 | |
95 | |
96 function [est, v, w, iter] = onenormest (varargin) | |
97 | |
98 if (size (varargin, 2) < 1 || size (varargin, 2) > 4) | |
99 print_usage (); | |
100 endif | |
101 | |
102 default_t = 5; | |
103 itmax = 10; | |
104 | |
105 if (ismatrix (varargin{1})) | |
106 n = size (varargin{1}, 1); | |
107 if n != size (varargin{1}, 2), | |
8664 | 108 error ("onenormest: matrix must be square"); |
7189 | 109 endif |
110 apply = @(x) varargin{1} * x; | |
111 apply_t = @(x) varargin{1}' * x; | |
112 if (size (varargin) > 1) | |
113 t = varargin{2}; | |
114 else | |
115 t = min (n, default_t); | |
116 endif | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
117 issing = isa (varargin {1}, "single"); |
7189 | 118 else |
119 if (size (varargin, 2) < 3) | |
120 print_usage(); | |
121 endif | |
122 n = varargin{3}; | |
123 apply = varargin{1}; | |
124 apply_t = varargin{2}; | |
125 if (size (varargin) > 3) | |
126 t = varargin{4}; | |
127 else | |
128 t = default_t; | |
129 endif | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
130 issing = isa (varargin {3}, "single"); |
7189 | 131 endif |
132 | |
133 ## Initial test vectors X. | |
134 X = rand (n, t); | |
135 X = X ./ (ones (n,1) * sum (abs (X), 1)); | |
136 | |
8506 | 137 ## Track if a vertex has been visited. |
138 been_there = zeros (n, 1); | |
139 | |
140 ## To check if the estimate has increased. | |
141 est_old = 0; | |
142 | |
143 ## Normalized vector of signs. | |
144 S = zeros (n, t); | |
7189 | 145 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
146 if (issing) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
147 myeps = eps ("single"); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
148 X = single (X); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
149 else |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
150 myeps = eps; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
151 endif |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7191
diff
changeset
|
152 |
7189 | 153 for iter = 1 : itmax + 1 |
154 Y = feval (apply, X); | |
155 | |
156 ## Find the initial estimate as the largest A*x. | |
157 [est, ind_best] = max (sum (abs (Y), 1)); | |
158 if (est > est_old || iter == 2) | |
159 w = Y(:,ind_best); | |
160 endif | |
161 if (iter >= 2 && est < est_old) | |
162 ## No improvement, so stop. | |
163 est = est_old; | |
164 break; | |
165 endif | |
166 | |
167 est_old = est; | |
168 S_old = S; | |
169 if (iter > itmax), | |
170 ## Gone too far. Stop. | |
171 break; | |
172 endif | |
173 | |
174 S = sign (Y); | |
175 | |
176 ## Test if any of S are approximately parallel to previous S | |
177 ## vectors or current S vectors. If everything is parallel, | |
178 ## stop. Otherwise, replace any parallel vectors with | |
179 ## rand{-1,+1}. | |
180 partest = any (abs (S_old' * S - n) < 4*eps*n); | |
181 if (all (partest)) | |
182 ## All the current vectors are parallel to old vectors. | |
183 ## We've hit a cycle, so stop. | |
184 break; | |
185 endif | |
186 if (any (partest)) | |
187 ## Some vectors are parallel to old ones and are cycling, | |
188 ## but not all of them. Replace the parallel vectors with | |
189 ## rand{-1,+1}. | |
190 numpar = sum (partest); | |
191 replacements = 2*(rand (n,numpar) < 0.5) - 1; | |
192 S(:,partest) = replacements; | |
193 endif | |
194 ## Now test for parallel vectors within S. | |
8507 | 195 partest = any ((S' * S - eye (t)) == n); |
7189 | 196 if (any (partest)) |
197 numpar = sum (partest); | |
198 replacements = 2*(rand (n,numpar) < 0.5) - 1; | |
199 S(:,partest) = replacements; | |
200 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
201 |
7189 | 202 Z = feval (apply_t, S); |
203 | |
204 ## Now find the largest non-previously-visted index per | |
205 ## vector. | |
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 |
219 ind = ind (!been_there (ind)); | |
220 if (length (ind) < t) | |
10549 | 221 ## There aren't enough new vectors, so we're practically |
222 ## in a cycle. Stop. | |
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 | |
232 been_there (ind (1 : t)) = 1; | |
233 endfor | |
234 | |
235 ## The estimate est and vector w are set in the loop above. The | |
236 ## vector v selects the ind_best column of A. | |
237 v = zeros (n, 1); | |
238 v(ind_best) = 1; | |
239 endfunction | |
240 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
241 |
7189 | 242 %!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
|
243 %! 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
|
244 %! 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
|
245 %! [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
|
246 %! 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
|
247 %! norm (inv (A), 1) |
7189 | 248 |
249 %!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
|
250 %! 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
|
251 %! 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
|
252 %! [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
|
253 %! [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
|
254 %! 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
|
255 %! 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
|
256 %! 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
|
257 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 258 |
259 %!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
|
260 %! 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
|
261 %! 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
|
262 %! [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
|
263 %! [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
|
264 %! 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
|
265 %! 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
|
266 %! 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
|
267 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 268 |
269 %!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
|
270 %! 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
|
271 %! 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
|
272 %! [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
|
273 %! [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
|
274 %! 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
|
275 %! 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
|
276 %! 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
|
277 %! assert (norm (winf, 1), nminf * norm (vinf, 1), -2*eps); |
7189 | 278 |
279 ## Only likely to be within a factor of 10. | |
280 %!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
|
281 %! 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
|
282 %! 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
|
283 %! 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
|
284 %! 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
|
285 %! 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
|
286 %! [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
|
287 %! [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
|
288 %! 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
|
289 %! 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
|
290 %! 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
|
291 %! 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
|
292 |