Lagrange multiplier (dual variable)

645 views
Skip to first unread message

TM

unread,
Sep 29, 2015, 11:05:14 PM9/29/15
to YALMIP
Hi Johan,

I'm trying to find the Lagrange multiplier of the following least squares with quadratic constraint:
x = min{norm(a+A*x)^2 + \lambda * norm(x)^2}. The solution is x = -(A^H*A+\lambda*I)^-1*a , for which norm(x)^2 = \alpha and \alpha is known.

I'm using YALMIP with MOSEK, My code is:
==============================================================================================
options = sdpsettings('solver','mosek','verbose',1,'savesolveroutput',1)
x = sdpvar(10,1,'full','complex');
Objective = norm(a + A*x);
C1 = norm(x) <= sqrt(alpha);
diagnostics = solvesdp([C1],Objective,options);
            if diagnostics.problem == 1
                error('Fail!')
            end
===============================================================================================
What do I need to add to this code to get the Lagrange multiplier \lambda. I tried using "dual", but it gave me "NAN".

TM

unread,
Sep 29, 2015, 11:23:04 PM9/29/15
to YALMIP
Okay, I tried dual(C1) which actually gave me a value, not sure though if that's the correct value for lambda....

Johan Löfberg

unread,
Sep 30, 2015, 2:15:24 AM9/30/15
to YALMIP
You have to realize that there is a lot of modelling happening under the hood here to deal with the high-level norm operator. Your model is internally written as

sdpvar t
C = cone([t;real(x);imag(x)])
C1 = [t <= sqrt(alpha), C];

The dual you extract is the dual on the linear constraint. 

If you want to have the vector SOCP dual, you have to model the norm manually

C1 = cone([sqrt(alpha);real(x);imag(x)]);






Johan Löfberg

unread,
Sep 30, 2015, 2:24:42 AM9/30/15
to YALMIP
and if you want the dual for the quadratic constraint (i.e. not for the SOCP constraint which YAMIP has to introduce), I think you have to use gurobi, which has support for recovering the corresponding dual of a quadratic constraint, when an SOCP was used to describe it. This requires you to catch it manually though. Additionally, since the norm objective is implemented using an SOCP cone also, I rewrite that to a quadratic, to avoid having two duals in the solution and confuse things

C1 = cone([sqrt(alpha);real(x);imag(x)]);
diagnostics = solvesdp(C1,(a+A*x)'*(a+A*x),sdpsettings('solver','gurobi','gurobi.QCPdual',1,'savesolveroutput',1))
diagnostics.solveroutput.result.qcpi

As you can see, it is a mess when you start working with high-level models of quadratics and norms, and want to have a dual which relates to a model which looks obvious on pen-and-paper, but can be solved in a completely different manner depending on the solver etc

TM

unread,
Sep 30, 2015, 2:55:25 AM9/30/15
to YALMIP
Thank you! I'm not that well versed in optimization. So the Lagrange multiplier I'm looking for is the dual for the quadratic constraint, correct?. I was hoping for a workaround using mosek as a solver. I'm getting 'NAN' when using gurobi, not sure if my license expired, I cannot really tell because I cannot see any output on the screen. How do I set verbose mode for gurbobi, I had it set for mosek but doesn't work for gurobi with ('verbose',1).

Actually using dual(C1) gave me a number (\lambda) that when I plugged in x = -(A^H*A+\lambda*I)^-1*a, x would have a norm: norm(x)^2 approximately equals \alpha, which is expected.

Johan Löfberg

unread,
Sep 30, 2015, 2:57:44 AM9/30/15
to YALMIP
You have to look at the diagnostics

>> diagnostics = optimize(sdpvar(1)>=0,[],sdpsettings('solver','bananas'))

ans = 

    solvertime: 0
          info: 'Specified solver name not recognized (bananas)'
       problem: -9
    yalmiptime: 0.0940


TM

unread,
Sep 30, 2015, 3:16:28 AM9/30/15
to YALMIP
Thank you!

abdulla ahmed

unread,
Nov 24, 2016, 8:35:28 PM11/24/16
to YALMIP
i have a problem, i am using yalmip to solve unit commitment problem, when i finished my code i tried to save it and run but i faced message for don't save it because if you saved it your yalmitp code become trouble and i didn't understand it and saved it and then when i tried to run again there is no results. the results are 
   yalmiptime: NaN
    solvertime: NaN
          info: [1x245 char]
       problem: 9  
so kindly if you have any solution please give me ASAP
THANKS so much

Johan Löfberg

unread,
Nov 25, 2016, 1:31:02 AM11/25/16
to YALMIP
so what does the info field say?

As both YALMIP time and solvertime is Nan, that means something crashed massively internally in the call to the solver

Set the option 'debug' to 1, and you will see the crash more clearly
Reply all
Reply to author
Forward
0 new messages