-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathmaxeigK.m
104 lines (99 loc) · 2.9 KB
/
maxeigK.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function lab = maxeigK(x,K)
% lab = maxeigK(x,K)
%
% MAXEIGK Computes the maximum eigenvalue of a vector x with respect to a
% self-dual homogenous cone K.
%
% See also sedumi, mat, vec, eyeK.
% New function by Michael C. Grant
% Copyright (C) 2013 Michael C. Grant.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
% 02110-1301, USA
%
% The existence of rsdpN is code for 'is this the internal format?'
if isfield(K,'rsdpN')
% The internal SeDuMi cone format.
is_int = true;
nf = 0;
nl = K.l;
nq = length(K.q);
nr = 0;
ns = length(K.s);
nrsdp = K.rsdpN;
else
% The external SeDuMi cone format.
is_int = false;
if isfield(K,'f'), nf = K.f; else nf = 0; end
if isfield(K,'l'), nl = K.l; else nl = 0; end
if isfield(K,'q'), nq = length(K.q); else nq = 0; end
if isfield(K,'r'), nr = length(K.r); else nr = 0; end
if isfield(K,'s'), ns = length(K.s); else ns = 0; end
end
xi = nf;
lab = max([-Inf;x(xi+1:xi+nl)]);
xi = xi + nl;
if nq
tmp = sqrt(0.5);
if is_int
% Internal version: all of the x0 values are at the front, and the
% vectors are stacked in order after that.
zi = xi;
xi = xi + nq;
for i = 1:nq
kk = K.q(i) - 1;
x0 = x(zi+i);
lab = max(lab,tmp*(x0+norm(x(xi+1:xi+kk))));
xi = xi + kk;
end
else
for i = 1:length(K.q)
kk = K.q(i);
x0 = x(xi+1);
lab = max(lab,tmp*(x0+norm(x(xi+2:xi+kk))));
xi = xi + kk;
end
end
end
for i = 1:nr
% Only the external format need be implemented here
ki = K.r(i);
x1 = xx(xi+1);
x2 = xx(xi+2);
lab = max(lab,0.5*(x1+x2+norm([x1-x2;2*x(xi+3:xi+ki)])));
xi = xi + ki;
end
if ns
for i = 1 : ns
ki = K.s(i);
qi = ki * ki;
XX = x(xi+1:xi+qi);
xi = xi + qi;
if i > nrsdp
XX = XX + 1i*x(xi+1:xi+qi);
xi = xi + qi;
end
XX = reshape(XX,ki,ki);
XX = XX + XX';
if ki > 500
if nnz(XX) < 0.1 * numel(XX), XX = sparse(XX); end
[v,val,flag] = eigs(XX,1,'LA');
if flag, val = max(eig(XX)); end
else
val = max(eig(XX));
end
lab = max(lab,0.5*val);
end
end