Recover dual variable

60 views
Skip to first unread message

matkabhai asd

unread,
Mar 17, 2015, 12:52:40 AM3/17/15
to yal...@googlegroups.com
In the code below I am trying to recover dual variable  of the upper bound constraint m1<=5. it is giving me following error

Error using lmi/subsref (line 42)
LMI #5 not available.

Error in PD1 (line 65)
mu2 = dual(Co2(5))
 


Please help in this matter

Regards,
PVC





CODE----------------------------


yalmip('clear')
clear all

k1 = 2;
b1 = -2;


R = 1;

Q = [1 1;1 1];

n = 2;


ml = 1;
mu = 5;



z11 = 3.5886;
z12 = -0.5;
z13 = 1.5094;
z22 = 1.3335;
z23 = -6.1671;
z33 = 28.7097;


Z11 = [z11 z12;z12 z22];
Z12 = [z13 z23]';
Z22 = z33;

Z = [Z11 Z12;Z12' Z22];


sdpvar m1

Co2 = [];


h11 = 2*m1*z12+m1;
h12 = -k1*z11-b1*z12+z13+m1*z22;
h22 = -2*k1*z12-2*b1*z22+2*z23+m1;
S1 = [h11 h12;h12 h22];
% Co2 = [Co2,h11==0;h12==0;h22==0;m1>=1;m1<=5;];
Co2 = [Co2,h11==0;h12==0;h22==0;m1>=1;m1<=5;];

Ob2 = m1+trace(R*Z22)+trace(Q*Z11);

di1 = optimize(Co2,Ob2)

x1 = double(m1)
val1 = double(Ob2)
p11 = dual(Co2(1))
p12 = dual(Co2(2))
p22 = dual(Co2(3))
mu1 = dual(Co2(4))
mu2 = dual(Co2(5))

Johan Löfberg

unread,
Mar 17, 2015, 2:29:35 AM3/17/15
to yal...@googlegroups.com
Co2 does not have a list of 5 constraints, as the first constraint trivially is removed (look at h11...)

Safer approach if you might add trivial constraints which will be pruned by YALMIP
TheBound = m1<=5;
Co2 = [h11==0;h12==0;h22==0;m1>=1;TheBound];
di1
= optimize(Co2,Ob2)
dual
(TheBound)

or with tag indexing
Co2 = [h11==0;h12==0;h22==0;m1>=1;(m1<=5):'My bound'];
di1
= optimize(Co2,Ob2)
dual(Co2('My bound'))




matkabhai asd

unread,
Mar 17, 2015, 4:46:42 AM3/17/15
to yal...@googlegroups.com
"as the first constraint trivially is removed (look at h11...)"

how to check this?

matkabhai asd

unread,
Mar 17, 2015, 4:55:37 AM3/17/15
to yal...@googlegroups.com
"as the first constraint trivially is removed (look at h11...)"

I got that using Checkset, but how to know which constraint is trivially removed?

Johan Löfberg

unread,
Mar 17, 2015, 4:56:37 AM3/17/15
to yal...@googlegroups.com
>> h11

h11
=

     
0


matkabhai asd

unread,
Mar 17, 2015, 5:35:42 AM3/17/15
to yal...@googlegroups.com
Thanks a 10^6 !!! :)

matkabhai asd

unread,
Mar 17, 2015, 5:42:17 AM3/17/15
to yal...@googlegroups.com
Hi,

Just a silly question.

I want to use the dual variable in an iterative program so everytime I can't manually check which constraint is trivially removed. Is there any way to check of a constraint is trivially removed so that I can get correct dual variable corresponding to the correct constraint. 

Also what is the way to get dual variable corresponding to the correct constraint?

Thank you and Regards

Johan Löfberg

unread,
Mar 17, 2015, 5:45:14 AM3/17/15
to yal...@googlegroups.com
Why don't you use some of the two methods I advised you to do?

matkabhai asd

unread,
Mar 17, 2015, 1:03:40 PM3/17/15
to yal...@googlegroups.com
Hi, 

Used both methods got following errors :
Method 1:

cn1 = h11==0;
cn2 = h12==0;
cn3 = h22==0;
TheBound1 = m1>=mu;
TheBound2 = m1<=mu;

Co2 = [cn1;cn2;cn3;TheBound1;TheBound2];


% duals

p11 = dual(cn1)
p12 = dual(cn2)
p22 = dual(cn3)
lambda1 = dual(TheBound1)
lambda2 = dual(TheBound2)

Error:

Undefined function 'dual' for input arguments of type 'logical'.

Error in PD1 (line 105)
p11 = dual(cn1)
 

%%%%%%%%%%%%%%%%%%%%%%%%%%%

Method 2:


Co2 = [(h11==0):'cn1';(h12==0):'cn2';(h22==0):'cn3';(m1>=1):' bound1';(m1<=5):'My bound2'];

% duals

p11 = dual(Co2('cn1'))
p12 = dual(Co2('cn2'))
p22 = dual(Co2('cn3'))
lambda1 = dual(Co2('My bound1'))
lambda2 = dual(Co2('My bound2'))


Error:

Error using  : 
For colon operator with char operands, first and last operands must be char.

Error in PD1 (line 97)
Co2 = [(h11==0):'cn1';(h12==0):'cn2';(h22==0):'cn3';(m1>=1):'My bound1';(m1<=5):'My bound2'];


Please help!!

Thank you and Regards



Johan Löfberg

unread,
Mar 17, 2015, 1:27:18 PM3/17/15
to yal...@googlegroups.com
You are defining trivial statements for which it makes no sense to apply a dual operator

>> cn1 = h11==0

cn1
=

     
1



matkabhai asd

unread,
Mar 17, 2015, 1:45:31 PM3/17/15
to yal...@googlegroups.com
Sir,

I am really Sorry to bother you again and again but I am in unable to think of any method to find the constraint which is is trivial during the iterative process.

As you had said that constraint h11 is trivial for one value of variable but for another value it may not be trivial, in that case its dual value will be recovered. Problem comes when it is trivial the program will stop giving  error. 

Can you suggest some method?

Thank you and Regards


Johan Löfberg

unread,
Mar 17, 2015, 1:48:29 PM3/17/15
to yal...@googlegroups.com
if isa(cn1,'logical')
 
if true(cn1)
  disp
('OK, it trivially satisfied. YALMIP will simply prune it, so I shouldn't try to check the dual later')
 
else
  disp('Ouch, I am creating a trivially infeasible model!')
end
 


matkabhai asd

unread,
Mar 17, 2015, 2:23:49 PM3/17/15
to yal...@googlegroups.com
It worked like a charm.

Thank a 10^6 Sir !!!!

God bless you!!
Reply all
Reply to author
Forward
0 new messages