forked from nathanieljohnston/QETLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Majorizes.m
56 lines (48 loc) · 1.28 KB
/
Majorizes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%% MAJORIZES Determines whether or not a vector or matrix majorizes another
% This function has two required arguments:
% A: a vector or matrix
% B: a vector or matrix
%
% M = Majorizes(A,B) is either 1 or 0, indicating that A does or does not
% majorize B. If A and B are matrices then majorization of their vectors
% of singular values is checked.
%
% This function has no optional arguments.
%
% URL: https://www.qetlab.com/Majorizes
% requires: nothing
% author: Nathaniel Johnston ([email protected])
% package: QETLAB
% last updated: March 4, 2014
function m = Majorizes(a,b)
if(min(size(a)) ~= 1) % if we received matrices as input, we check their singular values for majorization
a = svd(full(a)); % automatically sorted in descending order
else
a = sort(a(:),'descend');
end
% repeat for b
if(min(size(b)) ~= 1)
b = svd(full(b));
else
b = sort(b(:),'descend');
end
% pad with zeros if necessary
la = length(a);
lb = length(b);
if(la < lb)
a = [a;zeros(lb-la,1)];
elseif(lb < la)
b = [b;zeros(la-lb,1)];
end
cta = 0;
ctb = -norm(a)*eps^(3/4); % for numerical robustness reasons
% now check majorization
for k = 1:length(a)
cta = cta + a(k);
ctb = ctb + b(k);
if(cta < ctb)
m = 0;
return
end
end
m = 1;