Mercurial > forge
annotate main/general/inst/majle.m @ 9687:9df0cf7217ae octave-forge
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
author | carandraug |
---|---|
date | Tue, 13 Mar 2012 22:39:03 +0000 |
parents | 49d1c30a4040 |
children |
rev | line source |
---|---|
8351
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
1 ## Copyright (c) 2010 Andrew V. Knyazev <andrew.knyazev@ucdenver.edu> |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
2 ## Copyright (c) 2010 Merico .E. Argentati <Merico.Argentati@ucdenver.edu> |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
3 ## All rights reserved. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
4 ## |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
5 ## Redistribution and use in source and binary forms, with or without |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
6 ## modification, are permitted provided that the following conditions are met: |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
7 ## |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
8 ## 1 Redistributions of source code must retain the above copyright notice, |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
9 ## this list of conditions and the following disclaimer. |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
10 ## 2 Redistributions in binary form must reproduce the above copyright |
8351
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
11 ## notice, this list of conditions and the following disclaimer in the |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
12 ## documentation and/or other materials provided with the distribution. |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
13 ## 3 Neither the name of the author nor the names of its contributors may be |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
14 ## used to endorse or promote products derived from this software without |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
15 ## specific prior written permission. |
8351
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
16 ## |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
17 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
18 ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
19 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
20 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
21 ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
22 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
23 ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
24 ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
25 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
8351
diff
changeset
|
26 ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
8351
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
27 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
28 %MAJLE (Weak) Majorization check |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
29 % S = MAJLE(X,Y) checks if the real part of X is (weakly) majorized by |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
30 % the real part of Y, where X and Y must be numeric (full or sparse) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
31 % arrays. It returns S=0, if there is no weak majorization of X by Y, |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
32 % S=1, if there is a weak majorization of X by Y, or S=2, if there is a |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
33 % strong majorization of X by Y. The shapes of X and Y are ignored. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
34 % NUMEL(X) and NUMEL(Y) may be different, in which case one of them is |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
35 % appended with zeros to match the sizes with the other and, in case of |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
36 % any negative components, a special warning is issued. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
37 % |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
38 % S = MAJLE(X,Y,MAJLETOL) allows in addition to specify the tolerance in |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
39 % all inequalities [S,Z] = MAJLE(X,Y,MAJLETOL) also outputs a row vector |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
40 % Z, which appears in the definition of the (weak) majorization. In the |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
41 % traditional case, where the real vectors X and Y are of the same size, |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
42 % Z = CUMSUM(SORT(Y,'descend')-SORT(X,'descend')). Here, X is weakly |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
43 % majorized by Y, if MIN(Z)>0, and strongly majorized if MIN(Z)=0, see |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
44 % http://en.wikipedia.org/wiki/Majorization |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
45 % |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
46 % The value of MAJLETOL depends on how X and Y have been computed, i.e., |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
47 % on what the level of error in X or Y is. A good minimal starting point |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
48 % should be MAJLETOL=eps*MAX(NUMEL(X),NUMEL(Y)). The default is 0. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
49 % |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
50 % % Examples: |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
51 % x = [2 2 2]; y = [1 2 3]; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
52 % % returns the value 2. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
53 % x = [2 2 2]; y = [1 2 4]; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
54 % % returns the value 1. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
55 % x = [2 2 2]; y = [1 2 2]; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
56 % % returns the value 0. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
57 % x = [2 2 2]; y = [1 2 2]; [s,z] = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
58 % % also returns the vector z = [ 0 0 -1]. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
59 % x = [2 2 2]; y = [1 2 2]; s = majle(x,y,1) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
60 % % returns the value 2. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
61 % x = [2 2]; y = [1 2 2]; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
62 % % returns the value 1 and warns on tailing with zeros |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
63 % x = [2 2]; y = [-1 2 2]; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
64 % % returns the value 0 and gives two warnings on tailing with zeros |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
65 % x = [2 -inf]; y = [4 inf]; [s,z] = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
66 % % returns s = 1 and z = [Inf Inf]. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
67 % x = [2 inf]; y = [4 inf]; [s,z] = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
68 % % returns s = 1 and z = [NaN NaN] and a warning on NaNs in z. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
69 % x=speye(2); y=sparse([0 2; -1 1]); s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
70 % % returns the value 2. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
71 % x = [2 2; 2 2]; y = [1 3 4]; [s,z] = majle(x,y) %and |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
72 % x = [2 2; 2 2]+i; y = [1 3 4]-2*i; [s,z] = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
73 % % both return s = 2 and z = [2 3 2 0]. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
74 % x = [1 1 1 1 0]; y = [1 1 1 1 1 0 0]'; s = majle(x,y) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
75 % % returns the value 1 and warns on tailing with zeros |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
76 % |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
77 % % One can use this function to check numerically the validity of the |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
78 % Schur-Horn,Lidskii-Mirsky-Wielandt, and Gelfand-Naimark theorems: |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
79 % clear all; n=100; majleTol=n*n*eps; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
80 % A = randn(n,n); A = A'+A; eA = -sort(-eig(A)); dA = diag(A); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
81 % majle(dA,eA,majleTol) % returns the value 2 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
82 % % which is the Schur-Horn theorem; and |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
83 % B=randn(n,n); B=B'+B; eB=-sort(-eig(B)); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
84 % eAmB=-sort(-eig(A-B)); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
85 % majle(eA-eB,eAmB,majleTol) % returns the value 2 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
86 % % which is the Lidskii-Mirsky-Wielandt theorem; finally |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
87 % A = randn(n,n); sA = -sort(-svd(A)); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
88 % B = randn(n,n); sB = -sort(-svd(B)); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
89 % sAB = -sort(-svd(A*B)); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
90 % majle(log2(sAB)-log2(sA), log2(sB), majleTol) % retuns the value 2 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
91 % majle(log2(sAB)-log2(sB), log2(sA), majleTol) % retuns the value 2 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
92 % % which are the log versions of the Gelfand-Naimark theorems |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
93 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
94 % Tested in MATLAB 7.9.0.529 (R2009b) and Octave 3.2.3. |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
95 function [s,z]=majle(x,y,majleTol) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
96 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
97 if (nargin < 2) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
98 error('MAJORIZATION:majle:NotEnoughInputs',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
99 'Not enough input arguments.'); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
100 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
101 if (nargin > 3) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
102 error('MAJORIZATION:majle:TooManyInputs',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
103 'Too many input arguments.'); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
104 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
105 if (nargout > 2) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
106 error('MAJORIZATION:majle:TooManyOutputs',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
107 'Too many output arguments.'); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
108 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
109 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
110 % Assign default values to unspecified parameters |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
111 if (nargin == 2) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
112 majleTol = 0; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
113 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
114 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
115 % transform into real (row) vectors |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
116 x=real(x); xc=reshape(x,1,numel(x)); clear x; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
117 y=real(y); yc=reshape(y,1,numel(y)); clear y; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
118 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
119 % sort both vectors in descending order |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
120 xc=-sort(-xc); yc=-sort(-yc); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
121 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
122 % tail with zeros the shorter vector to make vectors of the same length |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
123 if size(xc,2)~=size(yc,2) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
124 checkForNegative = (xc(end) < -majleTol) || (yc(end) < -majleTol); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
125 warning('MAJORIZATION:majle:ResizeVectors', ... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
126 'The input vectors have different sizes. Tailing with zeros.'); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
127 yc=[yc zeros(size(xc,2)-size(yc,2),1)']; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
128 xc=[xc zeros(size(yc,2)-size(xc,2),1)']; |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
129 % but warn if negative |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
130 if checkForNegative |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
131 warning('MAJORIZATION:majle:ResizeNegativeVectors', ... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
132 sprintf('%s%s\n%s\n%s', ... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
133 'At least one of the input vectors ',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
134 'has negative components.',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
135 ' Tailing with zeros is most likely senseless.',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
136 ' Make sure that you know what you are doing.')); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
137 % sort again both vectors in descending order |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
138 xc=-sort(-xc); yc=-sort(-yc); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
139 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
140 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
141 z=cumsum(yc-xc); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
142 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
143 %check for NaNs in z |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
144 if any(isnan(z)) |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
145 warning('MAJORIZATION:majle:NaNsInComparisons', ... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
146 sprintf('%s%s\n%s\n%s', ... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
147 'At least one of the input vectors ',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
148 'includes -Inf, Inf, or NaN components.',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
149 ' Some comparisons could not be made. ',... |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
150 ' Make sure that you know what you are doing.')); |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
151 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
152 |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
153 if min(z) < -majleTol |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
154 s=0; % no majorization |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
155 elseif abs(z(end)) <= majleTol |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
156 s=2; % strong majorization |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
157 else |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
158 s=1; % weak majorization |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
159 end |
49d1c30a4040
majle: new function for the general package. Submitted by Andrew Knyazev on the mailing list
carandraug
parents:
diff
changeset
|
160 endfunction |