clear allclc
% The example works for f = [-x1;-x2] and rho = 1
eps = 1e-9;
%% System Definition
% State Space Variablesx1 = sdpvar(1);x2 = sdpvar(1);
% System definitionsf = [-x1-x1^3+x2^2;0];B = [0;1];
% Variational systemA = jacobian(f,[x1 x2]);MatrixA = sdisplay(A)
%% Contraction Metric set up
W = sdpvar(2,2); % The function rhoRhodeg = 2; % Degree of the polynomial of rho[Rho,cRho,vRho] = polynomial([x1 x2], Rhodeg, 0);FunctionRho = sdisplay(Rho)
% Lie Derivative along the vector field
LfW = A*W + W*A' + W - (B*B'); % Gives solution% LfW = A*W + W*A' + W - Rho*(B*B'); % Doesn't
LieDerivative = sdisplay(LfW)
%% Constraints
% The decision variables are the coefficients of the polynomialsConstraints = [W >= 0, LfW <= 0];Constraints % display list of constraints
% set required solveroptions = sdpsettings('solver','mosek','verbose',0);diagnostics = optimize(Constraints,[],options);
if diagnostics.problem == 0 disp('Feasible')elseif diagnostics.problem == 1 disp('Infeasible')else disp('Something else happened')end
W = value(W)solution2 = value(Rho)
+++++++++++++++++++++++++++++++++++++++++++++| ID| Constraint|+++++++++++++++++++++++++++++++++++++++++++++| #1| Matrix inequality 2x2|| #2| Matrix inequality (polynomial) 2x2|+++++++++++++++++++++++++++++++++++++++++++++Warning: Solver not applicable (mosek)Something else happened
W =
NaN NaN NaN NaN
solution2 =
NaN
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++| ID| Constraint| Primal residual|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++| #1| Matrix inequality| NaN|| #2| Matrix inequality (polynomial)| NaN|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LfW = A*W + W*A' + W - Rho*(B*B');
Constraints = [W>=eye(2), sos(-LfW),sos(Rho)];solvesos(Constraints,[],[],[W(:);cRho])value(W)value(cRho)
% polynomials for W matrixWdegree = 2;
[Wp11,Wc11,Wv11] = polynomial([x1 x2],Wdegree,0); [Wp12,Wc12,Wv12] = polynomial([x1 x2],Wdegree,0); [Wp22,Wc22,Wv22] = polynomial([x1 x2],Wdegree,0);
% set W matrix and its derivativesW = [Wp11 Wp12; Wp12 Wp22]; DWv = jacobian([Wp11;Wp12;Wp22],[x1 x2])*f; DW = [DWv(1) DWv(2); DWv(2) DWv(3)];
LfW = -DW + A*W + W*A' + W - Rho*(B*B');
Constraints = [W>=eye(2),sos(-LfW),sos(Rho)];
coefList = [Wc11;Wc12;Wc22;cRho];options = sdpsettings('solver','mosek');diagnostics = solvesos(Constraints,[],options,coefList);
++++++++++++++++++++++++++++++++++++++++++++++++| ID| Constraint|++++++++++++++++++++++++++++++++++++++++++++++++| #1| Matrix inequality (polynomial) 2x2|| #2| Sum-of-square constraint (polynomial)|| #3| Sum-of-square constraint (polynomial)|++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------YALMIP SOS module started...-------------------------------------------------------------------------Error using compilesos (line 170)No independent variables? Perhaps you added a constraint (p(x)) when you meant(sos(p(x))). It could also be that you added a constraint directly in theindependents, such as p(x)>=0 or similarily.
Error in solvesos (line 112)[F,obj,m,everything] = compilesos(F,obj,options,params,candidateMonomials);
Error in IansExample4 (line 58)diagnostics = solvesos(Constraints,[],options,coefList);
Constraints = [sos(-LfW),sos(Rho)];
++++++++++++++++++++++++++++++++++++++++++++++++| ID| Constraint|++++++++++++++++++++++++++++++++++++++++++++++++| #1| Sum-of-square constraint (polynomial)|| #2| Sum-of-square constraint (polynomial)|++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------YALMIP SOS module started...-------------------------------------------------------------------------Detected 24 parametric variables and 2 independent variables.Detected 0 linear inequalities, 0 equality constraints and 0 LMIs.Using kernel representation (options.sos.model=1).Initially 6 monomials in R^2Newton polytope (1 LPs).........Keeping 5 monomials (0.0468sec)Finding symmetries..............Found no symmetries (0.0312sec)Initially 3 monomials in R^2Newton polytope (0 LPs).........Keeping 3 monomials (0sec)Finding symmetries..............Found no symmetries (0sec)
MOSEK Version 7.1.0.49 (Build date: 2016-3-7 09:17:41)Copyright (c) 1998-2016 MOSEK ApS, Denmark. WWW: http://mosek.comPlatform: Windows/64-X86
Computer Platform : Windows/64-X86
Problem Name : Objective sense : min Type : CONIC (conic optimization problem) Constraints : 45 Cones : 0 Scalar variables : 24 Matrix variables : 2 Integer variables : 0
Optimizer started.Conic interior-point optimizer started.Presolve started.Linear dependency checker started.Linear dependency checker terminated.Eliminator - tries : 0 time : 0.00 Eliminator - elim's : 0 Lin. dep. - tries : 1 time : 0.01 Lin. dep. - number : 0 Presolve terminated. Time: 0.01 Optimizer - threads : 2 Optimizer - solved problem : the primal Optimizer - Constraints : 42Optimizer - Cones : 0Optimizer - Scalar variables : 22 conic : 0 Optimizer - Semi-definite variables: 2 scalarized : 61 Factor - setup time : 0.00 dense det. time : 0.00 Factor - ML order time : 0.00 GP order time : 0.00 Factor - nonzeros before factor : 873 after factor : 903 Factor - dense dim. : 0 flops : 3.89e+004 ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME 0 1.0e+000 1.0e+000 1.0e+000 0.00e+000 0.000000000e+000 0.000000000e+000 1.0e+000 0.03 1 3.8e-001 3.8e-001 3.8e-001 1.00e+000 0.000000000e+000 0.000000000e+000 3.8e-001 0.09 2 5.8e-002 5.8e-002 5.8e-002 1.00e+000 0.000000000e+000 0.000000000e+000 5.8e-002 0.09 3 9.9e-003 9.9e-003 9.9e-003 1.00e+000 0.000000000e+000 0.000000000e+000 9.9e-003 0.09 4 2.2e-003 2.2e-003 2.2e-003 1.00e+000 0.000000000e+000 0.000000000e+000 2.2e-003 0.11 5 5.5e-004 5.5e-004 5.5e-004 1.00e+000 0.000000000e+000 0.000000000e+000 5.5e-004 0.11 6 2.1e-004 2.1e-004 2.1e-004 1.00e+000 0.000000000e+000 0.000000000e+000 2.1e-004 0.11 7 4.0e-005 4.0e-005 4.0e-005 1.00e+000 0.000000000e+000 0.000000000e+000 4.0e-005 0.11 8 1.1e-005 1.1e-005 1.1e-005 1.00e+000 0.000000000e+000 0.000000000e+000 1.1e-005 0.13 9 2.1e-006 2.1e-006 2.1e-006 1.00e+000 0.000000000e+000 0.000000000e+000 2.1e-006 0.13 10 5.9e-007 5.9e-007 5.9e-007 1.00e+000 0.000000000e+000 0.000000000e+000 5.9e-007 0.13 11 1.5e-007 1.5e-007 1.5e-007 1.00e+000 0.000000000e+000 0.000000000e+000 1.5e-007 0.14 12 5.7e-008 5.7e-008 5.7e-008 1.00e+000 0.000000000e+000 0.000000000e+000 5.7e-008 0.14 13 1.0e-008 1.0e-008 1.0e-008 1.00e+000 0.000000000e+000 0.000000000e+000 1.0e-008 0.14 Interior-point optimizer terminated. Time: 0.14.
Optimizer terminated. Time: 0.22
Interior-point solution summary Problem status : PRIMAL_AND_DUAL_FEASIBLE Solution status : OPTIMAL Primal. obj: 0.0000000000e+000 Viol. con: 1e-008 var: 0e+000 barvar: 0e+000 Dual. obj: 0.0000000000e+000 Viol. con: 0e+000 var: 7e-009 barvar: 1e-008 Optimizer summary Optimizer - time: 0.22 Interior-point - iterations : 13 time: 0.14 Basis identification - time: 0.00 Primal - iterations : 0 time: 0.00 Dual - iterations : 0 time: 0.00 Clean primal - iterations : 0 time: 0.00 Clean dual - iterations : 0 time: 0.00 Clean primal-dual - iterations : 0 time: 0.00 Simplex - time: 0.00 Primal simplex - iterations : 0 time: 0.00 Dual simplex - iterations : 0 time: 0.00 Primal-dual simplex - iterations : 0 time: 0.00 Mixed integer - relaxations: 0 time: 0.00
Feasible
W =
NaN NaN NaN NaN
cRho =
1.4892 -0.0038 0.0000 1.6547 0.0000 1.8927
coefList
sdisplay(replace(W,[Wc11;Wc12;Wc22],value([Wc11;Wc12;Wc22])))