% variables
x = sdpvar(2,1);
t = sdpvar(1);
P = sdpvar(2);
P(1,1) = polynomial(t, 2);
P(2,1) = polynomial(t, 2);
P(1,2) = polynomial(t, 2);
P(2,2) = polynomial(t, 2);
[s1,s1c] = polynomial([x;t], 2);
[s2,s2c] = polynomial([x;t], 2);
params = [coefficients(P,t); s1c; s2c];
E =[+1.000466767369124-0.002408620734945*t^1-0.184725034833517*t^2+0.005128298848572*t^3, -0.000046676736913-0.374759137926505*t^1+0.018472503483352*t^2-0.000512829884857*t^3
+0.001555891230420+0.991971264216851*t^1-0.615750116111723*t^2+0.017094329495239*t^3, +0.999844410876958-1.249197126421685*t^1+0.061575011611172*t^2-0.001709432949524*t^3 ];
% solver options
acc = 1e-9;
opts = sdpsettings('verbose',0,'solver','mosek');
opts.mosek.MSK_DPAR_INTPNT_CO_TOL_PFEAS = acc;
opts.mosek.MSK_DPAR_INTPNT_CO_TOL_DFEAS = acc;
opts.mosek.MSK_DPAR_INTPNT_CO_TOL_REL_GAP = acc;
%constraints
T = [1e-3 1];
bounds = (t-T(1))*(T(2)-t);
lyap = x'*(P-eye(2))*x - s1*bounds;
stab = -x'*(E'*P*E - P)*x - s2*bounds;
F = [sos(stab), sos(lyap), sos(s1), sos(s2)];
for k=1:200
s = tic;
solvesos(F,[],opts,params);
p = toc(s); fprintf('k=%d, elapsed=%3.3fs\n',k,p);
end
function [] = SolvesosPerformanceIssue1()
clc
yalmip('clear');
ss = tic;
% Coefficient-ized polynomial matrix
% The cost of calculating this matrix is a significant duration of the
% problem
E_ = [ 0.005128298849 -0.1847250348 -0.002408620735 1.000466767
0.0170943295 -0.6157501161 0.9919712642 0.00155589123
-0.0005128298849 0.01847250348 -0.3747591379 -4.667673691e-05
-0.00170943295 0.06157501161 -1.249197126 0.9998444109];
mode_coefficients = 1;
for k=0:99
s = tic;
% Reset
if ~mod(k,1)
yalmip('clear');
p = toc(s); fprintf('[clear] duration=%3.3fs\n',p); s=tic;
end
% Variables
x = sdpvar(2,1);
t = sdpvar(1);
P = sdpvar(2);
P(1,1) = polynomial(t, 2);
P(2,1) = polynomial(t, 2);
P(1,2) = P(2,1);
P(2,2) = polynomial(t, 2);
[s1,s1c] = polynomial([x;t], 2);
[s2,s2c] = polynomial([x;t], 2);
params = [coefficients(P,t); s1c; s2c];
if mode_coefficients
E = polymat(t,E_);
else
E =[+1.000466767369124-0.002408620734945*t^1-0.184725034833517*t^2+0.005128298848572*t^3, -0.000046676736913-0.374759137926505*t^1+0.018472503483352*t^2-0.000512829884857*t^3
+0.001555891230420+0.991971264216851*t^1-0.615750116111723*t^2+0.017094329495239*t^3, +0.999844410876958-1.249197126421685*t^1+0.061575011611172*t^2-0.001709432949524*t^3 ];
end
% Constraints
T = [.1 1];
bounds = (t-T(1))*(T(2)-t);
lyap = x'*(P-eye(2))*x - s1*bounds;
stab = -x'*(E
'*P*E - P)*x - s2*bounds;
F = [sos(stab), sos(lyap), sos(s1), sos(s2)];
% Solve
opts = sdpsettings('verbose',0,'solver','mosek');
sol = solvesos(F,[],opts,params);
p = toc(s); fprintf('k=%d, elapsed=%3.3fs\n',k,p);
end
fprintf('total elapsed=%3.3fs\n',toc(ss));
function [P] = polymat(var,coefficients);
d = size(coefficients,2)-1;
n = sqrt( size(coefficients,1) );
basis = var.^(d:-1:0)';
polynomials = coefficients*basis;
P = reshape(polynomials,n,n);
end
end
mode_coefficients | 0 | 1 | ||
elapsed (s) | elapsed (s) | |||
clear (mod 100) | 64.20 | 62.15 | ||
clear (mod 10) | 43.71 | 42.80 | ||
clear (mod 1) | 41.76 | 40.70 | ||
optimizer | 3.13 | 3.13 |
S = optimizer(F,[],opts,[d],params);
p = toc(ss); fprintf('[setup] elapsed=%3.3fs\n',p); s = tic;
% Solve repeatedly
s = tic;
for k=0:99
sol = S{0};
p = toc(s); fprintf('k=%d, elapsed=%3.3fs\n',k,p); s = tic;
end
fprintf('total elapsed=%3.3fs\n',toc(ss));