Solver not applicable (mosek)

824 views
Skip to first unread message

HSS

unread,
Mar 9, 2016, 5:49:21 AM3/9/16
to YALMIP
I am trying to compile the following code 

clear all
clc

% The example works for f = [-x1;-x2] and rho = 1

eps = 1e-9;

%% System Definition

% State Space Variables
x1 = sdpvar(1);
x2 = sdpvar(1);

% System definitions
f = [-x1-x1^3+x2^2;0];
B = [0;1];

% Variational system
A =  jacobian(f,[x1 x2]);
MatrixA = sdisplay(A)

%% Contraction Metric set up

W  = sdpvar(2,2);
    
% The function rho
Rhodeg = 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 polynomials
Constraints = [W >= 0, LfW <= 0];
Constraints % display list of constraints

% set required solver
options = 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)

But the output is the following

+++++++++++++++++++++++++++++++++++++++++++++
|   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|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I am executing it on Matlab 2015a with Yalmip. What could be wrong?

Johan Löfberg

unread,
Mar 9, 2016, 6:06:59 AM3/9/16
to YALMIP
Not sure what it is what you are trying to do, but what you do is that you try to find x and rho such that some nasty nonlinear SDPs hold, which you of course cannot use mosek for

Looks like you really want to apply sum-of-squares.

Johan Löfberg

unread,
Mar 9, 2016, 6:12:34 AM3/9/16
to YALMIP
My guess, you want to find W and a non-negative polynomial rho, such the SDP holds for all x. Inner approximate with sum-of-squares

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)







Message has been deleted

HSS

unread,
Mar 9, 2016, 6:41:45 AM3/9/16
to YALMIP
Thank you, Johan.

I have modified the code to the actual code that I need. Now, the SDP is more complex. More specifically, I have changed the matrix W as follows

% polynomials for W matrix
Wdegree = 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 derivatives
W = [Wp11 Wp12;
     Wp12 Wp22];
 
DWv = jacobian([Wp11;Wp12;Wp22],[x1 x2])*f; 
DW  = [DWv(1) DWv(2);
       DWv(2) DWv(3)];

The Lie derivative of the W along the vector field f yields

LfW = -DW + A*W + W*A' + W - Rho*(B*B'); 


Now, I need to find rho and W satisfying the following constraints

Constraints = [W>=eye(2),sos(-LfW),sos(Rho)];

Which I tried to solve, by executing

coefList = [Wc11;Wc12;Wc22;cRho];
options = sdpsettings('solver','mosek');
diagnostics = solvesos(Constraints,[],options,coefList);

However, the output was

++++++++++++++++++++++++++++++++++++++++++++++++
|   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 the
independents, 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);

Then, I have changed the constraints to 

Constraints = [sos(-LfW),sos(Rho)];

And executed the solver as before. This gave me the following output

++++++++++++++++++++++++++++++++++++++++++++++++
|   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^2
Newton polytope (1 LPs).........Keeping 5 monomials (0.0468sec)
Finding symmetries..............Found no symmetries (0.0312sec)
Initially 3 monomials in R^2
Newton 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.com
Platform: 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            : 42
Optimizer  - Cones                  : 0
Optimizer  - 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

Would you know why W is a NaN matrix?

Johan Löfberg

unread,
Mar 9, 2016, 6:45:27 AM3/9/16
to YALMIP
You want W to be sum-of-squares in x, and the parameters defining W has to be added to the list of parameters in the call to solvesos

HSS

unread,
Mar 9, 2016, 6:52:53 AM3/9/16
to YALMIP
The vector 
coefList
is the coefficients that define the matrix W. Is this the list of parameter that I should pass to the solvesos?

Johan Löfberg

unread,
Mar 9, 2016, 6:55:50 AM3/9/16
to YALMIP
Missed that. Correct

HSS

unread,
Mar 9, 2016, 7:00:12 AM3/9/16
to YALMIP
OK. In this case, I still have the problem with the output

Johan Löfberg

unread,
Mar 9, 2016, 7:00:25 AM3/9/16
to YALMIP
and W is nan as only the values of the parameters are computed. x does not have any value, and is thus nan

HSS

unread,
Mar 9, 2016, 7:00:41 AM3/9/16
to YALMIP
Would you know what could be causing it?

HSS

unread,
Mar 9, 2016, 7:22:28 AM3/9/16
to YALMIP
But I am searching for the parameters of W, right? How can I see it?

Johan Löfberg

unread,
Mar 9, 2016, 7:27:53 AM3/9/16
to YALMIP
value(Wc11) etc

you've found this polynomial
sdisplay(replace(W,[Wc11;Wc12;Wc22],value([Wc11;Wc12;Wc22])))


HSS

unread,
Mar 9, 2016, 7:41:22 AM3/9/16
to YALMIP
Thank you very much Johan. One last question, shouldn't I add the condition W>=0 to the constraints vector?

Johan Löfberg

unread,
Mar 9, 2016, 7:57:19 AM3/9/16
to YALMIP
I already told you that. You most likely want to find a sos W
Reply all
Reply to author
Forward
0 new messages