1 # Created by Octave 3.6.1, Thu May 17 20:15:05 2012 UTC <root@brouzouf>
13 # name: <cell-element>
17 -- Function File: [XS, YS] = adresamp2 (X, Y, N, EPS)
18 Perform an adaptive resampling of a planar curve. The arrays X
19 and Y specify x and y coordinates of the points of the curve. On
20 return, the same curve is approximated by XS, YS that have length N
21 and the angles between successive segments are approximately equal.
26 # name: <cell-element>
30 Perform an adaptive resampling of a planar curve.
34 # name: <cell-element>
41 # name: <cell-element>
45 MAJLE (Weak) Majorization check
46 S = MAJLE(X,Y) checks if the real part of X is (weakly) majorized by
47 the real part of Y, where X and Y must be numeric (full or sparse)
48 arrays. It returns S=0, if there is no weak majorization of X by Y,
49 S=1, if there is a weak majorization of X by Y, or S=2, if there is a
50 strong majorization of X by Y. The shapes of X and Y are ignored.
51 NUMEL(X) and NUMEL(Y) may be different, in which case one of them is
52 appended with zeros to match the sizes with the other and, in case of
53 any negative components, a special warning is issued.
55 S = MAJLE(X,Y,MAJLETOL) allows in addition to specify the tolerance in
56 all inequalities [S,Z] = MAJLE(X,Y,MAJLETOL) also outputs a row vector
57 Z, which appears in the definition of the (weak) majorization. In the
58 traditional case, where the real vectors X and Y are of the same size,
59 Z = CUMSUM(SORT(Y,'descend')-SORT(X,'descend')). Here, X is weakly
60 majorized by Y, if MIN(Z)>0, and strongly majorized if MIN(Z)=0, see
61 http://en.wikipedia.org/wiki/Majorization
63 The value of MAJLETOL depends on how X and Y have been computed, i.e.,
64 on what the level of error in X or Y is. A good minimal starting point
65 should be MAJLETOL=eps*MAX(NUMEL(X),NUMEL(Y)). The default is 0.
68 x = [2 2 2]; y = [1 2 3]; s = majle(x,y)
69 % returns the value 2.
70 x = [2 2 2]; y = [1 2 4]; s = majle(x,y)
71 % returns the value 1.
72 x = [2 2 2]; y = [1 2 2]; s = majle(x,y)
73 % returns the value 0.
74 x = [2 2 2]; y = [1 2 2]; [s,z] = majle(x,y)
75 % also returns the vector z = [ 0 0 -1].
76 x = [2 2 2]; y = [1 2 2]; s = majle(x,y,1)
77 % returns the value 2.
78 x = [2 2]; y = [1 2 2]; s = majle(x,y)
79 % returns the value 1 and warns on tailing with zeros
80 x = [2 2]; y = [-1 2 2]; s = majle(x,y)
81 % returns the value 0 and gives two warnings on tailing with zeros
82 x = [2 -inf]; y = [4 inf]; [s,z] = majle(x,y)
83 % returns s = 1 and z = [Inf Inf].
84 x = [2 inf]; y = [4 inf]; [s,z] = majle(x,y)
85 % returns s = 1 and z = [NaN NaN] and a warning on NaNs in z.
86 x=speye(2); y=sparse([0 2; -1 1]); s = majle(x,y)
87 % returns the value 2.
88 x = [2 2; 2 2]; y = [1 3 4]; [s,z] = majle(x,y) %and
89 x = [2 2; 2 2]+i; y = [1 3 4]-2*i; [s,z] = majle(x,y)
90 % both return s = 2 and z = [2 3 2 0].
91 x = [1 1 1 1 0]; y = [1 1 1 1 1 0 0]'; s = majle(x,y)
92 % returns the value 1 and warns on tailing with zeros
94 % One can use this function to check numerically the validity of the
95 Schur-Horn,Lidskii-Mirsky-Wielandt, and Gelfand-Naimark theorems:
96 clear all; n=100; majleTol=n*n*eps;
97 A = randn(n,n); A = A'+A; eA = -sort(-eig(A)); dA = diag(A);
98 majle(dA,eA,majleTol) % returns the value 2
99 % which is the Schur-Horn theorem; and
100 B=randn(n,n); B=B'+B; eB=-sort(-eig(B));
101 eAmB=-sort(-eig(A-B));
102 majle(eA-eB,eAmB,majleTol) % returns the value 2
103 % which is the Lidskii-Mirsky-Wielandt theorem; finally
104 A = randn(n,n); sA = -sort(-svd(A));
105 B = randn(n,n); sB = -sort(-svd(B));
106 sAB = -sort(-svd(A*B));
107 majle(log2(sAB)-log2(sA), log2(sB), majleTol) % retuns the value 2
108 majle(log2(sAB)-log2(sB), log2(sA), majleTol) % retuns the value 2
109 % which are the log versions of the Gelfand-Naimark theorems
113 # name: <cell-element>
117 MAJLE (Weak) Majorization check
118 S = MAJLE(X,Y) checks if the real part of X
122 # name: <cell-element>
129 # name: <cell-element>
133 -- Function File: [O1, O2, ...] = pararrayfun (NPROC, FUN, A1, A2, ...)
134 -- Function File: pararrayfun (nproc, fun, ..., "UniformOutput", VAL)
135 -- Function File: pararrayfun (nproc, fun, ..., "ErrorHandler",
137 Evaluates a function for corresponding elements of an array.
138 Argument and options handling is analogical to `parcellfun',
139 except that arguments are arrays rather than cells. If cells occur
140 as arguments, they are treated as arrays of singleton cells.
141 Arrayfun supports one extra option compared to parcellfun:
142 "Vectorized". This option must be given together with
143 "ChunksPerProc" and it indicates that FUN is able to operate on
144 vectors rather than just scalars, and returns a vector. The same
145 must be true for ERRFUNC, if given. In this case, the array is
146 split into chunks which are then directly served to FUNC for
147 evaluation, and the results are concatenated to output arrays.
149 See also: parcellfun, arrayfun
155 # name: <cell-element>
159 Evaluates a function for corresponding elements of an array.
163 # name: <cell-element>
170 # name: <cell-element>
174 -- Function File: [O1, O2, ...] = parcellfun (NPROC, FUN, A1, A2, ...)
175 -- Function File: parcellfun (nproc, fun, ..., "UniformOutput", VAL)
176 -- Function File: parcellfun (nproc, fun, ..., "ErrorHandler",
178 -- Function File: parcellfun (nproc, fun, ..., "VerboseLevel", VAL)
179 -- Function File: parcellfun (nproc, fun, ..., "ChunksPerProc", VAL)
180 Evaluates a function for multiple argument sets using multiple
181 processes. NPROC should specify the number of processes. A
182 maximum recommended value is equal to number of CPUs on your
183 machine or one less. FUN is a function handle pointing to the
184 requested evaluating function. A1, A2 etc. should be cell arrays
185 of equal size. O1, O2 etc. will be set to corresponding output
188 The UniformOutput and ErrorHandler options are supported with
189 meaning identical to "cellfun". A VerboseLevel option controlling
190 the level output is supported. A value of 0 is quiet, 1 is
191 normal, and 2 or more enables debugging output. The ChunksPerProc
192 option control the number of chunks which contains elementary
193 jobs. This option particularly useful when time execution of
194 function is small. Setting this option to 100 is a good choice in
197 Notice that jobs are served from a single first-come first-served
198 queue, so the number of jobs executed by each process is generally
199 unpredictable. This means, for example, that when using this
200 function to perform Monte-Carlo simulations one cannot expect
201 results to be exactly reproducible. The pseudo random number
202 generators of each process are initialised with a unique state.
203 This currently works only for new style generators.
205 NOTE: this function is implemented using "fork" and a number of
206 pipes for IPC. Suitable for systems with an efficient "fork"
207 implementation (such as GNU/Linux), on other systems (Windows) it
208 should be used with caution. Also, if you use a multithreaded
209 BLAS, it may be wise to turn off multi-threading when using this
212 CAUTION: This function should be regarded as experimental.
213 Although all subprocesses should be cleared in theory, there is
214 always a danger of a subprocess hanging up, especially if
215 unhandled errors occur. Under GNU and compatible systems, the
216 following shell command may be used to display orphaned Octave
217 processes: ps -ppid 1 | grep octave
223 # name: <cell-element>
227 Evaluates a function for multiple argument sets using multiple
232 # name: <cell-element>
239 # name: <cell-element>
243 -- Function File: P = safeprod (X, DIM)
244 -- Function File: [P, E] = safeprod (X, DIM)
245 This function forms product(s) of elements of the array X along
246 the dimension specified by DIM, analogically to `prod', but avoids
247 overflows and underflows if possible. If called with 2 output
248 arguments, P and E are computed so that the product is `P * 2^E'.
256 # name: <cell-element>
260 This function forms product(s) of elements of the array X along the
265 # name: <cell-element>
272 # name: <cell-element>
276 -- Function File: [XS, YS] = unresamp2 (X, Y, N)
277 Perform a uniform resampling of a planar curve. The arrays X and
278 Y specify x and y coordinates of the points of the curve. On
279 return, the same curve is approximated by XS, YS that have length N
280 and the distances between successive points are approximately
286 # name: <cell-element>
290 Perform a uniform resampling of a planar curve.
294 # name: <cell-element>
301 # name: <cell-element>
305 -- Function File: M = unvech (V, SCALE)
306 Performs the reverse of `vech' on the vector V.
308 Given a Nx1 array V describing the lower triangular part of a
309 matrix (as obtained from `vech'), it returns the full matrix.
311 The upper triangular part of the matrix will be multiplied by
312 SCALE such that 1 and -1 can be used for symmetric and
313 antisymmetric matrix respectively. SCALE must be a scalar and
316 See also: vech, ind2sub
322 # name: <cell-element>
326 Performs the reverse of `vech' on the vector V.
330 # name: <cell-element>
337 # name: <cell-element>
341 -- Function File: function ztvals (X, TOL)
342 Replaces tiny elements of the vector X by zeros. Equivalent to
343 X(abs(X) < TOL * norm (X, Inf)) = 0
344 TOL specifies the chopping tolerance. It defaults to 1e-10 for
345 double precision and 1e-5 for single precision inputs.
350 # name: <cell-element>
354 Replaces tiny elements of the vector X by zeros.